Triangle to triangle
Testing if two triangles intersect is done using a generic SAT test. We will have to test a total of 11 axes. These axes are:
- The normal of the first triangle
- The normal of the second triangle
- The cross product of the edges of each triangle
Getting ready
We need to implement a new OverlapOnAxis
test as well as the actual SAT test. The actual SAT test will be performed inside the TriangleTriangle
collision function. We first covered the Separating Axis Theorem in Chapter 5, 2D Collisions. In this section we will check 11 axes of potential separation. If any axis of separation is found, the triangles do not intersect.
How to do it…
Follow these steps to check if two triangles intersect:
- Declare the
OverlapOnAxis
andTriangleTriangle
function inGeometry3D.h
:bool OverlapOnAxis(const Triangle& t1, const Triangle& t2, const vec3& axis); bool TriangleTriangle(const Triangle& t1, const Triangle& t2);
- Implement the
OverlapOnAxis
function inGeometry3D...