-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathray.rs
More file actions
49 lines (44 loc) · 1.01 KB
/
ray.rs
File metadata and controls
49 lines (44 loc) · 1.01 KB
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
48
49
use crate::rvec3::*;
pub struct Ray{
orig : Point3,
dir : Rvec3,
time : f64,
}
impl Default for Ray{
fn default()-> Self{
Self::new()
}
}
impl Ray{
pub fn new() -> Self {
Self{
orig: Point3::new(),
dir : Rvec3::new(),
time : 0.0
}
}
pub fn new_arg(_orig : Point3, _dir : Rvec3) -> Self{
let mut drr = _dir;
drr = Rvec3::unit_vector(&mut drr);
Self{
orig : _orig,
dir : drr,
time : 0.0
}
}
pub fn new_time(_orig : Point3, _dir : Rvec3, tm : f64) -> Self{
let mut drr = _dir;
drr = Rvec3::unit_vector(&mut drr);
Self{
orig : _orig,
dir : drr,
time : tm
}
}
pub fn origin(&mut self) -> Point3 { self.orig }
pub fn direction(&mut self) -> Rvec3 { self.dir }
pub fn time(&mut self) -> f64 {self.time}
pub fn at(&mut self, t : f64) -> Point3{
self.orig + t*self.dir
}
}