diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index 53a4c3d7..e6be72ec 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -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> RotmatMulRhs> for Rotmat { /* * Right/Left multiplication implementation for Vec3 and Vec2. */ +impl, Vec4>, N> RotmatMulRhs> for Vec4 { + #[inline] + fn binop(left: &Rotmat, right: &Vec4) -> Vec4 { + left.submat * *right + } +} + impl, Vec3>, N> RotmatMulRhs> for Vec3 { #[inline] fn binop(left: &Rotmat, right: &Vec3) -> Vec3 { @@ -307,6 +314,13 @@ impl, Vec2>, N> RotmatMulRhs> for Vec2 { } } +impl>> Vec4MulRhs> for Rotmat { + #[inline] + fn binop(left: &Vec4, right: &Rotmat) -> Vec4 { + *left * right.submat + } +} + impl>> Vec3MulRhs> for Rotmat { #[inline] fn binop(left: &Vec3, right: &Rotmat) -> Vec3 { @@ -414,6 +428,32 @@ impl, M2> Absolute for Rotmat { } } +impl AbsoluteRotate> for Rotmat> { + #[inline] + fn absolute_rotate(&self, v: &Vec4) -> Vec4 { + 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 AbsoluteRotate> for Rotmat> { #[inline] fn absolute_rotate(&self, v: &Vec3) -> Vec3 { diff --git a/src/spec/vec.rs b/src/spec/vec.rs index 660b0631..a8575fa5 100644 --- a/src/spec/vec.rs +++ b/src/spec/vec.rs @@ -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 + Sub> Cross> for Vec2 { @@ -207,3 +207,13 @@ impl UniformSphereSample for Vec3 { } } } + +impl UniformSphereSample for Vec4 { + #[inline(always)] + fn sample(_: &fn(Vec4)) { + fail!("UniformSphereSample::>::sample : Not yet implemented.") + // for sample in SAMPLES_3_F64.iter() { + // f(VecCast::from(*sample)) + // } + } +} diff --git a/src/traits/structure.rs b/src/traits/structure.rs index a931556d..89a61611 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -24,7 +24,6 @@ pub trait MatCast { // 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: Dim + Sub + Add + Neg + Zero + Eq + Mul + Div + Dot { diff --git a/src/types.rs b/src/types.rs index 80aa50c1..3d9cdc8f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -94,15 +94,15 @@ pub type Mat4f64 = Mat4; /// 4-dimensional `f32`-valued matrix. pub type Mat4f32 = Mat4; -// /// 4-dimensional `f64`-valued rotation matrix. -// pub type Rot4f64 = Rotmat>; -// /// 4-dimensional `f32`-valued rotation matrix. -// pub type Rot4f32 = Rotmat>; -// -// /// 4-dimensional `f64`-valued isometric transform. -// pub type Iso4f64 = Transform; -// /// 4-dimensional `f32`-valued isometric transform. -// pub type Iso4f32 = Transform; +/// 4-dimensional `f64`-valued rotation matrix. +pub type Rot4f64 = Rotmat>; +/// 4-dimensional `f32`-valued rotation matrix. +pub type Rot4f32 = Rotmat>; + +/// 4-dimensional `f64`-valued isometric transform. +pub type Iso4f64 = Transform; +/// 4-dimensional `f32`-valued isometric transform. +pub type Iso4f32 = Transform; /// 4-dimensional `f64`-valued general transform. pub type Aff4f64 = Transform;