#### Archived

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

# D3DXComputeBoundingSphere

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

## Recommended Posts

##### 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 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 on other sites
Skip the sqrt if you are only checking for collisions. The squared distance compared to the squared radius is fine.

• 17
• 10
• 19
• 14
• 19