Add implementation of `RotationMatrix` for `UnitQuat`.

This commit is contained in:
Sébastien Crozet 2015-11-15 21:38:23 +01:00
parent 6db6db19fc
commit 948341685e
1 changed files with 12 additions and 3 deletions

View File

@ -12,7 +12,7 @@ use structs::{Vec3, Pnt3, Rot3, Mat3};
use traits::operations::{ApproxEq, Inv, POrd, POrdering, Axpy}; use traits::operations::{ApproxEq, Inv, POrd, POrdering, Axpy};
use traits::structure::{Cast, Indexable, Iterable, IterableMut, Dim, Shape, BaseFloat, BaseNum, use traits::structure::{Cast, Indexable, Iterable, IterableMut, Dim, Shape, BaseFloat, BaseNum,
Bounded, Repeat}; Bounded, Repeat};
use traits::geometry::{Norm, Rotation, Rotate, RotationTo, Transform}; use traits::geometry::{Norm, Rotation, RotationMatrix, Rotate, RotationTo, Transform};
#[cfg(feature="arbitrary")] #[cfg(feature="arbitrary")]
use quickcheck::{Arbitrary, Gen}; use quickcheck::{Arbitrary, Gen};
@ -156,6 +156,8 @@ impl<N: ApproxEq<N> + BaseFloat> Div<Quat<N>> for Quat<N> {
} }
} }
rand_impl!(Quat, w, i, j, k);
/// A unit quaternion that can represent a 3D rotation. /// A unit quaternion that can represent a 3D rotation.
#[repr(C)] #[repr(C)]
@ -246,8 +248,6 @@ impl<N: BaseFloat> UnitQuat<N> {
} }
} }
rand_impl!(Quat, w, i, j, k);
impl<N> UnitQuat<N> { impl<N> UnitQuat<N> {
/// Creates a new unit quaternion from a quaternion. /// Creates a new unit quaternion from a quaternion.
@ -432,6 +432,15 @@ impl<N: BaseFloat> Rotation<Vec3<N>> for UnitQuat<N> {
} }
} }
impl<N: BaseFloat> RotationMatrix<N, Vec3<N>, Vec3<N>> for UnitQuat<N> {
type Output = Rot3<N>;
#[inline]
fn to_rot_mat(&self) -> Rot3<N> {
self.to_rot()
}
}
impl<N: BaseNum + Neg<Output = N>> Rotate<Vec3<N>> for UnitQuat<N> { impl<N: BaseNum + Neg<Output = N>> Rotate<Vec3<N>> for UnitQuat<N> {
#[inline] #[inline]
fn rotate(&self, v: &Vec3<N>) -> Vec3<N> { fn rotate(&self, v: &Vec3<N>) -> Vec3<N> {