#### Archived

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

# quick AABB test using the box entents

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

## Recommended Posts

hello, I want to know if there is a quick algorithm to see if two axis aligned bounding boxes collide based on the objects positions and box extents. I have the objets position stored in a vector nad I have the extents calculated as: (box.max + box.min)/2 is it possible to detect a collision with these two things?? Thank you. Jon

##### Share on other sites
i dont know whether it''s faulty or not.. but it works in almost all cases for me.
The idea is to check whether two AABB boxes are disjoint (totally seperated without any overlap) or not... if they r not disjoint.. then they must be overlapped somehow. The boxes are gaurenteed to be disjoint if

ONE of the ordinates ( x , y or z) of the min point of a box is greater than the corresponding ordinate of the max point of the other box then these two boxes will never overlap.

OR
ONE of the ordinates (x,y,z) of the max point of a box is less than the corresponding ordinate of the min point of the other box..then these two boxes will neva overlap.

Just put a NOT before the above test.. and u have a test for whether the two boxes overlap or not .

##### Share on other sites
I tried this in my code but when the two boxes collide the objects still go through each other. I have repsonse code that would make the object stay in its position if the boxes collide.

bool World::BoxCollision(Player *p1, Player *p2){   return (((p1->min->xpos >= p2->max->xpos) && (p1->min->ypos >= p2->max->ypos) && (p1->min->zpos >= p2->max->zpos)) ||	      ((p1->max->xpos <= p2->min->xpos) && (p1->max->ypos <= p2->min->ypos) && (p1->max->zpos <= p2->min->zpos)));}

[edited by - Jon723 on January 4, 2004 4:58:16 PM]

##### Share on other sites
too tired to debug your code (), so try

bool World::BoxCollision(Player *p1, Player *p2){   if (p1->min->xpos > p2->max->xpos || p2->min->xpos > p1->max->xpos) return false;    if (p1->min->ypos > p2->max->ypos || p2->min->ypos > p1->max->ypos) return false;    if (p1->min->zpos > p2->max->zpos || p2->min->zpos > p1->max->zpos) return false;    return true;}

[edited by - oliii on January 4, 2004 6:58:03 PM]

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
17
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002297
×