Linetest Triangle

Much like testing a line and an axis aligned or OBB intersection, testing a line and triangle intersection utilizes the existing Raycast function. We are going to cast a ray against the triangle being tested. If the Raycast succeeds, we need to make sure that the t value is along the line segment being tested.

Getting ready

We are about to implement a new Linetest function, which will test if a line and a triangle intersect. This function returns a Boolean result.

How to do it…

Follow these steps to check if a line intersects a triangle:

  1. Declare the new Linetest function in Geometry3D.h:
    bool Linetest(const Triangle& triangle, const Line& line);
  2. Implement the Linetest function in Geometry3D.cpp:
    bool Linetest(const Triangle& triangle, ...

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.