pub struct Ray {
pub origin: Vector3D,
pub direction: Vector3D,
pub t_min: f64,
pub t_max: f64,
pub depth: u32,
}Expand description
A 3D ray carrying the parameters needed for traversal and depth tracking.
Fields§
§origin: Vector3DThe world-space origin of the ray.
direction: Vector3DThe unit direction of the ray.
t_min: f64The minimum acceptable t value for valid intersections.
t_max: f64The maximum t value before the ray escapes the scene.
depth: u32The current recursion depth (used to terminate recursive bounces).
Implementations§
Source§impl Ray
impl Ray
Sourcepub fn with_depth(&self, depth: u32) -> Ray
pub fn with_depth(&self, depth: u32) -> Ray
Sourcepub fn with_range(&self, t_min: f64, t_max: f64) -> Ray
pub fn with_range(&self, t_min: f64, t_max: f64) -> Ray
Returns a clone of this ray with its parameter range replaced.
The new bounds are taken as given, so an inverted or non-finite
range is representable; both query entry points reject such a ray
as untraceable rather than letting NaN comparisons decide the
outcome.
§Arguments
f64- The minimum accepted hit parameter.f64- The maximum accepted hit parameter.
§Returns
Ray- The cloned ray with the new range.
Sourcepub fn intersect_triangle(
&self,
vertices: [Vector3D; 3],
) -> Option<(f64, Vector3D)>
pub fn intersect_triangle( &self, vertices: [Vector3D; 3], ) -> Option<(f64, Vector3D)>
Intersects this ray with a triangle using the Moller-Trumbore
algorithm, keeping only hits inside this ray’s t_min..=t_max
range.
The test is two-sided: a hit from either face counts, and the
returned normal always faces against the ray direction. This is the
range-clamped counterpart of the free
intersect_triangle, which reports the
raw distance however far away the triangle is.
§Arguments
[Vector3D; 3]- The three triangle vertices in winding order.
§Returns
Option<(f64, Vector3D)>- The hit distance along the ray and the unit normal oriented against the ray direction, orNoneon miss.