Struct fyrox_core::math::ray::Ray

source ·
pub struct Ray {
    pub origin: Vector3<f32>,
    pub dir: Vector3<f32>,
}

Fields§

§origin: Vector3<f32>§dir: Vector3<f32>

Implementations§

Creates ray from two points. May fail if begin == end.

Checks intersection with sphere. Returns two intersection points or none if there was no intersection.

Checks intersection with sphere.

Returns t factor (at pt=o+d*t equation) for projection of given point at ray

Returns point on ray which defined by pt=o+d*t equation.

Solves plane equation in order to find ray equation parameter. There is no intersection if result < 0.

Generic ray-cylinder intersection test.

https://mrl.nyu.edu/~dzorin/rend05/lecture2.pdf

Infinite cylinder oriented along line pa + va * t: sqr_len(q - pa - dot(va, q - pa) * va) - r ^ 2 = 0 where q - point on cylinder, substitute q with ray p + v * t: sqr_len(p - pa + vt - dot(va, p - pa + vt) * va) - r ^ 2 = 0 reduce to A * t * t + B * t + C = 0 (quadratic equation), where: A = sqr_len(v - dot(v, va) * va) B = 2 * dot(v - dot(v, va) * va, dp - dot(dp, va) * va) C = sqr_len(dp - dot(dp, va) * va) - r ^ 2 where dp = p - pa to find intersection points we have to solve quadratic equation to get root which will be t parameter of ray equation.

Transforms ray using given matrix. This method is useful when you need to transform ray into some object space to simplify calculations. For example you may have mesh with lots of triangles, and in one way you would take all vertices, transform them into world space by some matrix, then do intersection test in world space. This works, but too inefficient, much more faster would be to put ray into object space and do intersection test in object space. This removes vertex*matrix multiplication and significantly improves performance.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Casts self to a &dyn Any

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.