Skip to main content

intersect_triangle

Function intersect_triangle 

Source
pub fn intersect_triangle(
    origin: Vector3D,
    dir: Vector3D,
    v0: Vector3D,
    v1: Vector3D,
    v2: Vector3D,
) -> Option<(f64, Vector3D)>
Expand description

Intersects a ray with the triangle v0, v1, v2 using the Moller-Trumbore algorithm.

The test is two-sided: a hit on either face counts, and the returned normal is flipped when needed so that it always faces against the ray direction, making back-face hits usable for shading. A ray parallel to the triangle plane yields None. No t_min/t_max filtering is applied here; use Ray::intersect_triangle for the range-clamped variant.

§Arguments

  • Vector3D - The ray origin.
  • Vector3D - The ray direction (expected to be unit length).
  • Vector3D - The first triangle vertex.
  • Vector3D - The second triangle vertex.
  • Vector3D - The third triangle vertex.

§Returns

  • Option<(f64, Vector3D)> - The hit distance along the ray and the unit surface normal oriented against the ray direction, or None on miss.