Skip to content

Commit 18eec70

Browse files
committed
Fix deprecated look_at usage + remove repeated code
Remove a repated instance of Matrix4 look_at transform.
1 parent d41dc56 commit 18eec70

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed

src/matrix.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<S: BaseFloat> Matrix3<S> {
204204

205205
/// Create a rotation matrix that will cause a vector to point at
206206
/// `dir`, using `up` for orientation.
207-
#[deprecated = "Use Matrix3::look_to_lh"]
207+
#[deprecated = "Use Matrix3::look_to_lh or Matrix3::look_to_rh for the right handed variation"]
208208
pub fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
209209
Matrix3::look_to_lh(dir, up)
210210
}
@@ -361,19 +361,9 @@ impl<S: BaseFloat> Matrix4<S> {
361361

362362
/// Create a homogeneous transformation matrix that will cause a vector to point at
363363
/// `dir`, using `up` for orientation.
364-
#[deprecated = "Use Matrix4::look_to_rh"]
364+
#[deprecated = "Use Matrix4::look_to_rh or Matrix3::look_to_lh for the left handed variation"]
365365
pub fn look_at_dir(eye: Point3<S>, dir: Vector3<S>, up: Vector3<S>) -> Matrix4<S> {
366-
let f = dir.normalize();
367-
let s = f.cross(up).normalize();
368-
let u = s.cross(f);
369-
370-
#[cfg_attr(rustfmt, rustfmt_skip)]
371-
Matrix4::new(
372-
s.x.clone(), u.x.clone(), -f.x.clone(), S::zero(),
373-
s.y.clone(), u.y.clone(), -f.y.clone(), S::zero(),
374-
s.z.clone(), u.z.clone(), -f.z.clone(), S::zero(),
375-
-eye.dot(s), -eye.dot(u), eye.dot(f), S::one(),
376-
)
366+
Self::look_to_rh(eye, dir, up)
377367
}
378368

379369
/// Create a homogeneous transformation matrix that will cause a vector to point at
@@ -400,9 +390,9 @@ impl<S: BaseFloat> Matrix4<S> {
400390

401391
/// Create a homogeneous transformation matrix that will cause a vector to point at
402392
/// `center`, using `up` for orientation.
403-
#[deprecated = "Use Matrix4::look_at_rh"]
393+
#[deprecated = "Use Matrix4::look_at_rh or look_at_lh for the left handed variation"]
404394
pub fn look_at(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> {
405-
Matrix4::look_at_dir(eye, center - eye, up)
395+
Matrix4::look_to_rh(eye, center - eye, up)
406396
}
407397

408398
/// Create a homogeneous transformation matrix that will cause a vector to point at
@@ -1145,7 +1135,7 @@ impl<S: BaseFloat> Transform<Point3<S>> for Matrix3<S> {
11451135

11461136
fn look_at(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> {
11471137
let dir = center - eye;
1148-
Matrix3::look_at(dir, up)
1138+
Matrix3::look_to_lh(dir, up)
11491139
}
11501140

11511141
fn look_at_lh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> {

src/quaternion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl<S: BaseFloat> From<Quaternion<S>> for Basis3<S> {
475475
impl<S: BaseFloat> Rotation<Point3<S>> for Quaternion<S> {
476476
#[inline]
477477
fn look_to(dir: Vector3<S>, up: Vector3<S>) -> Quaternion<S> {
478-
Matrix3::look_at(dir, up).into()
478+
Matrix3::look_to_lh(dir, up).into()
479479
}
480480

481481
#[inline]

src/rotation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<S: BaseFloat> Rotation<Point3<S>> for Basis3<S> {
344344
#[inline]
345345
fn look_to(dir: Vector3<S>, up: Vector3<S>) -> Basis3<S> {
346346
Basis3 {
347-
mat: Matrix3::look_at(dir, up),
347+
mat: Matrix3::look_to_lh(dir, up),
348348
}
349349
}
350350

src/transform.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ pub trait Transform<P: EuclideanSpace>: Sized {
3333
/// Create a transformation that rotates a vector to look at `center` from
3434
/// `eye`, using `up` for orientation.
3535
#[deprecated = "Use look_at_rh or look_at_lh"]
36-
fn look_at(eye: P, center: P, up: P::Diff) -> Self;
36+
fn look_at(eye: P, center: P, up: P::Diff) -> Self {
37+
Self::look_at_lh(eye, center, up)
38+
}
3739

3840
/// Create a transformation that rotates a vector to look at `center` from
3941
/// `eye`, using `up` for orientation.
@@ -95,7 +97,7 @@ where
9597

9698
#[inline]
9799
fn look_at(eye: P, center: P, up: P::Diff) -> Decomposed<P::Diff, R> {
98-
let rot = R::look_at(center - eye, up);
100+
let rot = R::look_to(center - eye, up);
99101
let disp = rot.rotate_vector(P::origin() - eye);
100102
Decomposed {
101103
scale: P::Scalar::one(),
@@ -106,7 +108,7 @@ where
106108

107109
#[inline]
108110
fn look_at_lh(eye: P, center: P, up: P::Diff) -> Decomposed<P::Diff, R> {
109-
let rot = R::look_at(center - eye, up);
111+
let rot = R::look_to(center - eye, up);
110112
let disp = rot.rotate_vector(P::origin() - eye);
111113
Decomposed {
112114
scale: P::Scalar::one(),
@@ -117,7 +119,7 @@ where
117119

118120
#[inline]
119121
fn look_at_rh(eye: P, center: P, up: P::Diff) -> Decomposed<P::Diff, R> {
120-
let rot = R::look_at(eye - center, up);
122+
let rot = R::look_to(eye - center, up);
121123
let disp = rot.rotate_vector(P::origin() - eye);
122124
Decomposed {
123125
scale: P::Scalar::one(),

tests/matrix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ pub mod matrix3 {
740740
]));
741741

742742
#[allow(deprecated)]
743-
assert_ulps_eq!(m, Matrix3::look_at(dir, up));
743+
assert_ulps_eq!(m, Matrix3::look_to_lh(dir, up));
744744
}
745745

746746
#[test]
@@ -1164,7 +1164,7 @@ pub mod matrix4 {
11641164

11651165
let m = Matrix4::look_to_rh(eye, dir, up);
11661166
#[allow(deprecated)]
1167-
assert_ulps_eq!(m, Matrix4::look_at_dir(eye, dir, up));
1167+
assert_ulps_eq!(m, Matrix4::look_to_rh(eye, dir, up));
11681168

11691169
let expected = Matrix4::from([
11701170
[-0.9486833, -0.16903086, -0.26726127, 0.0],

0 commit comments

Comments
 (0)