31 const String TorqueCurve::customModel =
"CustomModel";
33 TorqueCurve::TorqueCurve() : usedSpline(0), usedModel(
"")
54 float t = Math::Clamp((rpm - minRPM) / (maxRPM - minRPM), 0.0f, 1.0f);
65 group = ResourceGroupManager::getSingleton().findGroupContainingResource(
"torque_models.cfg");
73 LOG(
"torque_models.cfg not found");
78 DataStreamPtr ds = ResourceGroupManager::getSingleton().openResource(
"torque_models.cfg", group);
80 String currentModel =
"";
85 StringUtil::trim(line);
87 if (line.empty() || line[0] ==
';')
90 Ogre::StringVector args = StringUtil::split(line,
",");
99 if (!currentModel.empty())
108 if (args.size() == 1)
112 if (args.size() != 2)
115 float pointx = StringConverter::parseReal(args[0]);
116 float pointy = StringConverter::parseReal(args[1]);
117 Vector3 point = Vector3(pointx, pointy, 0);
121 splines[model] = SimpleSpline();
125 splines[model].addPoint(point);
141 splines[name] = Ogre::SimpleSpline();
154 splines[model].addPoint(Ogre::Vector3(rpm, progress, 0));
163 LOG(
"Torquemodel "+String(name)+
" not found! ignoring that and using default model...");
177 SimpleSpline tmpSpline = *spline;
178 Real points = tmpSpline.getNumPoints();
184 Real minDistance = tmpSpline.getPoint(1).x - tmpSpline.getPoint(0).x;
186 for (
int i = 2; i < points; i++)
188 Real distance = tmpSpline.getPoint(i).x - tmpSpline.getPoint(i - 1).x;
189 minDistance = std::min(distance, minDistance);
195 Vector3 minPoint = tmpSpline.getPoint(0);
196 Vector3 maxPoint = tmpSpline.getPoint(points - 1);
198 Real rpmPoint = minPoint.x;
200 while (rpmPoint <= maxPoint.x && pointIndex < points)
203 if (rpmPoint > tmpSpline.getPoint(pointIndex).x)
206 Real newPoint = tmpSpline.getPoint(pointIndex - 1).y + (tmpSpline.getPoint(pointIndex).y - tmpSpline.getPoint(pointIndex - 1).y) /
207 (tmpSpline.getPoint(pointIndex).x - tmpSpline.getPoint(pointIndex - 1).x) * (rpmPoint - tmpSpline.getPoint(pointIndex - 1).x);
208 spline->addPoint(Vector3(rpmPoint, newPoint, 0));
209 rpmPoint += minDistance;
213 if (spline->getPoint(spline->getNumPoints() - 1).x < maxPoint.x && (rpmPoint - maxPoint.x) < 0.01 * maxPoint.x)
215 spline->addPoint(Vector3(rpmPoint, maxPoint.y, 0));