From 78ddaff5855bf8446adef9e18eb0d7b7ddcee52a Mon Sep 17 00:00:00 2001 From: lamp Date: Sun, 5 Mar 2023 21:45:56 +0000 Subject: init --- src/hittable/mod.rs | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/hittable/mod.rs (limited to 'src/hittable/mod.rs') diff --git a/src/hittable/mod.rs b/src/hittable/mod.rs new file mode 100644 index 0000000..e888c71 --- /dev/null +++ b/src/hittable/mod.rs @@ -0,0 +1,76 @@ +pub mod instance; +mod bvh_node; +pub use bvh_node::BVHNode; +mod constant_medium; +pub use constant_medium::ConstantMedium; +mod hittable_box; +pub use hittable_box::HittableBox; +mod hittable_list; +pub use hittable_list::HittableList; +mod xy_rect; +pub use xy_rect::XYRect; +mod xz_rect; +pub use xz_rect::XZRect; +mod yz_rect; +pub use yz_rect::YZRect; +mod sphere; +pub use sphere::Sphere; +mod triangle; +pub use triangle::Triangle; +mod model; +pub use model::Model; +mod aabb; + +use std::sync::Arc; + +use crate::ray::Ray; +use crate::vec3::{Point3, Vec3}; +use crate::material::Material; +use aabb::AABB; + +#[derive(Clone)] +pub struct HitRecord { + pub p: Point3, + pub normal: Vec3, + pub material: Option>, + pub t: f64, + pub u: f64, + pub v: f64, + pub front_face: bool, +} + +impl HitRecord { + pub fn new() -> HitRecord { + HitRecord { + p: Point3 { + x: 0.0, + y: 0.0, + z: 0.0, + }, + normal: Vec3 { + x: 0.0, + y: 0.0, + z: 0.0, + }, + material: None, + t: 0.0, + u: 0.0, + v: 0.0, + front_face: false, + } + } + + pub fn set_face_normal(&mut self, ray: &Ray, outward_normal: &Vec3) { + self.front_face = ray.direction.dot(&outward_normal) < 0.0; + self.normal = if self.front_face { + outward_normal.clone() + } else { + -outward_normal + }; + } +} + +pub trait Hittable: Send + Sync { + fn hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option; + fn bounding_box(&self, time_start: f64, time_end: f64) -> Option; +} -- cgit v1.2.3