use crate::material::Material; use crate::ray::Ray; use cgmath::{dot, Vector3}; pub struct Hit<'a> { pub t: f64, pub p: Vector3, pub normal: Vector3, pub front_face: bool, pub material: &'a (dyn Material + std::marker::Sync), } impl<'a> Hit<'a> { pub fn new( ray: &Ray, t: f64, out_normal: Vector3, material: &'a (dyn Material + std::marker::Sync), ) -> Hit<'a> { let front_face = dot(ray.dir, out_normal) < 0.0; let normal = if front_face { out_normal } else { -out_normal }; let p = ray.at(t); Hit { t, p, normal, front_face, material, } } } pub trait Hittable { fn is_hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option; }