Calculate Vehicle Speed

CmonGirl

12-10-2010 11:02:18

hi guys.
How can i calculate vehicle speed in KM?
I have a car. Can i use velocity? Help pls.

betajaen

12-10-2010 11:43:57

Get the linear velocity of the Actor, which is measured in metres per second, multiply by 3.6 for it to be in KPH.

CmonGirl

12-10-2010 12:05:29

linear velocity it have 3 parameters. How i do? I try this:
Ogre::Quaternion CalcQuat;
NxOgre::Quat VehQuat = mVehicle->mActor->getGlobalOrientationQuat();
CalcQuat.w = VehQuat.w;
CalcQuat.x = VehQuat.x;
CalcQuat.y = VehQuat.y;
CalcQuat.z = VehQuat.z;

Ogre::Real DirDeg = Ogre::Math::Abs(CalcQuat.getYaw().valueDegrees());
if(DirDeg > 90.0f)
DirDeg = Ogre::Math::Abs(90.0f - DirDeg);

NxOgre::Vec3 VehVel = mVehicle->mActor->getLinearVelocity();
float Velx = DirDeg * VehVel.z;
float Velz = (90 - DirDeg) * VehVel.x;
float VehSpeed = abs(Velx - Velz);

But dont stable working. Help me beta :)

betajaen

12-10-2010 12:37:58

Your orientation of the car has nothing to do with your velocity.

Jeez.

mVehicle->mActor->getLinearVelocity() * 3.6f

CmonGirl

12-10-2010 13:38:19

Thanks for relpy. But i can understand. velocity.x = 0 when my car move with 0 degree. But change velocity another degrees. And i need one parameter for km calculate.

betajaen

12-10-2010 13:41:29

This is it. It returns the velocity of the car in KPH.

mVehicle->mActor->getLinearVelocity().magnitude() * 3.6f

Orientation has nothing to do with velocity, this is basic physics stuff, that you should know if your using a physics engine.

CmonGirl

12-10-2010 13:53:29

vaaaaaaav. thanks good working.Thank you very much