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));
Central state/object manager and communications hub.
void LOG(const char *msg)
Legacy alias - formerly a macro.
Ogre::String usedModel
name of the torque model used by the truck.
void AddCurveSample(float rpm, float progress, Ogre::String const &model=customModel)
Adds a point to the torque curve graph.
TorqueCurve()
Constructor.
int loadDefaultTorqueModels()
Loads default torque models from the 'torque_models.cfg' file.
static const Ogre::String customModel
int spaceCurveEvenly(Ogre::SimpleSpline *spline)
Spaces the points of a spline evenly; this is needed for the correct calculation of the Ogre simple s...
int processLine(Ogre::StringVector args, Ogre::String model)
Processes the given vector.
Ogre::SimpleSpline * usedSpline
spline which is used for calculating the torque, set by setTorqueModel().
int setTorqueModel(Ogre::String name)
Sets the torque model which is used for the vehicle.
Ogre::Real getEngineTorque(Ogre::Real rpm)
Returns the calculated engine torque based on the given RPM, interpolating the torque curve spline.
std::map< Ogre::String, Ogre::SimpleSpline > splines
container were all torque curve splines are stored in.
bool CreateNewCurve(Ogre::String const &name=customModel)
Creates new torque curve.
~TorqueCurve()
Destructor.
std::string SanitizeUtf8String(std::string const &str_in)