Plane-ray intersection test
This commit is contained in:
parent
7eb6f48fef
commit
6a7a3c7774
3 changed files with 11 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue