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
sourceimpl Ray
impl Ray
sourcepub fn new(origin: Point3<f32>, direction: Vector3<f32>) -> Ray
pub fn new(origin: Point3<f32>, direction: Vector3<f32>) -> Ray
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);
sourcepub fn intersects_aabb(&self, aabb: &AABB) -> bool
pub fn intersects_aabb(&self, aabb: &AABB) -> bool
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));
sourcepub fn intersects_aabb_naive(&self, aabb: &AABB) -> bool
pub fn intersects_aabb_naive(&self, aabb: &AABB) -> bool
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));
sourcepub fn intersects_aabb_branchless(&self, aabb: &AABB) -> bool
pub fn intersects_aabb_branchless(&self, aabb: &AABB) -> bool
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));
sourcepub fn intersects_triangle(
&self,
a: &Point3<f32>,
b: &Point3<f32>,
c: &Point3<f32>
) -> Intersection
pub fn intersects_triangle(
&self,
a: &Point3<f32>,
b: &Point3<f32>,
c: &Point3<f32>
) -> Intersection
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
Auto Trait Implementations
impl RefUnwindSafe for Ray
impl Send for Ray
impl Sync for Ray
impl Unpin for Ray
impl UnwindSafe for Ray
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read morefn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.