From c0a66d2a341d76b97f199fed0fe4d0034c1d33fe Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Fri, 26 Jun 2020 23:43:27 -0400 Subject: [PATCH] Rename Matrix3::look_at_[rh|lh] to look_to_[rh|lh] This makes the Matrix3/4 and Decomposed `look_at_*` functions consistent with looking at a center/focus point and `look_to_*` functions consistent with looking in a direction. --- src/matrix.rs | 16 ++++++---------- tests/matrix.rs | 8 ++++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/matrix.rs b/src/matrix.rs index e5548a2..df8b4e9 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -189,7 +189,7 @@ impl Matrix3 { /// Create a rotation matrix that will cause a vector to point at /// `dir`, using `up` for orientation. - #[deprecated = "Use Matrix3::look_at_lh"] + #[deprecated = "Use Matrix3::look_to_lh"] pub fn look_at(dir: Vector3, up: Vector3) -> Matrix3 { let dir = dir.normalize(); let side = up.cross(dir).normalize(); @@ -200,7 +200,7 @@ impl Matrix3 { /// Create a rotation matrix that will cause a vector to point at /// `dir`, using `up` for orientation. - pub fn look_at_lh(dir: Vector3, up: Vector3) -> Matrix3 { + pub fn look_to_lh(dir: Vector3, up: Vector3) -> Matrix3 { let dir = dir.normalize(); let side = up.cross(dir).normalize(); let up = dir.cross(side).normalize(); @@ -210,12 +210,8 @@ impl Matrix3 { /// Create a rotation matrix that will cause a vector to point at /// `dir`, using `up` for orientation. - pub fn look_at_rh(dir: Vector3, up: Vector3) -> Matrix3 { - let dir = -dir.normalize(); - let side = up.cross(dir).normalize(); - let up = dir.cross(side).normalize(); - - Matrix3::from_cols(side, up, dir).transpose() + pub fn look_to_rh(dir: Vector3, up: Vector3) -> Matrix3 { + Matrix3::look_to_lh(-dir, up) } /// Create a rotation matrix from a rotation around the `x` axis (pitch). @@ -1135,12 +1131,12 @@ impl Transform> for Matrix3 { fn look_at_lh(eye: Point3, center: Point3, up: Vector3) -> Matrix3 { let dir = center - eye; - Matrix3::look_at_lh(dir, up) + Matrix3::look_to_lh(dir, up) } fn look_at_rh(eye: Point3, center: Point3, up: Vector3) -> Matrix3 { let dir = center - eye; - Matrix3::look_at_rh(dir, up) + Matrix3::look_to_rh(dir, up) } fn transform_vector(&self, vec: Vector3) -> Vector3 { diff --git a/tests/matrix.rs b/tests/matrix.rs index cdd4b7b..177ca4f 100644 --- a/tests/matrix.rs +++ b/tests/matrix.rs @@ -728,10 +728,10 @@ pub mod matrix3 { } #[test] - fn test_look_at_lh() { + fn test_look_to_lh() { let dir = Vector3::new(1.0, 2.0, 3.0).normalize(); let up = Vector3::unit_y(); - let m = Matrix3::look_at_lh(dir, up); + let m = Matrix3::look_to_lh(dir, up); assert_ulps_eq!(m, Matrix3::from([ [0.9486833, -0.16903085, 0.26726127], @@ -744,10 +744,10 @@ pub mod matrix3 { } #[test] - fn test_look_at_rh() { + fn test_look_to_rh() { let dir = Vector3::new(1.0, 2.0, 3.0).normalize(); let up = Vector3::unit_y(); - let m = Matrix3::look_at_rh(dir, up); + let m = Matrix3::look_to_rh(dir, up); assert_ulps_eq!(m, Matrix3::from([ [-0.9486833, -0.16903085, -0.26726127],