Struct truster::ray::Ray [−][src]
pub struct Ray { /* fields omitted */ }
Expand description
A ray which can be used for calculating intersections with shapes to render 3D scenes.
Implementations
Returns a new Ray with the given origin and direction.
Returns the point at the given distance t along self
.
Examples
use truster::tuple::Tuple; let ray = Ray::new(Tuple::point(2.0, 3.0, 4.0), Tuple::vector(1.0, 0.0, 0.0)); assert_eq!(ray.at(0.0), Tuple::point(2.0, 3.0, 4.0)); assert_eq!(ray.at(1.0), Tuple::point(3.0, 3.0, 4.0)); assert_eq!(ray.at(-1.0), Tuple::point(1.0, 3.0, 4.0)); assert_eq!(ray.at(2.5), Tuple::point(4.5, 3.0, 4.0));
Returns a new ray where both origin and direction are self
’s origin and direction
transformed by transform
.
Examples
Translating a ray:
use truster::tuple::Tuple; use truster::matrix::Matrix; let ray = Ray::new(Tuple::point(1.0, 2.0, 3.0), Tuple::vector(0.0, 1.0, 0.0)); let transform = Matrix::translation(3.0, 4.0, 5.0); let ray = ray.transform(&transform); assert_eq!(ray, Ray::new(Tuple::point(4.0, 6.0, 8.0), Tuple::vector(0.0, 1.0, 0.0)));
Scaling a ray:
use truster::tuple::Tuple; use truster::matrix::Matrix; let ray = Ray::new(Tuple::point(1.0, 2.0, 3.0), Tuple::vector(0.0, 1.0, 0.0)); let transform = Matrix::scaling(2.0, 3.0, 4.0); let ray = ray.transform(&transform); assert_eq!(ray, Ray::new(Tuple::point(2.0, 6.0, 12.0), Tuple::vector(0.0, 3.0, 0.0)));
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Ray
impl UnwindSafe for Ray
Blanket Implementations
Mutably borrows from an owned value. Read more