Skip to main content
GameDev.net gamedev.net
🔒 Locked

AABBs collision detection

Started by asafpolt Feb 18, 2005 at 5:17 AM 0 replies 800+ views
Original Post
asafpolt
asafpolt
I've been looking for an implementation of 2 AABB (axis-aligned bounding box) interception check for a few days now. I didn't came up with much, I realy am looking for the most easy code for checking if 2 AABBs intercept. I realy hope someone will post the code for this collision detection, or will refer me to where I can get it.
Zakwayda
Zakwayda
Very easy code to find, but with search down it may be harder to dig up. So:

bool AABB::IntersectAABB(const AABB& box) const{    if (m_min[0] > box.m_max[0])        return false;    if (m_min[1] > box.m_max[1])        return false;    if (m_min[2] > box.m_max[2])        return false;    if (m_max[0] < box.m_min[0])        return false;    if (m_max[1] < box.m_min[1])        return false;    if (m_max[2] < box.m_min[2])        return false;		    return true;}


As it's always good to understand the algorithms, this is a simple separating axis test. If you look through the code a little I'm sure you'll see what's going on.

You can also intersect moving AABBs, with a little more work. But the above will work for the static (non-moving) test.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.