GetClosestWheel giving me problems
by Josh Moore · in Torque Game Engine · 06/28/2004 (10:35 pm) · 6 replies
I'm having trouble with a fuction that retruns the closest wheel on a wheeled vehicle from a certatin position(similar to getdamageloctation). The function returns the correct front wheels, but returns wheel # 1 for both back wheels. It seems that the hit position is always in the front part of the vehicle even when its not.
Heres my function:
I don't know whats wrong with it but it shoudl be returning the back wheels.
Heres my function:
bool WheeledVehicle::getClosestWheel(const Point3F& pos)
{
Point3F newPoint;
mWorldToObj.mulP(pos, &newPoint);
S32 wheel;
if (newPoint.y >= 0.0f)
{
if (newPoint.x <= 0.0f)
wheel = 0;//"front_left";
else
wheel = 1;//"front_right";
}
else
{
if (newPoint.x <= 0.0f)
wheel = 3;//"back_left";
else
wheel = 2;//"back_right";
}
return wheel;
}I don't know whats wrong with it but it shoudl be returning the back wheels.
#2
And you know what happens? The same exact thing. It will return the correct wheel if hit in the front half of my jeep, but if hit in the back it returns wheel #1. I'm not very good at c++(as you can see), but I don't see why this isn't working. Any insight on what might be happening is welcome.
Thanks in advance.
06/30/2004 (11:59 am)
Thanks for the suggestion. I converted it to a S32 function, but I got the same resaults. So I reworked the entire function to this:S32 WheeledVehicle::getClosestWheel(const Point3F& pos)
{
Point3F newPoint;
mWorldToObj.mulP(pos, &newPoint);
S32 wheelNum = -1;
F32 distance = 100;
for (S32 i = 0; i < mDataBlock->wheelCount; i++) {
VectorF posVec = newPoint - mWheel[i].data->pos;
F32 test = posVec.len();
posVec.set(0,0,0);// clear the vector
if(test < distance)
{
distance = test;
wheelNum = i;
}
}
return wheelNum;
}And you know what happens? The same exact thing. It will return the correct wheel if hit in the front half of my jeep, but if hit in the back it returns wheel #1. I'm not very good at c++(as you can see), but I don't see why this isn't working. Any insight on what might be happening is welcome.
Thanks in advance.
#3
100 seems way too low...try bumping it up to something huge
07/01/2004 (6:46 am)
F32 distance = 100;
100 seems way too low...try bumping it up to something huge
#4
BTW, why don't you just step through it in the debugger?
07/01/2004 (7:09 am)
I think the first version was fine (assuming your vehicle is centered at its origin). I think the bool return value was your problem. Try doing a clean make and rebuild. Sometimes the compiler/linker won't properly change code when you change the type of a variable.BTW, why don't you just step through it in the debugger?
#5
07/01/2004 (7:19 am)
The only problem I see with the first one is that it will fail on non-4 wheeled vehicles. The second solution is a little more general purpose though it will be a very slight bit slower.
#6
07/02/2004 (9:27 pm)
I've tried alot of different ways to find the closest wheel and get similar results every time. It turns out that the newPoint.y is NEVER a negative value. I've tried to fix it, but I get the same resaults.
Torque Owner Sam Guffey