40 lines
751 B
Rust
40 lines
751 B
Rust
use crate::aabb::AABB;
|
|
use crate::hitable::Hit;
|
|
use crate::hitable::HitRecord;
|
|
use crate::ray::Ray;
|
|
|
|
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)
|
|
}
|
|
}
|