From b8861b7f8dad659b3c6438a4dfb719754733fa2a Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sat, 8 Sep 2018 19:58:24 -0700 Subject: [PATCH] Add simple ray module. --- rtiow/src/lib.rs | 1 + rtiow/src/ray.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 rtiow/src/ray.rs diff --git a/rtiow/src/lib.rs b/rtiow/src/lib.rs index 9b789be..1d07923 100644 --- a/rtiow/src/lib.rs +++ b/rtiow/src/lib.rs @@ -1 +1,2 @@ +pub mod ray; pub mod vec3; diff --git a/rtiow/src/ray.rs b/rtiow/src/ray.rs new file mode 100644 index 0000000..a9a67c0 --- /dev/null +++ b/rtiow/src/ray.rs @@ -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 + } +}