Revision: 1698
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1698&view=rev
Author: rorthomas
Date: 2011-02-25 10:13:15 +0000 (Fri, 25 Feb 2011)
Log Message:
-----------
fixes #40
Modified Paths:
--------------
trunk/source/main/framework/ContentManager.cpp
trunk/source/main/gameplay/TorqueCurve.cpp
trunk/source/main/gameplay/TorqueCurve.h
trunk/source/main/gameplay/engine.cpp
trunk/source/main/physics/input_output/BeamLoadTruck.cpp
Modified: trunk/source/main/framework/ContentManager.cpp
===================================================================
--- trunk/source/main/framework/ContentManager.cpp 2011-02-22 23:05:13 UTC
(rev 1697)
+++ trunk/source/main/framework/ContentManager.cpp 2011-02-25 10:13:15 UTC
(rev 1698)
@@ -28,6 +28,9 @@
#include "skinmanager.h"
#include "language.h"
+#include "CacheSystem.h"
+
+
using namespace Ogre;
using namespace std;
Modified: trunk/source/main/gameplay/TorqueCurve.cpp
===================================================================
--- trunk/source/main/gameplay/TorqueCurve.cpp 2011-02-22 23:05:13 UTC (rev
1697)
+++ trunk/source/main/gameplay/TorqueCurve.cpp 2011-02-25 10:13:15 UTC (rev
1698)
@@ -137,3 +137,43 @@
usedModel = name;
return 0;
}
+
+int TorqueCurve::spaceCurveEvenly(Ogre::SimpleSpline *spline)
+{
+ SimpleSpline tmpSpline=*spline;
+ Real points=tmpSpline.getNumPoints();
+ if (points>1)
+ {
+ //clear the original spline, so it's prepared for the new
corrected numbers
+ spline->clear();
+ Real minDistance=10000000.0f;
+ //looking for the mininimum distance (spacing) in the current
spline
+ for(int i=0;i<points-1;i++)
+ {
+ // the rpms must be in an ascending order, as the
points should be added at the end of the spline
+ if (tmpSpline.getPoint(i+1).x<tmpSpline.getPoint(i).x)
return 1;
+ Real
distance=tmpSpline.getPoint(i+1).x-tmpSpline.getPoint(i).x;
+ if (distance<minDistance) minDistance=distance;
+ }
+ //first(smallest), and last rpm
+ Vector3 minPoint=tmpSpline.getPoint(0);
+ Vector3 maxPoint=tmpSpline.getPoint(points-1);
+
+ Real rpmPoint=minPoint.x;
+ int PointNum=1; //this is the index used to interpolate between
the rpm points
+ while (rpmPoint<=maxPoint.x && PointNum<points)
+ {
+ //if actual rpm is higher than point of the spline,
proceed to the next point
+ if(rpmPoint>tmpSpline.getPoint(PointNum).x) PointNum++;
+ //interpolate(linear)
+ Real
newPoint=tmpSpline.getPoint(PointNum-1).y+(tmpSpline.getPoint(PointNum).y-tmpSpline.getPoint(PointNum-1).y)/
+
(tmpSpline.getPoint(PointNum).x-tmpSpline.getPoint(PointNum-1).x)*(rpmPoint-tmpSpline.getPoint(PointNum-1).x);
+ spline->addPoint(Vector3(rpmPoint,newPoint,0));
+ rpmPoint+=minDistance;
+ }
+ //if the last point is missing due the even spacing, we add the
last point manually
+ //criterium is that it must be smaller than 1% of the maximum
rpm.
+ if(spline->getPoint(spline->getNumPoints()-1).x<maxPoint.x &&
(rpmPoint-maxPoint.x)<0.01*maxPoint.x)
spline->addPoint(Vector3(rpmPoint,maxPoint.y,0));
+ }
+ return 0;
+}
Modified: trunk/source/main/gameplay/TorqueCurve.h
===================================================================
--- trunk/source/main/gameplay/TorqueCurve.h 2011-02-22 23:05:13 UTC (rev
1697)
+++ trunk/source/main/gameplay/TorqueCurve.h 2011-02-25 10:13:15 UTC (rev
1698)
@@ -78,6 +78,13 @@
*/
Ogre::String getTorqueModel() { return usedModel; };
+ /**
+ * Spaces the points of a spline evenly; this is needed for the correct
calculation of the Ogre simple spline.
+ * @param spline Pointer to the spline which should be processed.
+ * @return 0 on success, 1 on error
+ */
+ int spaceCurveEvenly(Ogre::SimpleSpline *spline);
+
protected:
Ogre::SimpleSpline *usedSpline; //!< spline
which is used for calculating the torque, set by setTorqueModel().
Ogre::String usedModel; //!< name of the
torque model used by the truck.
Modified: trunk/source/main/gameplay/engine.cpp
===================================================================
--- trunk/source/main/gameplay/engine.cpp 2011-02-22 23:05:13 UTC (rev
1697)
+++ trunk/source/main/gameplay/engine.cpp 2011-02-25 10:13:15 UTC (rev
1698)
@@ -155,7 +155,7 @@
//engine power
//with limiter
float tqValue = 1.0f;
- float rpmRatio = curEngineRPM / maxRPM;
+ float rpmRatio = curEngineRPM / (maxRPM*1.25);
if (rpmRatio > 1.0f) rpmRatio = 1.0f;
if (torqueCurve) tqValue = torqueCurve->getEngineTorque(rpmRatio);
if (running && contact && curEngineRPM<(maxRPM*1.25) &&
curEngineRPM>stallRPM)
Modified: trunk/source/main/physics/input_output/BeamLoadTruck.cpp
===================================================================
--- trunk/source/main/physics/input_output/BeamLoadTruck.cpp 2011-02-22
23:05:13 UTC (rev 1697)
+++ trunk/source/main/physics/input_output/BeamLoadTruck.cpp 2011-02-25
10:13:15 UTC (rev 1698)
@@ -3931,8 +3931,21 @@
nodes[nodenum].collRadius = radius;
}
-
};
+
+
+ // we should post-process the torque curve if existing
+ if(engine)
+ {
+ int
result=engine->getTorqueCurve()->spaceCurveEvenly(engine->getTorqueCurve()->getUsedSpline());
+ if (result==1)
+ {
+ LogManager::getSingleton().logMessage("TorqueCurve:
Points (rpm) must be in an ascending order. Using default curve");
+ engine->getTorqueCurve()->setTorqueModel("default");
+ }
+ }
+
+
if(!loading_finished) {
LogManager::getSingleton().logMessage("Reached end of file "+
String(fname)+ ". No 'end' was found! Did you forgot it? Trying to
continue...");
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel