pub struct Ray {
pub origin: Vec3,
pub direction: Vec3,
}Expand description
A half-line: an origin and a direction.
direction is expected to be normalised. Ray::new guarantees it; the
struct literal — kept public because a ray is plain data — does not.
Fields§
§origin: Vec3Origin point.
direction: Vec3Direction vector (should be normalized).
Implementations§
Source§impl Ray
impl Ray
Sourcepub fn inv_direction(&self) -> Vec3
pub fn inv_direction(&self) -> Vec3
The component-wise reciprocal of the direction, as the slab test wants it.
A zero component yields an infinity, which Aabb::intersect_ray
handles correctly: a ray parallel to a slab simply never leaves it.
Sourcepub fn intersect_aabb(&self, aabb: &Aabb) -> Option<f32>
pub fn intersect_aabb(&self, aabb: &Aabb) -> Option<f32>
Distance to the near face of aabb, or None if the ray misses it.
Negative when the origin is already inside or past the box. Hoist
Ray::inv_direction and call Aabb::intersect_ray directly when
testing one ray against many boxes.
Sourcepub fn intersect_plane(&self, point: Vec3, normal: Vec3) -> Option<f32>
pub fn intersect_plane(&self, point: Vec3, normal: Vec3) -> Option<f32>
Distance to the plane through point with normal normal, or None
when the ray is parallel to it or the plane lies behind the origin.
normal need not be normalised — it only appears in a ratio.
Sourcepub fn distance_to_point(&self, point: Vec3) -> f32
pub fn distance_to_point(&self, point: Vec3) -> f32
Perpendicular distance from point to the ray.
Measured from the half-line: a point behind the origin is measured from the origin itself, not from the line the ray extends backwards along.
Sourcepub fn closest_param_on_line(
&self,
origin: Vec3,
direction: Vec3,
) -> Option<f32>
pub fn closest_param_on_line( &self, origin: Vec3, direction: Vec3, ) -> Option<f32>
How far along the line origin + t * direction its closest approach to
this ray sits, or None if the two are parallel.
The classic closest-approach of two skew lines. direction must be
normalised. Note this parameterises the other line, not the ray —
which is what a caller dragging along an axis wants to know.
Sourcepub fn closest_point_on_segment(&self, a: Vec3, b: Vec3) -> Vec3
pub fn closest_point_on_segment(&self, a: Vec3, b: Vec3) -> Vec3
The point on segment a..b closest to this ray.
Falls back to the midpoint when the segment is parallel to the ray or degenerate — every point on it is then equally close, and a caller hit-testing a handle wants an answer rather than an absence.