Plane-ray intersection test
This commit is contained in:
parent
7eb6f48fef
commit
6a7a3c7774
|
@ -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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
mod sphere; pub use sphere::*;
|
||||
mod plane; pub use plane::*;
|
||||
mod triangle; pub use triangle::*;
|
||||
|
||||
use na::*;
|
||||
|
|
|
@ -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…
Reference in a new issue