Add simple ray module.
This commit is contained in:
parent
e1199611f0
commit
b8861b7f8d
@ -1 +1,2 @@
|
||||
pub mod ray;
|
||||
pub mod vec3;
|
||||
|
||||
22
rtiow/src/ray.rs
Normal file
22
rtiow/src/ray.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use vec3::Vec3;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Ray {
|
||||
a: Vec3,
|
||||
b: Vec3,
|
||||
}
|
||||
|
||||
impl Ray {
|
||||
pub fn new(a: Vec3, b: Vec3) -> Ray {
|
||||
Ray { a, b }
|
||||
}
|
||||
pub fn origin(self) -> Vec3 {
|
||||
self.a
|
||||
}
|
||||
pub fn direction(self) -> Vec3 {
|
||||
self.b
|
||||
}
|
||||
pub fn point_at_parameter(self, t: f32) -> Vec3 {
|
||||
self.a + self.b * t
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user