raytracers/rtiow/renderer/src/flip_normals.rs
Bill Thiede 4066bf4b85 rtiow: add blox with gloxy edges.
Fixed bug in kdtree that this uncovered.
Marked Hit and it's dependencies as needing to implement the Debug
trait.
2022-09-17 16:45:29 -07:00

42 lines
745 B
Rust

use crate::{
aabb::AABB,
hitable::{Hit, HitRecord},
ray::Ray,
};
#[derive(Debug)]
pub struct FlipNormals<H>
where
H: Hit,
{
hitable: H,
}
impl<H> FlipNormals<H>
where
H: Hit,
{
pub fn new(hitable: H) -> FlipNormals<H> {
FlipNormals { hitable }
}
}
impl<H> Hit for FlipNormals<H>
where
H: Hit,
{
fn hit(&self, r: Ray, t_min: f32, t_max: f32) -> Option<HitRecord> {
if let Some(rec) = self.hitable.hit(r, t_min, t_max) {
return Some(HitRecord {
normal: -rec.normal,
..rec
});
};
None
}
fn bounding_box(&self, t_min: f32, t_max: f32) -> Option<AABB> {
self.hitable.bounding_box(t_min, t_max)
}
}