diff options
author | Julian T <julian@jtle.dk> | 2021-07-31 14:02:52 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-07-31 14:02:52 +0200 |
commit | cee9bcf4a2c8ffbfe6487f7886b2247eaba1c92c (patch) | |
tree | 7fd405d9a3f6351d6341706fba50a8616d6c3a84 /src/world/hittable.rs | |
parent | 55044e56304c8484b8ff52f362ab1c66c9c5ca93 (diff) |
Better documentation and cleanup
Diffstat (limited to 'src/world/hittable.rs')
-rw-r--r-- | src/world/hittable.rs | 22 |
1 files changed, 16 insertions, 6 deletions
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); } } } |