This commit is contained in:
Jeroen Bollen 2015-09-15 19:47:27 +02:00
parent 0bcbd4df4b
commit 72ce1881ce
2 changed files with 22 additions and 16 deletions

View File

@ -70,7 +70,7 @@ impl<N: Clone + BaseFloat> Iso3<N> {
/// * up - Vector pointing up. The only requirement of this parameter is to not be colinear /// * up - Vector pointing up. The only requirement of this parameter is to not be colinear
/// with `at`. Non-colinearity is not checked. /// with `at`. Non-colinearity is not checked.
pub fn look_at(&mut self, eye: &Pnt3<N>, at: &Pnt3<N>, up: &Vec3<N>) { pub fn look_at(&mut self, eye: &Pnt3<N>, at: &Pnt3<N>, up: &Vec3<N>) {
self.rotation.look_at(&(*at - *eye), up); self.rotation = Rot3::look_at(&(*at - *eye), up);
self.translation = eye.as_vec().clone(); self.translation = eye.as_vec().clone();
} }
@ -84,7 +84,7 @@ impl<N: Clone + BaseFloat> Iso3<N> {
/// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear /// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear
/// with `at`. Non-colinearity is not checked. /// with `at`. Non-colinearity is not checked.
pub fn look_at_z(&mut self, eye: &Pnt3<N>, at: &Pnt3<N>, up: &Vec3<N>) { pub fn look_at_z(&mut self, eye: &Pnt3<N>, at: &Pnt3<N>, up: &Vec3<N>) {
self.rotation.look_at_z(&(*at - *eye), up); self.rotation = Rot3::look_at_z(&(*at - *eye), up);
self.translation = eye.as_vec().clone(); self.translation = eye.as_vec().clone();
} }
} }

View File

@ -195,41 +195,47 @@ impl<N: Clone + BaseFloat> Rot3<N> {
} }
impl<N: Clone + BaseFloat> Rot3<N> { impl<N: Clone + BaseFloat> Rot3<N> {
/// Reorient this matrix such that its local `x` axis points to a given point. Note that the /// Create a new matrix and orient it such that its local `x` axis points to a given point.
/// usually known `look_at` function does the same thing but with the `z` axis. See `look_at_z` /// Note that the usually known `look_at` function does the same thing but with the `z` axis.
/// for that. /// See `look_at_z` for that.
/// ///
/// # Arguments /// # Arguments
/// * at - The point to look at. It is also the direction the matrix `x` axis will be aligned /// * at - The point to look at. It is also the direction the matrix `x` axis will be aligned
/// with /// with
/// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear /// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear
/// with `at`. Non-colinearity is not checked. /// with `at`. Non-colinearity is not checked.
pub fn look_at(&mut self, at: &Vec3<N>, up: &Vec3<N>) { pub fn look_at(at: &Vec3<N>, up: &Vec3<N>) -> Rot3<N> {
let xaxis = Norm::normalize(at); let xaxis = Norm::normalize(at);
let zaxis = Norm::normalize(&Cross::cross(up, &xaxis)); let zaxis = Norm::normalize(&Cross::cross(up, &xaxis));
let yaxis = Cross::cross(&zaxis, &xaxis); let yaxis = Cross::cross(&zaxis, &xaxis);
self.submat = Mat3::new( unsafe {
Rot3::new_with_mat(Mat3::new(
xaxis.x.clone(), yaxis.x.clone(), zaxis.x.clone(), xaxis.x.clone(), yaxis.x.clone(), zaxis.x.clone(),
xaxis.y.clone(), yaxis.y.clone(), zaxis.y.clone(), xaxis.y.clone(), yaxis.y.clone(), zaxis.y.clone(),
xaxis.z , yaxis.z , zaxis.z) xaxis.z , yaxis.z , zaxis.z)
)
}
} }
/// Reorient this matrix such that its local `z` axis points to a given point. /// Create a new matrix and orient it such that its local `z` axis points to a given point.
/// ///
/// # Arguments /// # Arguments
/// * at - The look direction, that is, direction the matrix `y` axis will be aligned with /// * at - The look direction, that is, direction the matrix `y` axis will be aligned with
/// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear /// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear
/// with `at`. Non-colinearity is not checked. /// with `at`. Non-colinearity is not checked.
pub fn look_at_z(&mut self, at: &Vec3<N>, up: &Vec3<N>) { pub fn look_at_z(at: &Vec3<N>, up: &Vec3<N>) -> Rot3<N> {
let zaxis = Norm::normalize(at); let zaxis = Norm::normalize(at);
let xaxis = Norm::normalize(&Cross::cross(up, &zaxis)); let xaxis = Norm::normalize(&Cross::cross(up, &zaxis));
let yaxis = Cross::cross(&zaxis, &xaxis); let yaxis = Cross::cross(&zaxis, &xaxis);
self.submat = Mat3::new( unsafe {
Rot3::new_with_mat(Mat3::new(
xaxis.x.clone(), yaxis.x.clone(), zaxis.x.clone(), xaxis.x.clone(), yaxis.x.clone(), zaxis.x.clone(),
xaxis.y.clone(), yaxis.y.clone(), zaxis.y.clone(), xaxis.y.clone(), yaxis.y.clone(), zaxis.y.clone(),
xaxis.z , yaxis.z , zaxis.z) xaxis.z , yaxis.z , zaxis.z)
)
}
} }
} }