unclepauly
02-10-2006 22:20:00
my car (for test purposes) has only 1st gear, with a ratio of 3.2. The differential ratio is 2.1. Therefore, the total multiplier is 3.2*2.1 = 6.72. The car's wheel radius is 0.3m. Because each revolution of the wheel takes the car 2 *pi * R further, thats 2*3.14*0.3 = 1.884. The torque curve is:
rpm = 500 torque = 400
rpm = 5000 torque = 1100
rpm = 5500 torque = 1300
rpm = 6500 torque = 1800
rpm = 7500 torque = 1700
rpm = 9000 torque = 1600
So, going off the car physics tutorial...
when the engine is doing 9000 rpm in 1st gear, thats 9000/multiplier = 1339 revolutions of the wheel a minute. Thats 22 revolutions a second * 1.884 = 42 metres per second. Thats 151 km/h.
But my car only reaches 59km/h. Can anyone offer an explanation?
unclepauly
02-10-2006 22:22:39
btw, my UserCallback function is:
void Car::userCallback()
{
//get the average omega of the wheels
int count = 0;
Ogre::Real omega = 0.0;
for (Car::CarTire* tire = (Car::CarTire*)getFirstTire(); tire; tire = (Car::CarTire*)getNextTire( tire ) )
{
// get omega
omega += tire->getOmega();;
count++;
}
omega /= (Ogre::Real)count;
//calculate the RPM from this omega.
mRPM = omega * ((mGears[mCurrentGear]>0)?mGears[mCurrentGear]:-mGears[mCurrentGear]) * mDifferentialRatio * (60.0f/2.0f*3.14159f);
if (mRPM < mTorqueCurve[0].rpm) { mRPM = mTorqueCurve[0].rpm; }
if (mRPM > mTorqueCurve[mTorqueCurve.size()-1].rpm) { mRPM = mTorqueCurve[mTorqueCurve.size()-1].rpm; }
// find where we are in the torque curve.
unsigned short high = 0;
while ( mRPM >= mTorqueCurve[high].rpm )
{
high++;
if (high >= mTorqueCurve.size())
{
high = mTorqueCurve.size() - 1;
break;
}
}
// found low.
unsigned int low = high - 1;
if (high == 0) { low = 0; high = 1; }
// rpm is between [low,high] on the torque curve.
Ogre::Real interp = ((mRPM - mTorqueCurve[low].rpm) / (mTorqueCurve[high].rpm - mTorqueCurve[low].rpm));
mEngineTorque = mTorqueCurve[low].torque + ((mTorqueCurve[high].torque - mTorqueCurve[low].torque)*interp);
mWheelTorque = mThrottle * mEngineTorque * mGears[mCurrentGear] * mDifferentialRatio * mTransmissionEfficiency;
// loop through wheels, adding torque and steering, and updating their positions.
for (Car::CarTire* tire = (Car::CarTire*)getFirstTire(); tire; tire = (Car::CarTire*)getNextTire( tire ) )
{
// is this a driving tire?
if (!tire->mSteeringTire)
{
tire->setTorque(mWheelTorque); }
if (tire->mSteeringTire)
tire->setSteeringAngle(mSteering);
tire->updateNode();
}
}
HexiDave
02-10-2006 23:07:17
Check MaterialPairs so you can set proper friction - my guess is that your wheels are spinning like they're on ice a bit.
unclepauly
02-10-2006 23:13:57
ok ill have a look at that, thanks.
also, i have just added this to my UserCallback, in the tire loop...
Ogre::Real speed = tire->getLongitudinalSpeed();
tire->setMaxLongitudinalSlipSpeed( speed * tire->getGrip() );
tire->setLongitudinalSlipCoefficient( speed * load * (tire->getGrip()) );
the tire->getGrip() function returns the grip, as set in the tyre constructor. it was at 2. just now, i increased it to 222, and the km/h is now just under 100km/h.
is this increase of the grip similar to the MaterialPairs method you just mentioned? and is 222 a stupid number?
note my code is from Stunt Playground, with steering and braking taken out (for now). I do not see any MaterialPair code in Stunt Playground for tyre friction, unless i am mistaken...?
HexiDave
02-10-2006 23:48:59
There is - I don't have that code on this machine, but I know it's there - Walaber had a whole section for setting internal mechanics up and the Materials were one thing.
I dunno about the getGrip function, but I know increasing friction from 1 to 2 made the car a lot faster and more responsive.
unclepauly
02-10-2006 23:53:40
cool, thanks.
btw, i have just found this code for materialpairs:
OgreNewt::MaterialID* def_mat = mWorld->getDefaultMaterialID();
OgreNewt::MaterialID* other_mat = new Ogre::MaterialID( mWorld );
OgreNewt::MaterialPair* mat_pair = new OgreNewt::MaterialPair( mWorld, def_mat, other_mat );
mat_pair->setDefaultFriction( 1.0f, 0.9f );
looks like its quitre old code because Ogre:: doesnt have MaterialID and MaterialPair as members now (at least the latest SDK doesnt).
without holding my hand too tightly

, what members should i now be using?
[edit]
just seen your other post (
http://www.ogre3d.org/phpBB2/viewtopic. ... 413#178413)- no need to answer this!
[/edit]
unclepauly
03-10-2006 00:17:38