Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mat4::look_at_lh/rh #20

Merged
merged 2 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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).normalize();
repi marked this conversation as resolved.
Show resolved Hide resolved
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