Add incomplete implementation of 4D rotation.

This commit is contained in:
Sébastien Crozet 2013-11-22 09:46:48 +01:00
parent 281a17e456
commit 4addd531cf
3 changed files with 81 additions and 8 deletions

View File

@ -1,6 +1,8 @@
/*! /*!
# nalgebra # nalgebra
[![Build Status](https://travis-ci.org/sebcrozet/nalgebra.png?branch=master)](https://travis-ci.org/sebcrozet/nalgebra)
**nalgebra** is a linear algebra library written for Rust targeting: **nalgebra** is a linear algebra library written for Rust targeting:
* general-purpose linear algebra (still misses a lot of features). * general-purpose linear algebra (still misses a lot of features).
@ -106,6 +108,7 @@ Feel free to add your project to this list if you happen to use **nalgebra**!
*/ */
#[link(name = "nalgebra" #[link(name = "nalgebra"
, package_id = "nalgebra"
, vers = "0.1" , vers = "0.1"
, author = "Sébastien Crozet" , author = "Sébastien Crozet"
, uuid = "1e96070f-4778-4ec1-b080-bf69f7048216")]; , uuid = "1e96070f-4778-4ec1-b080-bf69f7048216")];

View File

@ -4,13 +4,13 @@
use std::num::{Zero, One}; use std::num::{Zero, One};
use std::rand::{Rand, Rng}; use std::rand::{Rand, Rng};
use structs::mat::{Mat3, Mat4}; use structs::mat::{Mat3, Mat4, Mat5};
use traits::structure::{Cast, Dim, Col}; use traits::structure::{Cast, Dim, Col};
use traits::operations::{Inv}; use traits::operations::{Inv};
use traits::geometry::{RotationMatrix, Rotation, Rotate, AbsoluteRotate, Transform, Transformation, use traits::geometry::{RotationMatrix, Rotation, Rotate, AbsoluteRotate, Transform, Transformation,
Translate, Translation, ToHomogeneous}; Translate, Translation, ToHomogeneous};
use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec2MulRhs, Vec3MulRhs}; use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec2MulRhs, Vec3MulRhs, Vec4MulRhs};
use structs::rot::{Rot2, Rot3, Rot4}; use structs::rot::{Rot2, Rot3, Rot4};
mod metal; mod metal;
@ -82,6 +82,18 @@ impl<N: Clone + Num + Algebraic> Iso3<N> {
} }
} }
impl<N> Iso4<N> {
// XXX remove that when iso_impl works for Iso4
/// Creates a new isometry from a rotation matrix and a vector.
#[inline]
pub fn new_with_rotmat(translation: Vec4<N>, rotation: Rot4<N>) -> Iso4<N> {
Iso4 {
rotation: rotation,
translation: translation
}
}
}
iso_impl!(Iso2, Rot2, Vec2, Vec1) iso_impl!(Iso2, Rot2, Vec2, Vec1)
double_dispatch_binop_decl_trait!(Iso2, Iso2MulRhs) double_dispatch_binop_decl_trait!(Iso2, Iso2MulRhs)
mul_redispatch_impl!(Iso2, Iso2MulRhs) mul_redispatch_impl!(Iso2, Iso2MulRhs)
@ -124,25 +136,23 @@ iso_mul_iso_impl!(Iso3, Iso3MulRhs)
iso_mul_vec_impl!(Iso3, Vec3, Iso3MulRhs) iso_mul_vec_impl!(Iso3, Vec3, Iso3MulRhs)
vec_mul_iso_impl!(Iso3, Vec3, Vec3MulRhs) vec_mul_iso_impl!(Iso3, Vec3, Vec3MulRhs)
/* // iso_impl!(Iso4, Rot4, Vec4, Vec4)
iso_impl!(Iso4, Rot4, Vec4, Vec4)
double_dispatch_binop_decl_trait!(Iso4, Iso4MulRhs) double_dispatch_binop_decl_trait!(Iso4, Iso4MulRhs)
mul_redispatch_impl!(Iso4, Iso4MulRhs) mul_redispatch_impl!(Iso4, Iso4MulRhs)
// rotation_matrix_impl!(Iso4, Rot4, Vec4, Vec4) // rotation_matrix_impl!(Iso4, Rot4, Vec4, Vec4)
// rotation_impl!(Iso4, Rot4, Vec4) // rotation_impl!(Iso4, Rot4, Vec4)
dim_impl!(Iso4, 4) dim_impl!(Iso4, 4)
one_impl!(Iso4) one_impl!(Iso4)
// absolute_rotate_impl!(Iso4, Vec4) absolute_rotate_impl!(Iso4, Vec4)
// rand_impl!(Iso4) // rand_impl!(Iso4)
approx_eq_impl!(Iso4) approx_eq_impl!(Iso4)
to_homogeneous_impl!(Iso4, Mat5) to_homogeneous_impl!(Iso4, Mat5)
inv_impl!(Iso4) inv_impl!(Iso4)
transform_impl!(Iso4, Vec4) transform_impl!(Iso4, Vec4)
transformation_impl!(Iso4) transformation_impl!(Iso4)
// rotate_impl!(Iso4, Vec4) rotate_impl!(Iso4, Vec4)
translation_impl!(Iso4, Vec4) translation_impl!(Iso4, Vec4)
translate_impl!(Iso4, Vec4) translate_impl!(Iso4, Vec4)
iso_mul_iso_impl!(Iso4, Iso4MulRhs) iso_mul_iso_impl!(Iso4, Iso4MulRhs)
iso_mul_vec_impl!(Iso4, Vec4, Iso4MulRhs) iso_mul_vec_impl!(Iso4, Vec4, Iso4MulRhs)
vec_mul_iso_impl!(Iso4, Vec4, Vec4MulRhs) vec_mul_iso_impl!(Iso4, Vec4, Vec4MulRhs)
*/

