Skip to content

Commit c591e4d

Browse files
committed
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.
1 parent 5045954 commit c591e4d

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/matrix.rs

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

190190
/// Create a rotation matrix that will cause a vector to point at
191191
/// `dir`, using `up` for orientation.
192-
#[deprecated = "Use Matrix3::look_at_lh"]
192+
#[deprecated = "Use Matrix3::look_to_lh"]
193193
pub fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
194194
let dir = dir.normalize();
195195
let side = up.cross(dir).normalize();
@@ -200,7 +200,7 @@ impl<S: BaseFloat> Matrix3<S> {
200200

201201
/// Create a rotation matrix that will cause a vector to point at
202202
/// `dir`, using `up` for orientation.
203-
pub fn look_at_lh(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
203+
pub fn look_to_lh(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
204204
let dir = dir.normalize();
205205
let side = up.cross(dir).normalize();
206206
let up = dir.cross(side).normalize();
@@ -210,12 +210,8 @@ impl<S: BaseFloat> Matrix3<S> {
210210

211211
/// Create a rotation matrix that will cause a vector to point at
212212
/// `dir`, using `up` for orientation.
213-
pub fn look_at_rh(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
214-
let dir = -dir.normalize();
215-
let side = up.cross(dir).normalize();
216-
let up = dir.cross(side).normalize();
217-
218-
Matrix3::from_cols(side, up, dir).transpose()
213+
pub fn look_to_rh(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
214+
Matrix3::look_to_lh(-dir, up)
219215
}
220216

221217
/// 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> {
11351131

11361132
fn look_at_lh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> {
11371133
let dir = center - eye;
1138-
Matrix3::look_at_lh(dir, up)
1134+
Matrix3::look_to_lh(dir, up)
11391135
}
11401136

11411137
fn look_at_rh(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix3<S> {
11421138
let dir = center - eye;
1143-
Matrix3::look_at_rh(dir, up)
1139+
Matrix3::look_to_rh(dir, up)
11441140
}
11451141

11461142
fn transform_vector(&self, vec: Vector3<S>) -> Vector3<S> {

tests/matrix.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,10 @@ pub mod matrix3 {
728728
}
729729

730730
#[test]
731-
fn test_look_at_lh() {
731+
fn test_look_to_lh() {
732732
let dir = Vector3::new(1.0, 2.0, 3.0).normalize();
733733
let up = Vector3::unit_y();
734-
let m = Matrix3::look_at_lh(dir, up);
734+
let m = Matrix3::look_to_lh(dir, up);
735735

736736
assert_ulps_eq!(m, Matrix3::from([
737737
[0.9486833, -0.16903085, 0.26726127],
@@ -744,10 +744,10 @@ pub mod matrix3 {
744744
}
745745

746746
#[test]
747-
fn test_look_at_rh() {
747+
fn test_look_to_rh() {
748748
let dir = Vector3::new(1.0, 2.0, 3.0).normalize();
749749
let up = Vector3::unit_y();
750-
let m = Matrix3::look_at_rh(dir, up);
750+
let m = Matrix3::look_to_rh(dir, up);
751751

752752
assert_ulps_eq!(m, Matrix3::from([
753753
[-0.9486833, -0.16903085, -0.26726127],

0 commit comments

Comments
 (0)