2019-04-13 16:19:10 +00:00
|
|
|
use cgmath::Vector3;
|
2019-03-21 06:40:30 +00:00
|
|
|
|
2019-03-20 14:56:29 +00:00
|
|
|
pub struct Ray {
|
|
|
|
pub origin: Vector3<f32>,
|
|
|
|
pub direction: Vector3<f32>,
|
|
|
|
pub inv_direction: Vector3<f32>,
|
|
|
|
pub signs: Vector3<usize>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ray {
|
|
|
|
pub fn new(origin: Vector3<f32>, direction: Vector3<f32>) -> Ray {
|
|
|
|
let inv_direction = 1.0 / direction;
|
|
|
|
|
|
|
|
let x = (inv_direction.x < 0.0) as usize;
|
|
|
|
let y = (inv_direction.y < 0.0) as usize;
|
|
|
|
let z = (inv_direction.z < 0.0) as usize;
|
|
|
|
|
|
|
|
Ray {
|
|
|
|
origin,
|
|
|
|
direction,
|
|
|
|
inv_direction,
|
|
|
|
signs: Vector3::new(x, y, z),
|
|
|
|
}
|
|
|
|
}
|
2019-03-21 06:40:30 +00:00
|
|
|
}
|