-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solve #2 by throwing in random lifetimes 💀
- Loading branch information
1 parent
adfdaef
commit 02c2c00
Showing
5 changed files
with
38 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
use crate::{interval::Interval, material::EMaterial, ray::Ray, vec3::{dot, Point3, Vec3}}; | ||
use crate::{interval::Interval, material::{DefaultMaterial, Material}, ray::Ray, vec3::{dot, Point3, Vec3}}; | ||
|
||
#[derive(Clone, Default)] | ||
pub struct HitRecord { | ||
#[derive(Clone)] | ||
pub struct HitRecord<'a> { | ||
pub p: Point3, | ||
pub normal: Vec3, | ||
pub mat: Box<EMaterial>, | ||
pub mat: &'a (dyn Material), | ||
pub t: f64, | ||
pub front_face: bool, | ||
} | ||
impl HitRecord { | ||
impl<'a> Default for HitRecord<'a> { | ||
fn default() -> Self { | ||
Self { p: Default::default(), normal: Default::default(), mat: &DefaultMaterial, t: Default::default(), front_face: Default::default() } | ||
} | ||
} | ||
impl<'a> HitRecord<'a> { | ||
pub fn set_face_normal(&mut self, r: &Ray, outward_normal: &Vec3) { | ||
self.front_face = dot(*r.dir(), *outward_normal) < 0.0; | ||
self.normal = if self.front_face {*outward_normal} else {-*outward_normal} | ||
} | ||
} | ||
|
||
pub trait Hittable { | ||
fn hit(&self, r: &Ray, ray_t: Interval, rec: &mut HitRecord) -> bool; | ||
pub trait Hittable<'a> { | ||
fn hit(&self, r: &Ray, ray_t: Interval, rec: &mut HitRecord<'a>) -> bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters