From 50d424a9019f4714ca5c7452dfa2a9140527214c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 29 Jun 2013 15:32:56 +0000 Subject: [PATCH] Changed the representation of rotations for 3D matrix. --- src/adaptors/rotmat.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index 42355585..2a5a3cce 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -1,7 +1,6 @@ use std::num::{One, Zero}; use std::rand::{Rand, Rng, RngUtil}; use std::cmp::ApproxEq; -use traits::ring::Ring; use traits::division_ring::DivisionRing; use traits::rlmul::{RMul, LMul}; use traits::dim::Dim; @@ -11,6 +10,7 @@ use traits::rotation::{Rotation, Rotate, Rotatable}; use traits::transformation::{Transform}; // FIXME: implement Transformation and Transformable use traits::homogeneous::ToHomogeneous; use traits::indexable::Indexable; +use traits::norm::Norm; use vec::Vec1; use mat::{Mat2, Mat3}; use vec::Vec3; @@ -28,9 +28,11 @@ pub fn rotmat2>(angle: N) -> Rotmat> { submat: Mat2::new( [ copy coa, -sia, copy sia, copy coa ] ) } } -pub fn rotmat3 -(axis: &Vec3, angle: N) -> Rotmat> +pub fn rotmat3 +(axisangle: Vec3) -> Rotmat> { + let mut axis = axisangle; + let angle = axis.normalize(); let _1 = One::one::(); let ux = copy axis.at[0]; let uy = copy axis.at[1]; @@ -82,29 +84,29 @@ Rotatable, Rotmat>> for Rotmat> { rotmat2(copy rot.at[0]) * *self } } -impl -Rotation<(Vec3, N)> for Rotmat> +impl +Rotation> for Rotmat> { #[inline] - fn rotation(&self) -> (Vec3, N) + fn rotation(&self) -> Vec3 { fail!("Not yet implemented.") } #[inline] - fn inv_rotation(&self) -> (Vec3, N) + fn inv_rotation(&self) -> Vec3 { fail!("Not yet implemented.") } #[inline] - fn rotate_by(&mut self, rot: &(Vec3, N)) + fn rotate_by(&mut self, rot: &Vec3) { *self = self.rotated(rot) } } -impl -Rotatable<(Vec3, N), Rotmat>> for Rotmat> +impl +Rotatable, Rotmat>> for Rotmat> { #[inline] - fn rotated(&self, &(axis, angle): &(Vec3, N)) -> Rotmat> - { rotmat3(&axis, angle) * *self } + fn rotated(&self, axisangle: &Vec3) -> Rotmat> + { rotmat3(copy *axisangle) * *self } } impl> Rand for Rotmat> @@ -136,12 +138,12 @@ impl + LMul, V> Transform for Rotmat { self.inv_rotate(v) } } -impl +impl Rand for Rotmat> { #[inline] fn rand(rng: &mut R) -> Rotmat> - { rotmat3(&rng.gen(), rng.gen()) } + { rotmat3(rng.gen()) } } impl Dim for Rotmat