Matrix::transform_point: correctly take the normalization term into account.

Fix #640
This commit is contained in:
sebcrozet 2019-08-27 14:30:20 +02:00 committed by Sébastien Crozet
parent e170729f67
commit cfb654240c
2 changed files with 17 additions and 4 deletions

View File

@ -358,10 +358,10 @@ where DefaultAllocator: Allocator<N, D, D>
+ unsafe { *self.get_unchecked((D::dim() - 1, D::dim() - 1)) };
if !n.is_zero() {
return transform * (pt / n) + translation;
(transform * pt + translation) / n
} else {
transform * pt + translation
}
transform * pt + translation
}
}

View File

@ -1,4 +1,4 @@
use na::{Orthographic3, Perspective3};
use na::{Orthographic3, Perspective3, Point3};
#[test]
fn perspective_inverse() {
@ -20,6 +20,19 @@ fn orthographic_inverse() {
assert!(id.is_identity(1.0e-7));
}
#[test]
fn perspective_matrix_point_transformation() {
// https://github.com/rustsim/nalgebra/issues/640
let proj = Perspective3::new(4.0 / 3.0, 90.0, 0.1, 100.0);
let perspective_inv = proj.as_matrix().try_inverse().unwrap();
let some_point = Point3::new(1.0, 2.0, 0.0);
assert_eq!(
perspective_inv.transform_point(&some_point),
Point3::from_homogeneous(perspective_inv * some_point.coords.push(1.0)).unwrap()
);
}
#[cfg(feature = "arbitrary")]
mod quickcheck_tests {
use na::{Orthographic3, Perspective3, Point3};