imple Transform (and Transform3) for Matrix4

The change in transform.rs is to disambiguate which invert function is used
This commit is contained in:
Mark Hintz 2016-04-27 23:54:56 +02:00
parent c32135a5d9
commit ab1d3d8622
2 changed files with 30 additions and 1 deletions

View file

@ -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<S: BaseFloat> ApproxEq for Matrix4<S> {
}
}
impl<S: BaseFloat> Transform<Point3<S>> for Matrix4<S> {
fn one() -> Matrix4<S> {
One::one()
}
fn look_at(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> {
Matrix4::look_at(eye, center, up)
}
fn transform_vector(&self, vec: Vector3<S>) -> Vector3<S> {
(self * vec.extend(S::zero())).truncate()
}
fn transform_point(&self, point: Point3<S>) -> Point3<S> {
Point3::from_homogeneous(self * point.to_homogeneous())
}
fn concat(&self, other: &Matrix4<S>) -> Matrix4<S> {
self * other
}
fn invert(&self) -> Option<Matrix4<S>> {
SquareMatrix::invert(self)
}
}
impl<S: BaseFloat> Transform3<S> for Matrix4<S> {}
macro_rules! impl_operators {
($MatrixN:ident, $VectorN:ident { $($field:ident : $row_index:expr),+ }) => {
impl_operator!(<S: BaseFloat> Neg for $MatrixN<S> {

View file

@ -197,7 +197,7 @@ impl<S: BaseFloat> Transform<Point3<S>> for AffineMatrix3<S> {
#[inline]
fn invert(&self) -> Option<AffineMatrix3<S>> {
self.mat.invert().map(|m| AffineMatrix3{ mat: m })
SquareMatrix::invert(& self.mat).map(|m| AffineMatrix3{ mat: m })
}
}