[SOLVED] how to check position between ....

r1cky17

02-11-2007 07:56:10

hi, i make a racing game.
how to check my car position is between the finish line?
i try like this but it's error compile


lapStart1 = Vector3(71, 0, 0);
lapStart2 = Vector3(80, 0, 0);
if (mCar->getPosition() >= lapStart1 + mCar->getPosition() <= lapStart2)



error C2676: binary '>=' : 'Ogre::Vector3' does not define this operator or a conversion to a type acceptable to the predefined operator


thx for the help

r1cky17

11-11-2007 19:27:46

hi, i know how to check that now
i'm using this math


Real x = Math::Pow((obj2.x - obj1.x),2);
Real y = Math::Pow((obj2.y - obj1.y),2);
radius = Math::Sqrt(x + y);


if the radius is zero, then the obj1 has pass the obj2 position :D

Tubez

12-11-2007 13:31:54

First of all, what you are doing there is computing the distance. I suggest you just use the Vector3() functions for that.

Second, It will never be exactly zero. And then you will never know whether you are in front of it or behind. Just that you are at a certain distance.
What you probably want here is to set up a plane that reflects the finish line and compute on which side of the plane you are. You do this by taking the dot-product of the connector between the object and the plane and plane normal.
If the dot-product is positive, you are on the side pointed to by the normal, if not you are on the other side.

If you have difficulty understanding this explanation, I suggest you go the library and grab a good book on 3D math. It's not going to get any easier from here.