aboutsummaryrefslogtreecommitdiff
path: root/src/world/hittable.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/world/hittable.rs')
-rw-r--r--src/world/hittable.rs22
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);
}
}
}