Plane-ray intersection test

This commit is contained in:
bijan2005 2020-11-30 09:00:35 -05:00
parent 7eb6f48fef
commit 6a7a3c7774
3 changed files with 11 additions and 3 deletions

View file

@ -27,7 +27,14 @@ impl Plane {
{ Plane::new(center, normal, move |_, _| color) }
pub fn intersect(&self, ray: Ray) -> Option<f32> {
unimplemented!()
let d = self.normal.dot(&ray.direction);
if d < 1e-6 { return None; }
let t = (self.center - ray.origin).dot(&*self.normal) / d;
if t >= 0.0 { Some(t) }
else { None }
}
pub fn getcolor(&self, point: Point3<f32>) -> Color {