Add Mat4::look_at
Hopefully I got this right...
This commit is contained in:
parent
4a63b1d28f
commit
8d4a06005c
1 changed files with 14 additions and 0 deletions
|
@ -19,6 +19,7 @@ use std::num::{Zero, zero, One, one, cast, sqrt};
|
|||
|
||||
use angle::{Rad, sin, cos, sin_cos};
|
||||
use array::{Array, build};
|
||||
use point::{Point, Point3};
|
||||
use quaternion::{Quat, ToQuat};
|
||||
use vector::{Vector, EuclideanVector};
|
||||
use vector::{Vec2, Vec3, Vec4};
|
||||
|
@ -222,6 +223,19 @@ impl<S: Primitive> Mat4<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: Float> Mat4<S> {
|
||||
pub fn look_at(eye: &Point3<S>, center: &Point3<S>, up: &Vec3<S>) -> Mat4<S> {
|
||||
let f = center.sub_p(eye).normalize();
|
||||
let s = f.cross(&up.normalize());
|
||||
let u = s.cross(&f).normalize();
|
||||
|
||||
Mat4::new(s.x.clone(), s.y.clone(), s.z.clone(), zero(),
|
||||
u.x.clone(), u.y.clone(), u.z.clone(), zero(),
|
||||
-f.x.clone(), -f.y.clone(), -f.z.clone(), zero(),
|
||||
-eye.dot(&s), -eye.dot(&u), -eye.dot(&f), one())
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Float> One for Mat2<S> { #[inline] fn one() -> Mat2<S> { Mat2::identity() } }
|
||||
impl<S: Float> One for Mat3<S> { #[inline] fn one() -> Mat3<S> { Mat3::identity() } }
|
||||
impl<S: Float> One for Mat4<S> { #[inline] fn one() -> Mat4<S> { Mat4::identity() } }
|
||||
|
|
Loading…
Reference in a new issue