quick AABB test using the box entents
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
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 .
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 .
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.
[edited by - Jon723 on January 4, 2004 4:58:16 PM]
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]
too tired to debug your code (), so try
[edited by - oliii on January 4, 2004 6:58:03 PM]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement