embree_rs/
ray.rs

1use cgmath::Vector3;
2use std::{f32, u32};
3
4use sys;
5
6pub type Ray = sys::RTCRay;
7pub type Hit = sys::RTCHit;
8pub type RayHit = sys::RTCRayHit;
9pub type IntersectContext = sys::RTCIntersectContext;
10
11impl Ray {
12    /// Create a new ray starting at `origin` and heading in direction `dir`
13    pub fn new(origin: Vector3<f32>, dir: Vector3<f32>) -> Ray {
14        Ray::segment(origin, dir, 0.0, f32::INFINITY)
15    }
16    pub fn segment(origin: Vector3<f32>, dir: Vector3<f32>, tnear: f32, tfar: f32) -> Ray {
17        sys::RTCRay {
18            org_x: origin.x,
19            org_y: origin.y,
20            org_z: origin.z,
21            dir_x: dir.x,
22            dir_y: dir.y,
23            dir_z: dir.z,
24            tnear: tnear,
25            tfar: tfar,
26            time: 0.0,
27            mask: u32::MAX,
28            id: 0,
29            flags: 0,
30        }
31    }
32}
33
34impl Hit {
35    pub fn new() -> Hit {
36        sys::RTCHit {
37            Ng_x: 0.0,
38            Ng_y: 0.0,
39            Ng_z: 0.0,
40            u: 0.0,
41            v: 0.0,
42            primID: u32::MAX,
43            geomID: u32::MAX,
44            instID: [u32::MAX; 1],
45        }
46    }
47    pub fn hit(&self) -> bool {
48        self.geomID != u32::MAX
49    }
50}
51
52impl RayHit {
53    pub fn new(ray: Ray) -> RayHit {
54        sys::RTCRayHit {
55            ray: ray,
56            hit: Hit::new(),
57        }
58    }
59}
60
61impl IntersectContext {
62    pub fn coherent() -> IntersectContext {
63        IntersectContext::new(sys::RTCIntersectContextFlags::COHERENT)
64    }
65    pub fn incoherent() -> IntersectContext {
66        IntersectContext::new(sys::RTCIntersectContextFlags::INCOHERENT)
67    }
68    fn new(flags: sys::RTCIntersectContextFlags) -> IntersectContext {
69        sys::RTCIntersectContext {
70            flags: flags,
71            filter: None,
72            instID: [u32::MAX; 1],
73        }
74    }
75}