Skip to content

Commit

Permalink
Fix Mat4::look_at*
Browse files Browse the repository at this point in the history
  • Loading branch information
repi committed Sep 17, 2019
1 parent 516e11a commit 3a87052
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/f32/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 3a87052

Please sign in to comment.