pub struct Ray {
pub origin: DVec3,
pub dir: DVec3,
pub t_min: f64,
pub t_max: f64,
}Expand description
A ray defined by an origin and a direction (not normalised).
The direction may have any non-zero length; the traversal code normalises
internally. t_min / t_max bound how far along the ray intersections are
accepted, in units of the ray’s direction length.
Fields§
§origin: DVec3Origin in simulation space.
dir: DVec3Direction vector (not necessarily unit length).
t_min: f64Minimum parametric distance to accept.
t_max: f64Maximum parametric distance to accept.
Implementations§
Source§impl Ray
impl Ray
Sourcepub fn new(origin: DVec3, dir: DVec3) -> Self
pub fn new(origin: DVec3, dir: DVec3) -> Self
Create a ray from origin and direction, with default bounds (0, +inf).
Examples found in repository?
examples/filtered_ray_volley.rs (line 90)
77fn main() {
78 let rays: u64 = std::env::args()
79 .nth(1)
80 .map_or(Ok(100_000), |count| count.parse())
81 .expect("the argument is a ray count");
82 let mut world = volley_world();
83 let filter = QueryFilter::masked(LEVEL);
84 let mut hits = 0u64;
85 for n in 0..rays {
86 let origin = crowd_point(4, n, 1.5);
87 let yaw = hash_unit(5, n) * std::f64::consts::TAU;
88 let pitch = (hash_unit(6, n) - 0.5) * 0.2;
89 let dir = DVec3::new(cos(yaw), pitch, sin(yaw)).normalize();
90 let ray = Ray::new(origin, dir).with_bounds(0.0, RAY_LENGTH);
91 hits += u64::from(world.cast_ray_filtered(black_box(&ray), filter).is_some());
92 }
93 println!("{rays} rays, {hits} hits");
94}Sourcepub fn with_bounds(self, t_min: f64, t_max: f64) -> Self
pub fn with_bounds(self, t_min: f64, t_max: f64) -> Self
Set the parametric bounds.
Examples found in repository?
examples/filtered_ray_volley.rs (line 90)
77fn main() {
78 let rays: u64 = std::env::args()
79 .nth(1)
80 .map_or(Ok(100_000), |count| count.parse())
81 .expect("the argument is a ray count");
82 let mut world = volley_world();
83 let filter = QueryFilter::masked(LEVEL);
84 let mut hits = 0u64;
85 for n in 0..rays {
86 let origin = crowd_point(4, n, 1.5);
87 let yaw = hash_unit(5, n) * std::f64::consts::TAU;
88 let pitch = (hash_unit(6, n) - 0.5) * 0.2;
89 let dir = DVec3::new(cos(yaw), pitch, sin(yaw)).normalize();
90 let ray = Ray::new(origin, dir).with_bounds(0.0, RAY_LENGTH);
91 hits += u64::from(world.cast_ray_filtered(black_box(&ray), filter).is_some());
92 }
93 println!("{rays} rays, {hits} hits");
94}Trait Implementations§
impl Copy for Ray
impl StructuralPartialEq for Ray
Auto Trait Implementations§
impl Forget for Ray
impl Freeze for Ray
impl Move 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more