Collision detection (bounding box)

Started by
0 comments, last by Shooter 21 years, 5 months ago
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 ;-)
I don''t need any signature ;-)
Advertisement
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;

This topic is closed to new replies.

Advertisement