Skip to main content

Ray

Struct Ray 

Source
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: Vec3

Origin point.

§direction: Vec3

Direction vector (should be normalized).

Implementations§

Source§

impl Ray

Source

pub fn new(origin: Vec3, direction: Vec3) -> Self

Creates a ray, normalising direction.

Source

pub fn at(&self, distance: f32) -> Vec3

The point distance along the ray.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'__de, __Context> BorrowDecode<'__de, __Context> for Ray

Source§

fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
Source§

impl Clone for Ray

Source§

fn clone(&self) -> Ray

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ray

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<__Context> Decode<__Context> for Ray

Source§

fn decode<__D: Decoder<Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
Source§

impl<'de> Deserialize<'de> for Ray

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Encode for Ray

Source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.
Source§

impl PartialEq for Ray

Source§

fn eq(&self, other: &Ray) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Ray

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Ray

Source§

impl StructuralPartialEq for Ray

Auto Trait Implementations§

§

impl Freeze for Ray

§

impl RefUnwindSafe for Ray

§

impl Send for Ray

§

impl Sync for Ray

§

impl Unpin for Ray

§

impl UnsafeUnpin for Ray

§

impl UnwindSafe for Ray

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AppLifecycle for T
where T: ?Sized,

Source§

fn on_start(&mut self, ctx: &mut dyn AppContext)

Called once after the backend is up but before the first update. Apps install their theme / fonts here.
Source§

fn on_exit(&mut self)

Called once when the window is closing. Persist state here.
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns a reference to the inner value as &dyn Any.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,