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,
v0: Vector3D,
v1: Vector3D,
v2: Vector3D,
) -> Option<(f64, Vector3D)>
pub fn intersect_triangle( &self, v0: Vector3D, v1: Vector3D, v2: Vector3D, ) -> Option<(f64, Vector3D)>
Intersects this ray with the triangle v0, v1, v2 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.
§Arguments
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 normal oriented against the ray direction, orNoneon miss.