diff --git a/src/matrix.rs b/src/matrix.rs index 1f12ee6..67d6295 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -26,7 +26,7 @@ use angle::Rad; use approx::ApproxEq; use euler::Euler; use num::BaseFloat; -use point::Point3; +use point::{Point2, Point3}; use quaternion::Quaternion; use transform::{Transform, Transform2, Transform3}; use vector::{Vector2, Vector3, Vector4}; @@ -756,6 +756,33 @@ impl ApproxEq for Matrix4 { } } +impl Transform> for Matrix3 { + fn one() -> Matrix3 { + One::one() + } + + fn look_at(eye: Point2, center: Point2, up: Vector2) -> Matrix3 { + let dir = center - eye; + Matrix3::from(Matrix2::look_at(dir, up)) + } + + fn transform_vector(&self, vec: Vector2) -> Vector2 { + (self * vec.extend(S::zero())).truncate() + } + + fn transform_point(&self, point: Point2) -> Point2 { + Point2::from_vec((self * Point3::new(point.x, point.y, S::one()).to_vec()).truncate()) + } + + fn concat(&self, other: &Matrix3) -> Matrix3 { + self * other + } + + fn invert(&self) -> Option> { + SquareMatrix::invert(self) + } +} + impl Transform> for Matrix3 { fn one() -> Matrix3 { One::one() @@ -809,6 +836,8 @@ impl Transform> for Matrix4 { } } +impl Transform2 for Matrix3 {} + impl Transform3 for Matrix3 {} impl Transform3 for Matrix4 {}