Archived

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

Shooter

Collision detection (bounding box)

Recommended Posts

Hello, I am currently writing a collision detection for my 3d game. Unfortunately, it does not work; Sometimes it does not recognize collisions. I think that the problem should be within the following lines (the y coordinates are ignored right now!). Any idea what went wrong? Thanks in advance! bool GfxEngine::BoxesTouch(const BOUNDINGBOX* box1, const BOUNDINGBOX* box2) { bool bHaveTouched=false; if(((box2->minx >= box1->minx) && (box2->minx <= box1->maxx) && (box2->minz >= box1->minz) && (box2->minz <= box1->maxz) && (true)) || ((box2->minx <= box1->minx) && (box2->maxx >= box1->minx) && (box2->minz <= box1->minz) && (box2->maxz >= box1->minz) && (true))) bHaveTouched=true; //Wert zurückgeben return bHaveTouched; } I don''''t need any signature ;-)

Share this post


Link to post
Share on other sites
You are better off checking if the boxes are *not* intersecting:

if(box1->maxx < box2->minx || box2->maxx < box1->minx)
return no_hit;
if(box1->maxz < box2->minz || box2->maxz < box1->minz)
return no_hit;

return hit;

Share this post


Link to post
Share on other sites