Simple AABB vs AABB collision detection

An AABB is an axis aligned bounding box. It’s mainly used in broadphase physics detection.

Assume this are the basic properties of an AABB.

struct AABB
{
	Point c;		// center point
	float r[3];	// halfwidths
};

Then we can use this simple test to check if there is an overlap between the bounding boxes.

bool testAABBAABB(const AABB &a, const AABB &b)
{
	float t;
	if ( Abs(a.c[0] - b.c[0]) > (a.r[0] + b.r[0]) return false;
	if ( Abs(a.c[1] - b.c[1]) > (a.r[1] + b.r[1]) return false;
	if ( Abs(a.c[2] - b.c[2]) > (a.r[2] + b.r[2]) return false;
	// We have an overlap
	return true;
};
VN:F [1.9.13_1145]
Rating: 4.6/5 (5 votes cast)
Simple AABB vs AABB collision detection, 4.6 out of 5 based on 5 ratings
Share

3 Comments

  1. tania says

    cool :D

  2. BlazeX says

    What is the “float t;” for? You never use this var.

  3. kent says

    It can be safely removed.

    It’s probably some leftovers from trying to do continuous collision detection (CCD).

Leave a Reply

Leave a Reply
  • (required)
  • (required) (will not be published)