Add look_at_z.

Having a look_at which aligns the z-axis with the look_at direction is useful for cameras. It
will exist only in 3d.
This commit is contained in:
Sébastien Crozet 2013-07-23 18:41:57 +02:00
parent 8634b9037d
commit 93597f0ef9
2 changed files with 17 additions and 0 deletions

View File

@ -86,6 +86,17 @@ impl<N: Clone + DivisionRing + Algebraic> Rotmat<Mat3<N>>
xaxis.y.clone(), yaxis.y.clone(), zaxis.y.clone(),
xaxis.z , yaxis.z , zaxis.z)
}
pub fn look_at_z(&mut self, at: &Vec3<N>, up: &Vec3<N>)
{
let zaxis = at.normalized();
let xaxis = up.cross(&zaxis).normalized();
let yaxis = zaxis.cross(&xaxis);
self.submat = Mat3::new(xaxis.x.clone(), yaxis.x.clone(), zaxis.x.clone(),
xaxis.y.clone(), yaxis.y.clone(), zaxis.y.clone(),
xaxis.z , yaxis.z , zaxis.z)
}
}
impl<N: Trigonometric + DivisionRing + Clone>

View File

@ -47,6 +47,12 @@ impl<N: Clone + DivisionRing + Algebraic> Transform<Rotmat<Mat3<N>>, Vec3<N>>
self.submat.look_at(&(*at - *eye), up);
self.subtrans = eye.clone();
}
pub fn look_at_z(&mut self, eye: &Vec3<N>, at: &Vec3<N>, up: &Vec3<N>)
{
self.submat.look_at_z(&(*at - *eye), up);
self.subtrans = eye.clone();
}
}
impl<M: Dim, V> Dim for Transform<M, V>