diff --git a/src/f32/mat4.rs b/src/f32/mat4.rs index 00c7ef1c..c1432fbe 100644 --- a/src/f32/mat4.rs +++ b/src/f32/mat4.rs @@ -389,29 +389,29 @@ 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).normalize(); 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] pub fn look_at_lh(eye: Vec3, center: Vec3, up: Vec3) -> Self { glam_assert!(up.is_normalized()); - Mat4::look_to_lh(eye, center - eye, up) + Mat4::look_to_lh(eye, eye - center, up) } #[inline] pub fn look_at_rh(eye: Vec3, center: Vec3, up: Vec3) -> Self { glam_assert!(up.is_normalized()); - Mat4::look_to_lh(eye, eye - center, up) + Mat4::look_to_lh(eye, center - eye, up) } #[inline]