From 72ce1881ce777df3b5cf9439652a4030044bc72b Mon Sep 17 00:00:00 2001 From: Jeroen Bollen Date: Tue, 15 Sep 2015 19:47:27 +0200 Subject: [PATCH] Fixed issue #154 https://github.com/sebcrozet/nalgebra/issues/154 --- src/structs/iso.rs | 4 ++-- src/structs/rot.rs | 34 ++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/structs/iso.rs b/src/structs/iso.rs index e1d2a062..b8e6957e 100644 --- a/src/structs/iso.rs +++ b/src/structs/iso.rs @@ -70,7 +70,7 @@ impl Iso3 { /// * up - Vector pointing up. The only requirement of this parameter is to not be colinear /// with `at`. Non-colinearity is not checked. pub fn look_at(&mut self, eye: &Pnt3, at: &Pnt3, up: &Vec3) { - self.rotation.look_at(&(*at - *eye), up); + self.rotation = Rot3::look_at(&(*at - *eye), up); self.translation = eye.as_vec().clone(); } @@ -84,7 +84,7 @@ impl Iso3 { /// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear /// with `at`. Non-colinearity is not checked. pub fn look_at_z(&mut self, eye: &Pnt3, at: &Pnt3, up: &Vec3) { - self.rotation.look_at_z(&(*at - *eye), up); + self.rotation = Rot3::look_at_z(&(*at - *eye), up); self.translation = eye.as_vec().clone(); } } diff --git a/src/structs/rot.rs b/src/structs/rot.rs index ebf24217..aa60f33d 100644 --- a/src/structs/rot.rs +++ b/src/structs/rot.rs @@ -195,41 +195,47 @@ impl Rot3 { } impl Rot3 { - /// Reorient this matrix such that its local `x` axis points to a given point. Note that the - /// usually known `look_at` function does the same thing but with the `z` axis. See `look_at_z` - /// for that. + /// Create a new matrix and orient it such that its local `x` axis points to a given point. + /// Note that the usually known `look_at` function does the same thing but with the `z` axis. + /// See `look_at_z` for that. /// /// # Arguments /// * at - The point to look at. It is also the direction the matrix `x` axis will be aligned /// with /// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear /// with `at`. Non-colinearity is not checked. - pub fn look_at(&mut self, at: &Vec3, up: &Vec3) { + pub fn look_at(at: &Vec3, up: &Vec3) -> Rot3 { let xaxis = Norm::normalize(at); let zaxis = Norm::normalize(&Cross::cross(up, &xaxis)); let yaxis = Cross::cross(&zaxis, &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) + unsafe { + Rot3::new_with_mat(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) + ) + } } - /// 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 /// * 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 /// with `at`. Non-colinearity is not checked. - pub fn look_at_z(&mut self, at: &Vec3, up: &Vec3) { + pub fn look_at_z(at: &Vec3, up: &Vec3) -> Rot3 { let zaxis = Norm::normalize(at); let xaxis = Norm::normalize(&Cross::cross(up, &zaxis)); let yaxis = Cross::cross(&zaxis, &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) + unsafe { + Rot3::new_with_mat(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) + ) + } } }