From 33e747fa1c0957546c10e4d7b490ac7fbb0fd2d2 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 7 Feb 2021 14:25:06 +0100 Subject: Abstracted lambertian into material --- src/core/hittable.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/core/hittable.rs (limited to 'src/core/hittable.rs') diff --git a/src/core/hittable.rs b/src/core/hittable.rs new file mode 100644 index 0000000..20c82f7 --- /dev/null +++ b/src/core/hittable.rs @@ -0,0 +1,23 @@ +use crate::core::{Vector3f, Ray}; + +/// Returns the context of a intersection +pub struct Intersection { + /// Normal vector at intersection + pub n: Vector3f, + pub p: Vector3f, +} + +impl Intersection { + pub fn norm_against_ray(&self, r: &Ray) -> Vector3f { + if self.n.dot(&r.direction) < 0.0 { + self.n + } else { + -self.n + } + } +} + +/// Defines a common trait for objects in the scene +pub trait Hittable { + fn intersect(&self, ray: &Ray) -> Option; +} -- cgit v1.2.3