Skip to content

Commit

Permalink
Merge pull request #20 from EmbarkStudios/mat4-look-at
Browse files Browse the repository at this point in the history
Fix Mat4::look_at_lh/rh
  • Loading branch information
bitshifter committed Sep 17, 2019
2 parents 516e11a + 55b1c61 commit 083f6a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/f32/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,17 @@ impl Mat4 {
// TODO: make public at some point
fn look_to_lh(eye: Vec3, dir: Vec3, up: Vec3) -> Self {
let f = dir.normalize();
let s = up.cross(f).normalize();
let u = f.cross(s);
let (fx, fy, fz) = f.into();
let s = f.cross(up);
let (sx, sy, sz) = s.into();
let u = s.cross(f);
let (ux, uy, uz) = u.into();
Self {
x_axis: Vec4::new(sx, ux, -fx, 0.0),
y_axis: Vec4::new(sy, uy, -fy, 0.0),
z_axis: Vec4::new(sz, uz, -fz, 0.0),
w_axis: Vec4::new(-s.dot(eye), -u.dot(eye), f.dot(eye), 1.0),
}
Mat4::new(
Vec4::new(sx, ux, fx, 0.0),
Vec4::new(sy, uy, fy, 0.0),
Vec4::new(sz, uz, fz, 0.0),
Vec4::new(-s.dot(eye), -u.dot(eye), -f.dot(eye), 1.0),
)
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions tests/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ fn test_mat4_look_at() {
let lh = Mat4::look_at_lh(eye, center, up);
let rh = Mat4::look_at_rh(eye, center, up);
let point = Vec3::new(1.0, 0.0, 0.0);
assert_ulps_eq!(lh.transform_point3(point), Vec3::new(0.0, 1.0, -5.0));
assert_ulps_eq!(rh.transform_point3(point), Vec3::new(0.0, 1.0, 5.0));
assert_ulps_eq!(lh.transform_point3(point), Vec3::new(0.0, 1.0, 5.0));
assert_ulps_eq!(rh.transform_point3(point), Vec3::new(0.0, 1.0, -5.0));
}

#[test]
Expand Down

0 comments on commit 083f6a7

Please sign in to comment.