latest changes

This commit is contained in:
2023-01-29 15:02:32 +01:00
parent 52ea780ca7
commit a9badcdedd
4 changed files with 104 additions and 1 deletions

29
src/hittable.rs Normal file
View File

@@ -0,0 +1,29 @@
use crate::ray::*;
use crate::vec3::*;
#[derive(Clone)]
pub struct HitRecord {
pub p: Point3,
pub normal: Vec3,
pub t: f64,
pub front_face: bool,
}
impl HitRecord {
pub fn new_empty() -> Self {
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 }
}
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
} else {
*outward_normal * -1.0
}
}
}
pub trait Hittable {
fn hit(&self, r: &Ray, t_min: f64, t_max: f64, rec: &mut HitRecord) -> bool;
}