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, ...
Get Game Physics Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.