forked from M-Labs/nalgebra
Add some impls for 4d rotations.
It is not possible to create a 4d rotation yet.
This commit is contained in:
parent
820790bfa9
commit
2356723e90
@ -5,8 +5,8 @@ use traits::geometry::{Cross, Rotation, Rotate, RotationMatrix, AbsoluteRotate,
|
||||
ToHomogeneous, Norm};
|
||||
use traits::structure::{Dim, Row, Col, Indexable};
|
||||
use traits::operations::{Inv, Transpose, Absolute};
|
||||
use vec::{Vec1, Vec2, Vec3, Vec2MulRhs, Vec3MulRhs};
|
||||
use mat::{Mat2, Mat3};
|
||||
use vec::{Vec1, Vec2, Vec3, Vec4, Vec2MulRhs, Vec3MulRhs, Vec4MulRhs};
|
||||
use mat::{Mat2, Mat3, Mat4};
|
||||
|
||||
#[path = "../metal.rs"]
|
||||
mod metal;
|
||||
@ -293,6 +293,13 @@ impl<M: Mul<M, M>> RotmatMulRhs<M, Rotmat<M>> for Rotmat<M> {
|
||||
/*
|
||||
* Right/Left multiplication implementation for Vec3 and Vec2.
|
||||
*/
|
||||
impl<M: Mul<Vec4<N>, Vec4<N>>, N> RotmatMulRhs<M, Vec4<N>> for Vec4<N> {
|
||||
#[inline]
|
||||
fn binop(left: &Rotmat<M>, right: &Vec4<N>) -> Vec4<N> {
|
||||
left.submat * *right
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Mul<Vec3<N>, Vec3<N>>, N> RotmatMulRhs<M, Vec3<N>> for Vec3<N> {
|
||||
#[inline]
|
||||
fn binop(left: &Rotmat<M>, right: &Vec3<N>) -> Vec3<N> {
|
||||
@ -307,6 +314,13 @@ impl<M: Mul<Vec2<N>, Vec2<N>>, N> RotmatMulRhs<M, Vec2<N>> for Vec2<N> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N, M: Vec4MulRhs<N, Vec4<N>>> Vec4MulRhs<N, Vec4<N>> for Rotmat<M> {
|
||||
#[inline]
|
||||
fn binop(left: &Vec4<N>, right: &Rotmat<M>) -> Vec4<N> {
|
||||
*left * right.submat
|
||||
}
|
||||
}
|
||||
|
||||
impl<N, M: Vec3MulRhs<N, Vec3<N>>> Vec3MulRhs<N, Vec3<N>> for Rotmat<M> {
|
||||
#[inline]
|
||||
fn binop(left: &Vec3<N>, right: &Rotmat<M>) -> Vec3<N> {
|
||||
@ -414,6 +428,32 @@ impl<M: Absolute<M2>, M2> Absolute<M2> for Rotmat<M> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Signed> AbsoluteRotate<Vec4<N>> for Rotmat<Mat4<N>> {
|
||||
#[inline]
|
||||
fn absolute_rotate(&self, v: &Vec4<N>) -> Vec4<N> {
|
||||
Vec4::new(
|
||||
self.submat.m11.abs() * v.x +
|
||||
self.submat.m12.abs() * v.y +
|
||||
self.submat.m13.abs() * v.z +
|
||||
self.submat.m14.abs() * v.w,
|
||||
|
||||
self.submat.m21.abs() * v.x +
|
||||
self.submat.m22.abs() * v.y +
|
||||
self.submat.m23.abs() * v.z +
|
||||
self.submat.m24.abs() * v.w,
|
||||
|
||||
self.submat.m31.abs() * v.x +
|
||||
self.submat.m32.abs() * v.y +
|
||||
self.submat.m33.abs() * v.z +
|
||||
self.submat.m34.abs() * v.w,
|
||||
|
||||
self.submat.m41.abs() * v.x +
|
||||
self.submat.m42.abs() * v.y +
|
||||
self.submat.m43.abs() * v.z +
|
||||
self.submat.m44.abs() * v.w)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Signed> AbsoluteRotate<Vec3<N>> for Rotmat<Mat3<N>> {
|
||||
#[inline]
|
||||
fn absolute_rotate(&self, v: &Vec3<N>) -> Vec3<N> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::num::{Zero, One};
|
||||
use vec::{Vec1, Vec2, Vec3, Norm, VecCast, UniformSphereSample, Cross, CrossMatrix, Basis};
|
||||
use vec::{Vec1, Vec2, Vec3, Vec4, Norm, VecCast, UniformSphereSample, Cross, CrossMatrix, Basis};
|
||||
use mat::{Mat3, Row};
|
||||
|
||||
impl<N: Mul<N, N> + Sub<N, N>> Cross<Vec1<N>> for Vec2<N> {
|
||||
@ -207,3 +207,13 @@ impl<N: NumCast + Clone> UniformSphereSample for Vec3<N> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: NumCast + Clone> UniformSphereSample for Vec4<N> {
|
||||
#[inline(always)]
|
||||
fn sample(_: &fn(Vec4<N>)) {
|
||||
fail!("UniformSphereSample::<Vec4<N>>::sample : Not yet implemented.")
|
||||
// for sample in SAMPLES_3_F64.iter() {
|
||||
// f(VecCast::from(*sample))
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ pub trait MatCast<M> {
|
||||
// XXX: we keep ScalarAdd and ScalarSub here to avoid trait impl conflict (overriding) between the
|
||||
// different Add/Sub traits. This is _so_ unfortunate…
|
||||
|
||||
// NOTE: cant call that `Vector` because it conflicts with std::Vector
|
||||
/// Trait grouping most common operations on vectors.
|
||||
pub trait Vec<N>: Dim + Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Zero + Eq + Mul<N, Self>
|
||||
+ Div<N, Self> + Dot<N> {
|
||||
|
18
src/types.rs
18
src/types.rs
@ -94,15 +94,15 @@ pub type Mat4f64 = Mat4<f64>;
|
||||
/// 4-dimensional `f32`-valued matrix.
|
||||
pub type Mat4f32 = Mat4<f32>;
|
||||
|
||||
// /// 4-dimensional `f64`-valued rotation matrix.
|
||||
// pub type Rot4f64 = Rotmat<Mat4<f64>>;
|
||||
// /// 4-dimensional `f32`-valued rotation matrix.
|
||||
// pub type Rot4f32 = Rotmat<Mat4<f32>>;
|
||||
//
|
||||
// /// 4-dimensional `f64`-valued isometric transform.
|
||||
// pub type Iso4f64 = Transform<Rot4f64, Vec4f64>;
|
||||
// /// 4-dimensional `f32`-valued isometric transform.
|
||||
// pub type Iso4f32 = Transform<Rot4f32, Vec4f32>;
|
||||
/// 4-dimensional `f64`-valued rotation matrix.
|
||||
pub type Rot4f64 = Rotmat<Mat4<f64>>;
|
||||
/// 4-dimensional `f32`-valued rotation matrix.
|
||||
pub type Rot4f32 = Rotmat<Mat4<f32>>;
|
||||
|
||||
/// 4-dimensional `f64`-valued isometric transform.
|
||||
pub type Iso4f64 = Transform<Vec4f64, Mat4f64>;
|
||||
/// 4-dimensional `f32`-valued isometric transform.
|
||||
pub type Iso4f32 = Transform<Vec4f32, Mat4f32>;
|
||||
|
||||
/// 4-dimensional `f64`-valued general transform.
|
||||
pub type Aff4f64 = Transform<Vec4f64, Mat4f64>;
|
||||
|
Loading…
Reference in New Issue
Block a user