Implement Transform trait for Plane
Still needs unit tests.
This commit is contained in:
parent
a856fcbc21
commit
5df3f81359
|
|
@ -1,9 +1,9 @@
|
|||
use nalgebra::{convert, Point3, Vector3};
|
||||
use nalgebra::{convert, Affine3, Point3, Vector3};
|
||||
|
||||
use crate::materials::Material;
|
||||
use crate::Real;
|
||||
|
||||
use super::{BoundingBox, HasBoundingBox, Intersect, IntersectionInfo, Primitive, Ray};
|
||||
use super::{BoundingBox, HasBoundingBox, Intersect, IntersectionInfo, Primitive, Ray, Transform};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -36,6 +36,18 @@ impl<T: Real> Plane<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Real> Transform<T> for Plane<T> {
|
||||
fn transform(&mut self, transformation: &Affine3<T>) -> &Self {
|
||||
self.normal = transformation.transform_vector(&self.normal).normalize();
|
||||
self.cotangent = transformation.transform_vector(&self.cotangent).normalize();
|
||||
self.cotangent = self.normal.cross(&self.cotangent);
|
||||
self.distance_from_origin = transformation
|
||||
.transform_vector(&(self.normal * self.distance_from_origin))
|
||||
.norm();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Real> Intersect<T> for Plane<T> {
|
||||
fn intersect<'a>(&'a self, ray: &Ray<T>) -> Option<IntersectionInfo<T>> {
|
||||
let ray_direction_dot_plane_normal = ray.direction.dot(&self.normal);
|
||||
|
|
|
|||
Loading…
Reference in New Issue