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.
This commit is contained in:
Aaron Loucks 2020-06-26 23:43:27 -04:00 committed by Dzmitry Malyshau
parent a628d134f1
commit c0a66d2a34
2 changed files with 10 additions and 14 deletions

View file

@ -189,7 +189,7 @@ impl<S: BaseFloat> Matrix3<S> {
/// Create a rotation matrix that will cause a vector to point at /// Create a rotation matrix that will cause a vector to point at
/// `dir`, using `up` for orientation. /// `dir`, using `up` for orientation.
#[deprecated = "Use Matrix3::look_at_lh"] #[deprecated = "Use Matrix3::look_to_lh"]
pub fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> { pub fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
let dir = dir.normalize(); let dir = dir.normalize();
let side = up.cross(dir).normalize(); let side = up.cross(dir).normalize();
@ -200,7 +200,7 @@ impl<S: BaseFloat> Matrix3<S> {
/// Create a rotation matrix that will cause a vector to point at /// Create a rotation matrix that will cause a vector to point at
/// `dir`, using `up` for orientation. /// `dir`, using `up` for orientation.
pub fn look_at_lh(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> { pub fn look_to_lh(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
let dir = dir.normalize(); let dir = dir.normalize();
let side = up.cross(dir).normalize(); let side = up.cross(dir).normalize();
let up = dir.cross(side).normalize(); let up = dir.cross(side).normalize();
@ -210,12 +210,8 @@ impl<S: BaseFloat> Matrix3<S> {
/// Create a rotation matrix that will cause a vector to point at /// Create a rotation matrix that will cause a vector to point at
/// `dir`, using `up` for orientation. /// `dir`, using `up` for orientation.
pub fn look_at_rh(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> { pub fn look_to_rh(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
let dir = -dir.normalize(); Matrix3::look_to_lh(-dir, up)
let side = up.cross(dir).normalize();
let up = dir.cross(side).normalize();
Matrix3::from_cols(side, up, dir).transpose()
} }
/// Create a rotation matrix from a rotation around the `x` axis (pitch). /// Create a rotation matrix from a rotation around the `x` axis (pitch).
@ -1135,12 +1131,12 @@ impl<S: BaseFloat> Transform<Point3<S>> for Matrix3<S> {
fn look_at_lh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> { fn look_at_lh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> {
let dir = center - eye; let dir = center - eye;
Matrix3::look_at_lh(dir, up) Matrix3::look_to_lh(dir, up)
} }
fn look_at_rh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> { fn look_at_rh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> {
let dir = center - eye; let dir = center - eye;
Matrix3::look_at_rh(dir, up) Matrix3::look_to_rh(dir, up)
} }
fn transform_vector(&self, vec: Vector3<S>) -> Vector3<S> { fn transform_vector(&self, vec: Vector3<S>) -> Vector3<S> {

View file

@ -728,10 +728,10 @@ pub mod matrix3 {
} }
#[test] #[test]
fn test_look_at_lh() { fn test_look_to_lh() {
let dir = Vector3::new(1.0, 2.0, 3.0).normalize(); let dir = Vector3::new(1.0, 2.0, 3.0).normalize();
let up = Vector3::unit_y(); 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([ assert_ulps_eq!(m, Matrix3::from([
[0.9486833, -0.16903085, 0.26726127], [0.9486833, -0.16903085, 0.26726127],
@ -744,10 +744,10 @@ pub mod matrix3 {
} }
#[test] #[test]
fn test_look_at_rh() { fn test_look_to_rh() {
let dir = Vector3::new(1.0, 2.0, 3.0).normalize(); let dir = Vector3::new(1.0, 2.0, 3.0).normalize();
let up = Vector3::unit_y(); 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([ assert_ulps_eq!(m, Matrix3::from([
[-0.9486833, -0.16903085, -0.26726127], [-0.9486833, -0.16903085, -0.26726127],