View File

@ -269,6 +269,28 @@ pub struct Rot4<N> {
priv submat: Mat4<N> priv submat: Mat4<N>
} }
// 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);
//
// 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);
//
// Rot4 {
// submat: mat_left_iso * mat_right_iso
// }
// }
// }
impl<N: Signed> AbsoluteRotate<Vec4<N>> for Rot4<N> { impl<N: Signed> AbsoluteRotate<Vec4<N>> for Rot4<N> {
#[inline] #[inline]
fn absolute_rotate(&self, v: &Vec4<N>) -> Vec4<N> { fn absolute_rotate(&self, v: &Vec4<N>) -> Vec4<N> {
@ -287,6 +309,44 @@ impl<N: Signed> AbsoluteRotate<Vec4<N>> for Rot4<N> {
} }
} }
impl<N: Trigonometric + Num + Clone>
Rotation<Vec4<N>> for Rot4<N> {
#[inline]
fn rotation(&self) -> Vec4<N> {
fail!("Not yet implemented")
}
#[inline]
fn inv_rotation(&self) -> Vec4<N> {
fail!("Not yet implemented")
}
#[inline]
fn append_rotation(&mut self, _: &Vec4<N>) {
fail!("Not yet implemented")
}
#[inline]
fn append_rotation_cpy(_: &Rot4<N>, _: &Vec4<N>) -> Rot4<N> {
fail!("Not yet implemented")
}
#[inline]
fn prepend_rotation(&mut self, _: &Vec4<N>) {
fail!("Not yet implemented")
}
#[inline]
fn prepend_rotation_cpy(_: &Rot4<N>, _: &Vec4<N>) -> Rot4<N> {
fail!("Not yet implemented")
}
#[inline]
fn set_rotation(&mut self, _: Vec4<N>) {
fail!("Not yet implemented")
}
}
/* /*
* Common implementations. * Common implementations.
@ -340,7 +400,7 @@ rot_mul_rot_impl!(Rot4, Rot4MulRhs)
rot_mul_vec_impl!(Rot4, Vec4, Rot4MulRhs) rot_mul_vec_impl!(Rot4, Vec4, Rot4MulRhs)
vec_mul_rot_impl!(Rot4, Vec4, Vec4MulRhs) vec_mul_rot_impl!(Rot4, Vec4, Vec4MulRhs)
one_impl!(Rot4) one_impl!(Rot4)
// rotation_matrix_impl!(Rot4, Vec4, Vec4) rotation_matrix_impl!(Rot4, Vec4, Vec4)
col_impl!(Rot4, Vec4) col_impl!(Rot4, Vec4)
row_impl!(Rot4, Vec4) row_impl!(Rot4, Vec4)
absolute_impl!(Rot4, Mat4) absolute_impl!(Rot4, Mat4)