Raycast plane and triangle
We have two planar primitives in our geometry toolbox, the Plane
and the Triangle
. The collision normal for both primitives is the same as the normal of the primitive itself. We must keep in mind that if a ray hits a plane or triangle from behind, that is not actually a hit. This is not a bug, it's how raycasting against these primitives should work. The "forward" direction of a triangle is determined by counter clockwise winding.
Getting ready
When we modify the Raycast
API for a plane or a triangle we break all the functions that internally use the old declaration. We must take care to update these broken functions as well. We will need to update the Linetest
against triangle function and the MeshRay
function.
How to do it…
Follow these steps to update the Raycast
function for both triangles and planes so that the functions return more useful data:
- Change the declaration of
Raycast
against both thePlane
andTriangle
inGeometry3D.h
:bool Raycast...