AABB-to-AABB
Testing if two AABBs overlap involves performing an interval test on each of the world axes. To visualize this problem, let's consider what an interval test looks like on just one axis:
Given shapes A and B, we have an overlap only if the minimum of A is less than the maximum of B and the maximum of A is greater than the minimum of B. The actual overlap test would look something like this:
A.min <= B.max && a.max >= b.min
We can determine if two AABBs overlap by performing this test on the global X, Y, and Z axes.
Getting ready
We are going to implement a function to test if two AABBs are overlapping or not. This function will test for interval overlap on the global X, Y, and Z axis.
How to do it…
Follow the given steps to detect intersections between two AABBs:
Declare
AABBAABB
inGeometry3D.h
:bool AABBAABB(const AABB& aabb1, const AABB& aabb2);
Implement
AABBAABB
inGeometry3D.cpp
:bool AABBAABB(const AABB& aabb1, const AABB& aabb2) {
Find the min and max...