Merge pull request #435 from gendx/add_look_at_dir

Add Matrix4::look_at_dir (fix #433).
This commit is contained in:
Brendan Zabarauskas 2017-10-23 23:09:25 +11:00 committed by GitHub
commit 429249fffd

View file

@ -232,8 +232,8 @@ impl<S: BaseFloat> Matrix4<S> {
/// Create a homogeneous transformation matrix that will cause a vector to point at /// Create a homogeneous transformation matrix that will cause a vector to point at
/// `dir`, using `up` for orientation. /// `dir`, using `up` for orientation.
pub fn look_at(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> { pub fn look_at_dir(eye: Point3<S>, dir: Vector3<S>, up: Vector3<S>) -> Matrix4<S> {
let f = (center - eye).normalize(); let f = dir.normalize();
let s = f.cross(up).normalize(); let s = f.cross(up).normalize();
let u = s.cross(f); let u = s.cross(f);
@ -243,6 +243,12 @@ impl<S: BaseFloat> Matrix4<S> {
-eye.dot(s), -eye.dot(u), eye.dot(f), S::one()) -eye.dot(s), -eye.dot(u), eye.dot(f), S::one())
} }
/// Create a homogeneous transformation matrix that will cause a vector to point at
/// `center`, using `up` for orientation.
pub fn look_at(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> {
Matrix4::look_at_dir(eye, center - eye, up)
}
/// Create a homogeneous transformation matrix from a rotation around the `x` axis (pitch). /// Create a homogeneous transformation matrix from a rotation around the `x` axis (pitch).
pub fn from_angle_x<A: Into<Rad<S>>>(theta: A) -> Matrix4<S> { pub fn from_angle_x<A: Into<Rad<S>>>(theta: A) -> Matrix4<S> {
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations