2013-10-06 22:54:09 +08:00
|
|
|
|
//! Rotations matrices.
|
|
|
|
|
|
2014-11-01 00:40:47 +08:00
|
|
|
|
#![allow(missing_docs)]
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
use std::num::{Zero, One, Num};
|
2014-10-15 03:37:44 +08:00
|
|
|
|
use std::rand::{Rand, Rng};
|
2013-10-06 22:54:09 +08:00
|
|
|
|
use traits::geometry::{Rotate, Rotation, AbsoluteRotate, RotationMatrix, Transform, ToHomogeneous,
|
|
|
|
|
Norm, Cross};
|
2014-11-15 22:47:59 +08:00
|
|
|
|
use traits::structure::{Cast, Dim, Row, Col, BaseFloat};
|
2014-01-10 03:48:30 +08:00
|
|
|
|
use traits::operations::{Absolute, Inv, Transpose, ApproxEq};
|
2013-10-06 22:54:09 +08:00
|
|
|
|
use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec2MulRhs, Vec3MulRhs, Vec4MulRhs};
|
2014-10-10 17:23:52 +08:00
|
|
|
|
use structs::pnt::{Pnt2, Pnt3, Pnt4, Pnt2MulRhs, Pnt3MulRhs, Pnt4MulRhs};
|
2013-10-06 22:54:09 +08:00
|
|
|
|
use structs::mat::{Mat2, Mat3, Mat4, Mat5};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Two dimensional rotation matrix.
|
2014-06-04 04:37:46 +08:00
|
|
|
|
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Show, Hash)]
|
2013-10-06 22:54:09 +08:00
|
|
|
|
pub struct Rot2<N> {
|
2014-04-02 04:58:06 +08:00
|
|
|
|
submat: Mat2<N>
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: Clone + BaseFloat + Neg<N>> Rot2<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
|
/// Builds a 2 dimensional rotation matrix from an angle in radian.
|
2013-10-14 16:22:32 +08:00
|
|
|
|
pub fn new(angle: Vec1<N>) -> Rot2<N> {
|
|
|
|
|
let (sia, coa) = angle.x.sin_cos();
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
|
|
Rot2 {
|
|
|
|
|
submat: Mat2::new(coa.clone(), -sia, sia.clone(), coa)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: BaseFloat + Clone> Rotation<Vec1<N>> for Rot2<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn rotation(&self) -> Vec1<N> {
|
2014-04-26 02:28:05 +08:00
|
|
|
|
Vec1::new((-self.submat.m12).atan2(self.submat.m11.clone()))
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn inv_rotation(&self) -> Vec1<N> {
|
|
|
|
|
-self.rotation()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2013-10-14 16:22:32 +08:00
|
|
|
|
fn append_rotation(&mut self, rot: &Vec1<N>) {
|
|
|
|
|
*self = Rotation::append_rotation_cpy(self, rot)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2013-10-14 16:22:32 +08:00
|
|
|
|
fn append_rotation_cpy(t: &Rot2<N>, rot: &Vec1<N>) -> Rot2<N> {
|
|
|
|
|
Rot2::new(rot.clone()) * *t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn prepend_rotation(&mut self, rot: &Vec1<N>) {
|
|
|
|
|
*self = Rotation::prepend_rotation_cpy(self, rot)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn prepend_rotation_cpy(t: &Rot2<N>, rot: &Vec1<N>) -> Rot2<N> {
|
|
|
|
|
*t * Rot2::new(rot.clone())
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn set_rotation(&mut self, rot: Vec1<N>) {
|
2013-10-14 16:22:32 +08:00
|
|
|
|
*self = Rot2::new(rot)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: Clone + Rand + BaseFloat + Neg<N>> Rand for Rot2<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn rand<R: Rng>(rng: &mut R) -> Rot2<N> {
|
2013-10-14 16:22:32 +08:00
|
|
|
|
Rot2::new(rng.gen())
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: BaseFloat> AbsoluteRotate<Vec2<N>> for Rot2<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn absolute_rotate(&self, v: &Vec2<N>) -> Vec2<N> {
|
|
|
|
|
// the matrix is skew-symetric, so we dont need to compute the absolute value of every
|
|
|
|
|
// component.
|
2014-11-15 22:47:59 +08:00
|
|
|
|
let m11 = ::abs(&self.submat.m11);
|
|
|
|
|
let m12 = ::abs(&self.submat.m12);
|
|
|
|
|
let m22 = ::abs(&self.submat.m22);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
|
|
Vec2::new(m11 * v.x + m12 * v.y, m12 * v.x + m22 * v.y)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 3d rotation
|
|
|
|
|
*/
|
|
|
|
|
/// Three dimensional rotation matrix.
|
2014-06-04 04:37:46 +08:00
|
|
|
|
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Show, Hash)]
|
2013-10-06 22:54:09 +08:00
|
|
|
|
pub struct Rot3<N> {
|
2014-04-02 04:58:06 +08:00
|
|
|
|
submat: Mat3<N>
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: Clone + BaseFloat> Rot3<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
|
/// Builds a 3 dimensional rotation matrix from an axis and an angle.
|
|
|
|
|
///
|
|
|
|
|
/// # Arguments
|
|
|
|
|
/// * `axisangle` - A vector representing the rotation. Its magnitude is the amount of rotation
|
|
|
|
|
/// in radian. Its direction is the axis of rotation.
|
2013-10-14 16:22:32 +08:00
|
|
|
|
pub fn new(axisangle: Vec3<N>) -> Rot3<N> {
|
2013-10-17 03:44:33 +08:00
|
|
|
|
if Norm::sqnorm(&axisangle).is_zero() {
|
2013-10-06 22:54:09 +08:00
|
|
|
|
One::one()
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let mut axis = axisangle;
|
|
|
|
|
let angle = axis.normalize();
|
|
|
|
|
let _1: N = One::one();
|
|
|
|
|
let ux = axis.x.clone();
|
|
|
|
|
let uy = axis.y.clone();
|
|
|
|
|
let uz = axis.z.clone();
|
|
|
|
|
let sqx = ux * ux;
|
|
|
|
|
let sqy = uy * uy;
|
|
|
|
|
let sqz = uz * uz;
|
|
|
|
|
let (sin, cos) = angle.sin_cos();
|
|
|
|
|
let one_m_cos = _1 - cos;
|
|
|
|
|
|
|
|
|
|
Rot3 {
|
|
|
|
|
submat: Mat3::new(
|
|
|
|
|
(sqx + (_1 - sqx) * cos),
|
|
|
|
|
(ux * uy * one_m_cos - uz * sin),
|
|
|
|
|
(ux * uz * one_m_cos + uy * sin),
|
|
|
|
|
|
|
|
|
|
(ux * uy * one_m_cos + uz * sin),
|
|
|
|
|
(sqy + (_1 - sqy) * cos),
|
|
|
|
|
(uy * uz * one_m_cos - ux * sin),
|
|
|
|
|
|
|
|
|
|
(ux * uz * one_m_cos - uy * sin),
|
|
|
|
|
(uy * uz * one_m_cos + ux * sin),
|
|
|
|
|
(sqz + (_1 - sqz) * cos))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-15 03:37:44 +08:00
|
|
|
|
|
|
|
|
|
/// Builds a rotation matrix from an orthogonal matrix.
|
|
|
|
|
///
|
|
|
|
|
/// This is unsafe because the orthogonality of `mat` is not checked.
|
|
|
|
|
pub unsafe fn new_with_mat(mat: Mat3<N>) -> Rot3<N> {
|
|
|
|
|
Rot3 {
|
|
|
|
|
submat: mat
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Creates a new rotation from Euler angles.
|
|
|
|
|
///
|
|
|
|
|
/// The primitive rotations are applied in order: 1 roll − 2 pitch − 3 yaw.
|
|
|
|
|
pub fn new_with_euler_angles(roll: N, pitch: N, yaw: N) -> Rot3<N> {
|
|
|
|
|
let (sr, cr) = roll.sin_cos();
|
|
|
|
|
let (sp, cp) = pitch.sin_cos();
|
|
|
|
|
let (sy, cy) = yaw.sin_cos();
|
|
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
Rot3::new_with_mat(
|
|
|
|
|
Mat3::new(
|
|
|
|
|
cy * cp, cy * sp * sr - sy * cr, cy * sp * cr + sy * sr,
|
|
|
|
|
sy * cp, sy * sp * sr + cy * cr, sy * sp * cr - cy * sr,
|
|
|
|
|
-sp, cp * sr, cp * cr
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: Clone + BaseFloat> Rot3<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
|
/// 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.
|
|
|
|
|
///
|
|
|
|
|
/// # 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<N>, up: &Vec3<N>) {
|
2013-10-14 16:22:32 +08:00
|
|
|
|
let xaxis = Norm::normalize_cpy(at);
|
2013-10-17 03:44:33 +08:00
|
|
|
|
let zaxis = Norm::normalize_cpy(&Cross::cross(up, &xaxis));
|
|
|
|
|
let yaxis = Cross::cross(&zaxis, &xaxis);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
2013-10-14 16:22:32 +08:00
|
|
|
|
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)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 19:08:04 +08:00
|
|
|
|
/// Reorient this matrix such that its local `z` axis points to a given point.
|
2013-10-06 22:54:09 +08:00
|
|
|
|
///
|
|
|
|
|
/// # Arguments
|
2014-10-11 02:56:40 +08:00
|
|
|
|
/// * at - The look direction, that is, direction the matrix `y` axis will be aligned with
|
2013-10-06 22:54:09 +08:00
|
|
|
|
/// * 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<N>, up: &Vec3<N>) {
|
2013-10-14 16:22:32 +08:00
|
|
|
|
let zaxis = Norm::normalize_cpy(at);
|
2013-10-17 03:44:33 +08:00
|
|
|
|
let xaxis = Norm::normalize_cpy(&Cross::cross(up, &zaxis));
|
|
|
|
|
let yaxis = Cross::cross(&zaxis, &xaxis);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
2013-10-14 16:22:32 +08:00
|
|
|
|
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)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: Clone + BaseFloat + Cast<f64>>
|
2013-10-06 22:54:09 +08:00
|
|
|
|
Rotation<Vec3<N>> for Rot3<N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn rotation(&self) -> Vec3<N> {
|
2013-10-10 04:59:44 +08:00
|
|
|
|
let angle = ((self.submat.m11 + self.submat.m22 + self.submat.m33 - One::one()) / Cast::from(2.0)).acos();
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
|
|
if angle != angle {
|
|
|
|
|
// FIXME: handle that correctly
|
|
|
|
|
Zero::zero()
|
|
|
|
|
}
|
|
|
|
|
else if angle.is_zero() {
|
|
|
|
|
Zero::zero()
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let m32_m23 = self.submat.m32 - self.submat.m23;
|
|
|
|
|
let m13_m31 = self.submat.m13 - self.submat.m31;
|
|
|
|
|
let m21_m12 = self.submat.m21 - self.submat.m12;
|
|
|
|
|
|
|
|
|
|
let denom = (m32_m23 * m32_m23 + m13_m31 * m13_m31 + m21_m12 * m21_m12).sqrt();
|
|
|
|
|
|
|
|
|
|
if denom.is_zero() {
|
|
|
|
|
// XXX: handle that properly
|
2014-10-30 12:25:47 +08:00
|
|
|
|
// panic!("Internal error: singularity.")
|
2013-10-06 22:54:09 +08:00
|
|
|
|
Zero::zero()
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let a_d = angle / denom;
|
|
|
|
|
|
|
|
|
|
Vec3::new(m32_m23 * a_d, m13_m31 * a_d, m21_m12 * a_d)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn inv_rotation(&self) -> Vec3<N> {
|
|
|
|
|
-self.rotation()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2013-10-14 16:22:32 +08:00
|
|
|
|
fn append_rotation(&mut self, rot: &Vec3<N>) {
|
|
|
|
|
*self = Rotation::append_rotation_cpy(self, rot)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn append_rotation_cpy(t: &Rot3<N>, axisangle: &Vec3<N>) -> Rot3<N> {
|
|
|
|
|
Rot3::new(axisangle.clone()) * *t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn prepend_rotation(&mut self, rot: &Vec3<N>) {
|
|
|
|
|
*self = Rotation::prepend_rotation_cpy(self, rot)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2013-10-14 16:22:32 +08:00
|
|
|
|
fn prepend_rotation_cpy(t: &Rot3<N>, axisangle: &Vec3<N>) -> Rot3<N> {
|
|
|
|
|
*t * Rot3::new(axisangle.clone())
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn set_rotation(&mut self, axisangle: Vec3<N>) {
|
2013-10-14 16:22:32 +08:00
|
|
|
|
*self = Rot3::new(axisangle)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: Clone + Rand + BaseFloat>
|
2013-10-06 22:54:09 +08:00
|
|
|
|
Rand for Rot3<N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn rand<R: Rng>(rng: &mut R) -> Rot3<N> {
|
2013-10-14 16:22:32 +08:00
|
|
|
|
Rot3::new(rng.gen())
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: BaseFloat> AbsoluteRotate<Vec3<N>> for Rot3<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn absolute_rotate(&self, v: &Vec3<N>) -> Vec3<N> {
|
|
|
|
|
Vec3::new(
|
2014-11-15 22:47:59 +08:00
|
|
|
|
::abs(&self.submat.m11) * v.x + ::abs(&self.submat.m12) * v.y + ::abs(&self.submat.m13) * v.z,
|
|
|
|
|
::abs(&self.submat.m21) * v.x + ::abs(&self.submat.m22) * v.y + ::abs(&self.submat.m23) * v.z,
|
|
|
|
|
::abs(&self.submat.m31) * v.x + ::abs(&self.submat.m32) * v.y + ::abs(&self.submat.m33) * v.z)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Four dimensional rotation matrix.
|
2014-06-04 04:37:46 +08:00
|
|
|
|
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Show, Hash)]
|
2013-10-06 22:54:09 +08:00
|
|
|
|
pub struct Rot4<N> {
|
2014-04-02 04:58:06 +08:00
|
|
|
|
submat: Mat4<N>
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-22 16:46:48 +08:00
|
|
|
|
// impl<N> Rot4<N> {
|
|
|
|
|
// pub fn new(left_iso: Quat<N>, right_iso: Quat<N>) -> Rot4<N> {
|
|
|
|
|
// assert!(left_iso.is_unit());
|
|
|
|
|
// assert!(right_iso.is_unright);
|
2014-05-21 19:08:04 +08:00
|
|
|
|
//
|
2013-11-22 16:46:48 +08:00
|
|
|
|
// let mat_left_iso = Mat4::new(
|
|
|
|
|
// left_iso.x, -left_iso.y, -left_iso.z, -left_iso.w,
|
|
|
|
|
// left_iso.y, left_iso.x, -left_iso.w, left_iso.z,
|
|
|
|
|
// left_iso.z, left_iso.w, left_iso.x, -left_iso.y,
|
|
|
|
|
// left_iso.w, -left_iso.z, left_iso.y, left_iso.x);
|
|
|
|
|
// let mat_right_iso = Mat4::new(
|
|
|
|
|
// right_iso.x, -right_iso.y, -right_iso.z, -right_iso.w,
|
|
|
|
|
// right_iso.y, right_iso.x, right_iso.w, -right_iso.z,
|
|
|
|
|
// right_iso.z, -right_iso.w, right_iso.x, right_iso.y,
|
|
|
|
|
// right_iso.w, right_iso.z, -right_iso.y, right_iso.x);
|
2014-05-21 19:08:04 +08:00
|
|
|
|
//
|
2013-11-22 16:46:48 +08:00
|
|
|
|
// Rot4 {
|
|
|
|
|
// submat: mat_left_iso * mat_right_iso
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: BaseFloat> AbsoluteRotate<Vec4<N>> for Rot4<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn absolute_rotate(&self, v: &Vec4<N>) -> Vec4<N> {
|
|
|
|
|
Vec4::new(
|
2014-11-15 22:47:59 +08:00
|
|
|
|
::abs(&self.submat.m11) * v.x + ::abs(&self.submat.m12) * v.y +
|
|
|
|
|
::abs(&self.submat.m13) * v.z + ::abs(&self.submat.m14) * v.w,
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
::abs(&self.submat.m21) * v.x + ::abs(&self.submat.m22) * v.y +
|
|
|
|
|
::abs(&self.submat.m23) * v.z + ::abs(&self.submat.m24) * v.w,
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
::abs(&self.submat.m31) * v.x + ::abs(&self.submat.m32) * v.y +
|
|
|
|
|
::abs(&self.submat.m33) * v.z + ::abs(&self.submat.m34) * v.w,
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
::abs(&self.submat.m41) * v.x + ::abs(&self.submat.m42) * v.y +
|
|
|
|
|
::abs(&self.submat.m43) * v.z + ::abs(&self.submat.m44) * v.w)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 22:47:59 +08:00
|
|
|
|
impl<N: BaseFloat + Clone>
|
2013-11-22 16:46:48 +08:00
|
|
|
|
Rotation<Vec4<N>> for Rot4<N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn rotation(&self) -> Vec4<N> {
|
2014-10-30 12:25:47 +08:00
|
|
|
|
panic!("Not yet implemented")
|
2013-11-22 16:46:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn inv_rotation(&self) -> Vec4<N> {
|
2014-10-30 12:25:47 +08:00
|
|
|
|
panic!("Not yet implemented")
|
2013-11-22 16:46:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn append_rotation(&mut self, _: &Vec4<N>) {
|
2014-10-30 12:25:47 +08:00
|
|
|
|
panic!("Not yet implemented")
|
2013-11-22 16:46:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn append_rotation_cpy(_: &Rot4<N>, _: &Vec4<N>) -> Rot4<N> {
|
2014-10-30 12:25:47 +08:00
|
|
|
|
panic!("Not yet implemented")
|
2013-11-22 16:46:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn prepend_rotation(&mut self, _: &Vec4<N>) {
|
2014-10-30 12:25:47 +08:00
|
|
|
|
panic!("Not yet implemented")
|
2013-11-22 16:46:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn prepend_rotation_cpy(_: &Rot4<N>, _: &Vec4<N>) -> Rot4<N> {
|
2014-10-30 12:25:47 +08:00
|
|
|
|
panic!("Not yet implemented")
|
2013-11-22 16:46:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn set_rotation(&mut self, _: Vec4<N>) {
|
2014-10-30 12:25:47 +08:00
|
|
|
|
panic!("Not yet implemented")
|
2013-11-22 16:46:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Common implementations.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
double_dispatch_binop_decl_trait!(Rot2, Rot2MulRhs)
|
|
|
|
|
mul_redispatch_impl!(Rot2, Rot2MulRhs)
|
|
|
|
|
submat_impl!(Rot2, Mat2)
|
2014-10-10 17:23:52 +08:00
|
|
|
|
rotate_impl!(Rot2RotateRhs, Rot2, Vec2, Pnt2)
|
|
|
|
|
transform_impl!(Rot2TransformRhs, Rot2, Vec2, Pnt2)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
dim_impl!(Rot2, 2)
|
|
|
|
|
rot_mul_rot_impl!(Rot2, Rot2MulRhs)
|
|
|
|
|
rot_mul_vec_impl!(Rot2, Vec2, Rot2MulRhs)
|
|
|
|
|
vec_mul_rot_impl!(Rot2, Vec2, Vec2MulRhs)
|
2014-10-10 17:23:52 +08:00
|
|
|
|
rot_mul_pnt_impl!(Rot2, Pnt2, Rot2MulRhs)
|
|
|
|
|
pnt_mul_rot_impl!(Rot2, Pnt2, Pnt2MulRhs)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
one_impl!(Rot2)
|
|
|
|
|
rotation_matrix_impl!(Rot2, Vec2, Vec1)
|
|
|
|
|
col_impl!(Rot2, Vec2)
|
|
|
|
|
row_impl!(Rot2, Vec2)
|
2014-10-26 05:02:16 +08:00
|
|
|
|
index_impl!(Rot2)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
absolute_impl!(Rot2, Mat2)
|
|
|
|
|
to_homogeneous_impl!(Rot2, Mat3)
|
|
|
|
|
inv_impl!(Rot2)
|
|
|
|
|
transpose_impl!(Rot2)
|
|
|
|
|
approx_eq_impl!(Rot2)
|
|
|
|
|
|
|
|
|
|
double_dispatch_binop_decl_trait!(Rot3, Rot3MulRhs)
|
|
|
|
|
mul_redispatch_impl!(Rot3, Rot3MulRhs)
|
|
|
|
|
submat_impl!(Rot3, Mat3)
|
2014-10-10 17:23:52 +08:00
|
|
|
|
rotate_impl!(Rot3RotateRhs, Rot3, Vec3, Pnt3)
|
|
|
|
|
transform_impl!(Rot3TransformRhs, Rot3, Vec3, Pnt3)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
dim_impl!(Rot3, 3)
|
|
|
|
|
rot_mul_rot_impl!(Rot3, Rot3MulRhs)
|
|
|
|
|
rot_mul_vec_impl!(Rot3, Vec3, Rot3MulRhs)
|
|
|
|
|
vec_mul_rot_impl!(Rot3, Vec3, Vec3MulRhs)
|
2014-10-10 17:23:52 +08:00
|
|
|
|
rot_mul_pnt_impl!(Rot3, Pnt3, Rot3MulRhs)
|
|
|
|
|
pnt_mul_rot_impl!(Rot3, Pnt3, Pnt3MulRhs)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
one_impl!(Rot3)
|
|
|
|
|
rotation_matrix_impl!(Rot3, Vec3, Vec3)
|
|
|
|
|
col_impl!(Rot3, Vec3)
|
|
|
|
|
row_impl!(Rot3, Vec3)
|
2014-10-26 05:02:16 +08:00
|
|
|
|
index_impl!(Rot3)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
absolute_impl!(Rot3, Mat3)
|
|
|
|
|
to_homogeneous_impl!(Rot3, Mat4)
|
|
|
|
|
inv_impl!(Rot3)
|
|
|
|
|
transpose_impl!(Rot3)
|
|
|
|
|
approx_eq_impl!(Rot3)
|
|
|
|
|
|
|
|
|
|
double_dispatch_binop_decl_trait!(Rot4, Rot4MulRhs)
|
|
|
|
|
mul_redispatch_impl!(Rot4, Rot4MulRhs)
|
|
|
|
|
submat_impl!(Rot4, Mat4)
|
2014-10-10 17:23:52 +08:00
|
|
|
|
rotate_impl!(Rot4RotateRhs, Rot4, Vec4, Pnt4)
|
|
|
|
|
transform_impl!(Rot4TransformRhs, Rot4, Vec4, Pnt4)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
dim_impl!(Rot4, 4)
|
|
|
|
|
rot_mul_rot_impl!(Rot4, Rot4MulRhs)
|
|
|
|
|
rot_mul_vec_impl!(Rot4, Vec4, Rot4MulRhs)
|
|
|
|
|
vec_mul_rot_impl!(Rot4, Vec4, Vec4MulRhs)
|
2014-10-10 17:23:52 +08:00
|
|
|
|
rot_mul_pnt_impl!(Rot4, Pnt4, Rot4MulRhs)
|
|
|
|
|
pnt_mul_rot_impl!(Rot4, Pnt4, Pnt4MulRhs)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
one_impl!(Rot4)
|
2013-11-22 16:46:48 +08:00
|
|
|
|
rotation_matrix_impl!(Rot4, Vec4, Vec4)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
col_impl!(Rot4, Vec4)
|
|
|
|
|
row_impl!(Rot4, Vec4)
|
2014-10-26 05:02:16 +08:00
|
|
|
|
index_impl!(Rot4)
|
2013-10-06 22:54:09 +08:00
|
|
|
|
absolute_impl!(Rot4, Mat4)
|
|
|
|
|
to_homogeneous_impl!(Rot4, Mat5)
|
|
|
|
|
inv_impl!(Rot4)
|
|
|
|
|
transpose_impl!(Rot4)
|
|
|
|
|
approx_eq_impl!(Rot4)
|