Struct bvh::ray::Ray

source ·
pub struct Ray {
    pub origin: Point3<f32>,
    pub direction: Vector3<f32>,
    /* private fields */
}
Expand description

A struct which defines a ray and some of its cached values.

Fields

origin: Point3<f32>

The ray origin.

direction: Vector3<f32>

The ray direction.

Implementations

Creates a new Ray from an origin and a direction. direction will be normalized.

Examples
use bvh::ray::Ray;
use bvh::nalgebra::{Point3,Vector3};

let origin = Point3::new(0.0,0.0,0.0);
let direction = Vector3::new(1.0,0.0,0.0);
let ray = Ray::new(origin, direction);

assert_eq!(ray.origin, origin);
assert_eq!(ray.direction, direction);

Tests the intersection of a Ray with an AABB using the optimized algorithm from this paper.

Examples
use bvh::aabb::AABB;
use bvh::ray::Ray;
use bvh::nalgebra::{Point3,Vector3};

let origin = Point3::new(0.0,0.0,0.0);
let direction = Vector3::new(1.0,0.0,0.0);
let ray = Ray::new(origin, direction);

let point1 = Point3::new(99.9,-1.0,-1.0);
let point2 = Point3::new(100.1,1.0,1.0);
let aabb = AABB::with_bounds(point1, point2);

assert!(ray.intersects_aabb(&aabb));

Naive implementation of a Ray/AABB intersection algorithm.

Examples
use bvh::aabb::AABB;
use bvh::ray::Ray;
use bvh::nalgebra::{Point3,Vector3};

let origin = Point3::new(0.0,0.0,0.0);
let direction = Vector3::new(1.0,0.0,0.0);
let ray = Ray::new(origin, direction);

let point1 = Point3::new(99.9,-1.0,-1.0);
let point2 = Point3::new(100.1,1.0,1.0);
let aabb = AABB::with_bounds(point1, point2);

assert!(ray.intersects_aabb_naive(&aabb));

Implementation of the algorithm described [here] (https://tavianator.com/fast-branchless-raybounding-box-intersections/).

Examples
use bvh::aabb::AABB;
use bvh::ray::Ray;
use bvh::nalgebra::{Point3,Vector3};

let origin = Point3::new(0.0,0.0,0.0);
let direction = Vector3::new(1.0,0.0,0.0);
let ray = Ray::new(origin, direction);

let point1 = Point3::new(99.9,-1.0,-1.0);
let point2 = Point3::new(100.1,1.0,1.0);
let aabb = AABB::with_bounds(point1, point2);

assert!(ray.intersects_aabb_branchless(&aabb));

Implementation of the [Möller-Trumbore triangle/ray intersection algorithm] (https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm). Returns the distance to the intersection, as well as the u and v coordinates of the intersection. The distance is set to +INFINITY if the ray does not intersect the triangle, or hits it from behind.

Trait Implementations

Formats the value using the given formatter. 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

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 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.