Collision prob
distance = fabs(distance);
since a negative distance would cause your app to report collisions even if there is none.
quote:
Original post by Mister Stewart
The code for detecting collison is as follows:
relpos = mesh1center - mesh2center;
distance = ((relpos.x*relpos.x) + (relpos.y*relpos.y) + (relpos.z*relpos.z));
mindistance = mesh1rad + mesh2rad;
if(distance <= (mindistance * mindistance))
{
//message box, then quit
//MessageBox(main_window_handle, "collision occured", "collision occurred", MB_OK);
//PostMessage(main_window_handle, WM_CLOSE, 0,0);
}
Greetings,
Your math checks out just fine. The way that you are calculating it, distance will definately be a positive number; a sum of squares is always positive. So, my guess would be that your problem is in the calculation of meshNcenter and meshNrad; N\in{1,2}.
Unfortunately, I don't know directX at all so I can't verify whether the other part of the code is correct. I would suggest printing out the vectors meshNcenter, and the values of meshNrad to verify that they agree with what you know the values to be. Or, at least setting a breakpoint at the "if" to inspect said values. My hunch is that something's not getting set correctly.
Alternately, you could easily code an inefficient function which calculates the center and radius for you. The center is the midpoint of the bounding box of the mesh; ie: calculate max & min values for x, y, and z of all the vertices in the mesh then take the average of each min/max pair as the center. Then, the radius of the bounding sphere is the max{||v-center||:v a vertex of the mesh} (that is, calculate the distance of each vertex from the center, and take the maximum; taking the max over the squares of the distance won't work if you have any distances less than 1, as the square of a value less than 1 is less than the value being squared).
I hope I've given you some leads to chase. Good luck!
-Eraslin
[edited by - Eraslin on April 20, 2002 10:33:38 PM]
Now I gotta spend some time reading over it and understanding it, then I''m gonna try my hand at understanding mesh animation.
Thanks again for the replies.
"Sweetie! Get Mommy''s bazooka!
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.