Add retro (towards camera) direction to IntersectionInfo

Not tested or used yet.
This commit is contained in:
Matthew Gordon 2019-11-13 17:47:40 -05:00
parent c144780fce
commit d2fb84191e
2 changed files with 6 additions and 0 deletions

View File

@ -129,6 +129,7 @@ mod tests {
location, location,
distance: _, distance: _,
normal: _, normal: _,
retro: _,
}) => location, }) => location,
None => panic!(), None => panic!(),
}; };

View File

@ -24,6 +24,7 @@ pub struct IntersectionInfo<T: RealField> {
pub distance: T, pub distance: T,
pub location: Vector3<T>, pub location: Vector3<T>,
pub normal: Vector3<T>, pub normal: Vector3<T>,
pub retro: Vector3<T>,
} }
pub trait Intersect<T: RealField> { pub trait Intersect<T: RealField> {
@ -69,10 +70,12 @@ impl<T: RealField> Intersect<T> for Sphere<T> {
}; };
let location = ray.point_at(distance); let location = ray.point_at(distance);
let normal = (location - self.centre).normalize(); let normal = (location - self.centre).normalize();
let retro = -ray.direction;
Some(IntersectionInfo { Some(IntersectionInfo {
distance, distance,
location, location,
normal, normal,
retro,
}) })
} }
} }
@ -113,6 +116,7 @@ impl<T: RealField> Intersect<T> for Plane<T> {
distance: t, distance: t,
location: ray.point_at(t), location: ray.point_at(t),
normal: self.normal, normal: self.normal,
retro: -ray.direction,
}) })
} }
} }
@ -220,6 +224,7 @@ mod tests {
distance: _, distance: _,
location, location,
normal: _, normal: _,
retro: _,
}) => assert!((location.x - (-5.0f64)).abs() < 0.0000000001), }) => assert!((location.x - (-5.0f64)).abs() < 0.0000000001),
None => panic!(), None => panic!(),
} }