1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::f32;
use linalg::{Point, Vector};
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Ray {
pub o: Point,
pub d: Vector,
pub min_t: f32,
pub max_t: f32,
pub depth: u32,
pub time: f32,
}
impl Ray {
pub fn new(o: &Point, d: &Vector, time: f32) -> Ray {
Ray { o: *o, d: *d, min_t: 0f32, max_t: f32::INFINITY, depth: 0, time: time }
}
pub fn segment(o: &Point, d: &Vector, min_t: f32, max_t: f32, time: f32) -> Ray {
Ray { o: *o, d: *d, min_t: min_t, max_t: max_t, depth: 0, time: time }
}
pub fn child(&self, o: &Point, d: &Vector) -> Ray {
Ray { o: *o, d: *d, min_t: 0f32, max_t: f32::INFINITY, depth: self.depth + 1, time: self.time }
}
pub fn child_segment(&self, o: &Point, d: &Vector, min_t: f32, max_t: f32) -> Ray {
Ray { o: *o, d: *d, min_t: min_t, max_t: max_t, depth: self.depth + 1, time: self.time }
}
pub fn at(&self, t: f32) -> Point {
self.o + self.d * t
}
}