-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Game Physics Cookbook
By :
Raycasting against a triangle is a three step process:
We already have functions to implement this entire process. The FromTriangle function will create a plane from the triangle. We already have a Raycast function that casts a ray against a plane. We also have a PointInTriangle function.
We can improve the performance of the Raycast by using barycentric coordinates instead of the existing PointInTriangle test. Barycentric coordinates are a way to represent the position of a point relative to a triangle.
We are going to implement a new function, Barycentric. This new function will return the barycentric coordinates of a point with respect to a triangle. We will use this new function, along with the existing FromTriangle and Raycast functions created in Chapter 10, 3D Line Intersections to make a new Raycast against triangle function.