Changed the representation of rotations for 3D matrix.
This commit is contained in:
parent
429bcbf9c3
commit
50d424a901
|
@ -1,7 +1,6 @@
|
||||||
use std::num::{One, Zero};
|
use std::num::{One, Zero};
|
||||||
use std::rand::{Rand, Rng, RngUtil};
|
use std::rand::{Rand, Rng, RngUtil};
|
||||||
use std::cmp::ApproxEq;
|
use std::cmp::ApproxEq;
|
||||||
use traits::ring::Ring;
|
|
||||||
use traits::division_ring::DivisionRing;
|
use traits::division_ring::DivisionRing;
|
||||||
use traits::rlmul::{RMul, LMul};
|
use traits::rlmul::{RMul, LMul};
|
||||||
use traits::dim::Dim;
|
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::transformation::{Transform}; // FIXME: implement Transformation and Transformable
|
||||||
use traits::homogeneous::ToHomogeneous;
|
use traits::homogeneous::ToHomogeneous;
|
||||||
use traits::indexable::Indexable;
|
use traits::indexable::Indexable;
|
||||||
|
use traits::norm::Norm;
|
||||||
use vec::Vec1;
|
use vec::Vec1;
|
||||||
use mat::{Mat2, Mat3};
|
use mat::{Mat2, Mat3};
|
||||||
use vec::Vec3;
|
use vec::Vec3;
|
||||||
|
@ -28,9 +28,11 @@ pub fn rotmat2<N: Copy + Trigonometric + Neg<N>>(angle: N) -> Rotmat<Mat2<N>>
|
||||||
{ submat: Mat2::new( [ copy coa, -sia, copy sia, copy coa ] ) }
|
{ submat: Mat2::new( [ copy coa, -sia, copy sia, copy coa ] ) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rotmat3<N: Copy + Trigonometric + Ring>
|
pub fn rotmat3<N: Copy + Trigonometric + DivisionRing + Algebraic>
|
||||||
(axis: &Vec3<N>, angle: N) -> Rotmat<Mat3<N>>
|
(axisangle: Vec3<N>) -> Rotmat<Mat3<N>>
|
||||||
{
|
{
|
||||||
|
let mut axis = axisangle;
|
||||||
|
let angle = axis.normalize();
|
||||||
let _1 = One::one::<N>();
|
let _1 = One::one::<N>();
|
||||||
let ux = copy axis.at[0];
|
let ux = copy axis.at[0];
|
||||||
let uy = copy axis.at[1];
|
let uy = copy axis.at[1];
|
||||||
|
@ -82,29 +84,29 @@ Rotatable<Vec1<N>, Rotmat<Mat2<N>>> for Rotmat<Mat2<N>>
|
||||||
{ rotmat2(copy rot.at[0]) * *self }
|
{ rotmat2(copy rot.at[0]) * *self }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Trigonometric + DivisionRing>
|
impl<N: Copy + Trigonometric + DivisionRing + Algebraic>
|
||||||
Rotation<(Vec3<N>, N)> for Rotmat<Mat3<N>>
|
Rotation<Vec3<N>> for Rotmat<Mat3<N>>
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rotation(&self) -> (Vec3<N>, N)
|
fn rotation(&self) -> Vec3<N>
|
||||||
{ fail!("Not yet implemented.") }
|
{ fail!("Not yet implemented.") }
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
||||||
fn inv_rotation(&self) -> (Vec3<N>, N)
|
fn inv_rotation(&self) -> Vec3<N>
|
||||||
{ fail!("Not yet implemented.") }
|
{ fail!("Not yet implemented.") }
|
||||||
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rotate_by(&mut self, rot: &(Vec3<N>, N))
|
fn rotate_by(&mut self, rot: &Vec3<N>)
|
||||||
{ *self = self.rotated(rot) }
|
{ *self = self.rotated(rot) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Trigonometric + DivisionRing>
|
impl<N: Copy + Trigonometric + DivisionRing + Algebraic>
|
||||||
Rotatable<(Vec3<N>, N), Rotmat<Mat3<N>>> for Rotmat<Mat3<N>>
|
Rotatable<Vec3<N>, Rotmat<Mat3<N>>> for Rotmat<Mat3<N>>
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rotated(&self, &(axis, angle): &(Vec3<N>, N)) -> Rotmat<Mat3<N>>
|
fn rotated(&self, axisangle: &Vec3<N>) -> Rotmat<Mat3<N>>
|
||||||
{ rotmat3(&axis, angle) * *self }
|
{ rotmat3(copy *axisangle) * *self }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Rand + Trigonometric + Neg<N>> Rand for Rotmat<Mat2<N>>
|
impl<N: Copy + Rand + Trigonometric + Neg<N>> Rand for Rotmat<Mat2<N>>
|
||||||
|
@ -136,12 +138,12 @@ impl<M: RMul<V> + LMul<V>, V> Transform<V> for Rotmat<M>
|
||||||
{ self.inv_rotate(v) }
|
{ self.inv_rotate(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Rand + Trigonometric + Ring>
|
impl<N: Copy + Rand + Trigonometric + DivisionRing + Algebraic>
|
||||||
Rand for Rotmat<Mat3<N>>
|
Rand for Rotmat<Mat3<N>>
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Rotmat<Mat3<N>>
|
fn rand<R: Rng>(rng: &mut R) -> Rotmat<Mat3<N>>
|
||||||
{ rotmat3(&rng.gen(), rng.gen()) }
|
{ rotmat3(rng.gen()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Dim> Dim for Rotmat<M>
|
impl<M: Dim> Dim for Rotmat<M>
|
||||||
|
|
Loading…
Reference in New Issue