diff --git a/src/matrix.rs b/src/matrix.rs index d2bd66e..6687157 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -28,6 +28,7 @@ use euler::Euler; use num::BaseFloat; use point::Point3; use quaternion::Quaternion; +use transform::{Transform, Transform2, Transform3}; use vector::{Vector2, Vector3, Vector4}; /// A 2 x 2, column major matrix @@ -755,6 +756,34 @@ impl ApproxEq for Matrix4 { } } +impl Transform> for Matrix4 { + fn one() -> Matrix4 { + One::one() + } + + fn look_at(eye: Point3, center: Point3, up: Vector3) -> Matrix4 { + Matrix4::look_at(eye, center, up) + } + + fn transform_vector(&self, vec: Vector3) -> Vector3 { + (self * vec.extend(S::zero())).truncate() + } + + fn transform_point(&self, point: Point3) -> Point3 { + Point3::from_homogeneous(self * point.to_homogeneous()) + } + + fn concat(&self, other: &Matrix4) -> Matrix4 { + self * other + } + + fn invert(&self) -> Option> { + SquareMatrix::invert(self) + } +} + +impl Transform3 for Matrix4 {} + macro_rules! impl_operators { ($MatrixN:ident, $VectorN:ident { $($field:ident : $row_index:expr),+ }) => { impl_operator!( Neg for $MatrixN { diff --git a/src/transform.rs b/src/transform.rs index 3bf6a1d..f7c1833 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -197,7 +197,7 @@ impl Transform> for AffineMatrix3 { #[inline] fn invert(&self) -> Option> { - self.mat.invert().map(|m| AffineMatrix3{ mat: m }) + SquareMatrix::invert(& self.mat).map(|m| AffineMatrix3{ mat: m }) } }