From cee9bcf4a2c8ffbfe6487f7886b2247eaba1c92c Mon Sep 17 00:00:00 2001 From: Julian T Date: Sat, 31 Jul 2021 14:02:52 +0200 Subject: Better documentation and cleanup --- src/world/hittable.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/world/hittable.rs') diff --git a/src/world/hittable.rs b/src/world/hittable.rs index c5a353e..e11a3bc 100644 --- a/src/world/hittable.rs +++ b/src/world/hittable.rs @@ -7,16 +7,26 @@ pub struct Intersection<'a> { /// Normal vector at intersection pub n: Vector3f, pub p: Vector3f, + pub front: bool, pub t: Float, pub m: Option<&'a dyn Material>, } -impl Intersection<'_> { - pub fn norm_against_ray(&self, r: &Ray) -> Vector3f { - if self.n.dot(&r.direction) < 0.0 { - self.n - } else { - -self.n +impl<'a> Intersection<'a> { + pub fn new(out_normal: Vector3f, point: Vector3f, ray: &Ray, t: Float) -> Self { + let front = ray.direction.dot(&out_normal) < 0.0; + Intersection { + n: { if front { out_normal } else { -out_normal } }, + front, + p: point, + m: None, + t, + } + } + + pub fn add_material_if_none(&mut self, mat: &'a dyn Material) { + if let None = self.m { + self.m = Some(mat); } } } -- cgit v1.2.3