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

@ -15,8 +15,8 @@ This list may be changed or extended in the future.
- [x] Sphere normal generation
- [x] Color mapping on spheres
- [ ] Plane objects
- [ ] Plane struct
- [ ] Plane intersection test
- [x] Plane struct
- [x] Plane intersection test
- [ ] Color mapping on planes
- [ ] Triangle objects
- [ ] Triangle struct

View file

@ -1,5 +1,6 @@
mod sphere; pub use sphere::*;
mod plane; pub use plane::*;
mod triangle; pub use triangle::*;
use na::*;

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 {