raytracers/rtiow/renderer/src/flip_normals.rs
Bill Thiede d9d183b1e5
Some checks failed
continuous-integration/drone/push Build is failing
rtiow: break project into multiple workspaces.
2019-11-09 11:56:33 -08:00

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)
}
}