Triangle to Oriented Bounding Box
Like triangle to AABB, testing a triangle and an Oriented Bounding Box (OBB) is done using the SAT. In fact, the only difference in the actual test is the rotation frame of the bounding box.
Getting ready
We already have the GetInterval
support function written for both the OBB and the Triangle. We just need to write the OverlapOnAxis
support function and the actual SAT test.
How to do it…
Follow these steps to check if a triangle and an OBB intersect:
- Declare
OverlapOnAxis
andTriangleOBB
inGeometry3D.h
:bool OverlapOnAxis(const OBB& obb, const Triangle& triangle, const vec3& axis); bool TriangleOBB(const Triangle& t, const OBB& o);
- Add a convenience macro to
Geometry3D.h
:#define OBBTriangle(o, t) \ TriangleOBB(t, o)
- Implement
OverlapOnAxis
inGeometry3D.cpp
:bool OverlapOnAxis(const OBB& obb, const Triangle& triangle, const vec3& axis) { Interval a = GetInterval(obb, axis); Interval b = GetInterval(triangle...