Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


This topic is 5554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I''m trying to do collision detection (simple bounding sphere right now) but am having some weird results. I use the D3DXComputeBoundingSphere to compute the radius of the bounding sphere around a mesh, but i get really weird collisions when I do a simple interect test. I basically do this: CheckCollision(*obj1, *obj2) { //get radius of each rad1 = *obj1->getRadius(); rad2 = *obj2->getRadius(); //compute difference in distances in each axis float diffx = fabs(obj1->x - obj2->x); float diffy = fabs(obj1->y - obj2->y); float diffz = fabs(obj1->z - obj2->z); if((rad1+rad2) >= diffx) { if((rad1+rad2) >= diffy) { if((rad1+rad2) >= diffz) { return true; } } } return false; } Anyway, I draw a wireframe sphere around my meshes in debug mode so I can see that the radius computed is correct, but I get collisions even when two meshes are quite far apart. But it doesn''t make sense. For example, I get that the radius of each mesh in the collision is 5.14, but the distance between them is computed as only 2.4 even though the objects are not interecting at all. Could it be some sort of conversion I''m missing from object space to world coordinate space? Thanks, # andrew.c

Share this post

Link to post
Share on other sites
You're not actually calculating the distance between the two.

Try this:

bool CheckCollision (CObject *obj1, CObject *obj2)
//get radius of each

float rad1 = *obj1->getRadius();
float rad2 = *obj2->getRadius();

//Calculate threshold and square it

float threshold = rad1 + rad2;
threshold *= threshold;

//compute difference in distances in each axis

float diffx = obj1->x - obj2->x;
float diffy = obj1->y - obj2->y;
float diffz = obj1->z - obj2->z;

//Calculate distance - leave it squared to prevent sqrt

float distance = diffx * diffx + diffy * diffy + diffz * diffz;

return distance < threshold;

[edited by - Kippesoep on March 7, 2003 5:35:14 PM]

Share this post

Link to post
Share on other sites
Distance between two points in space:
d = sqrt( delta_x^2 + delta_y^2 + delta_z^2 );

delta is v2 - v1 where v is a variable

so if d is less than radius_of_object1 + radius_of_object2 you have a collision.

I am a signature virus. Please add me to your signature so that I may multiply.

[edited by - Enselic on March 7, 2003 2:39:04 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!