This commit is contained in:
2023-02-02 00:58:59 +01:00
parent 560b2b1196
commit 72fb4ce3fd
3 changed files with 15 additions and 17 deletions

View File

@@ -16,16 +16,16 @@ impl HitRecord<'_> {
HitRecord { p: Point3::new(0.0, 0.0, 0.0), normal: Vec3::new(0.0, 0.0, 0.0), t: 0.0, front_face: false, mat_ptr: material }
}
pub fn set_face_normal(&mut self, r: &Ray, outward_normal: &Vec3) {
self.front_face = r.direction().dot(outward_normal) < 0.0;
pub fn set_face_normal(&mut self, r: &Ray, outward_normal: Vec3) {
self.front_face = r.direction().dot(&outward_normal) < 0.0;
self.normal = if self.front_face {
*outward_normal
outward_normal
} else {
*outward_normal * -1.0
outward_normal * -1.0
}
}
}
pub trait Hittable {
fn hit(&mut self, r: &Ray, t_min: f64, t_max: f64, rec: &mut HitRecord) -> bool;
fn hit(&mut self, r: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord>;
}