Transform::concat implemented
This commit is contained in:
parent
b12af38746
commit
7f39520aa1
3 changed files with 29 additions and 14 deletions
|
@ -44,18 +44,6 @@ pub trait Array
|
||||||
fn each_mut(&mut self, f: &fn(i: uint, x: &mut T));
|
fn each_mut(&mut self, f: &fn(i: uint, x: &mut T));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*impl //TODO
|
|
||||||
<
|
|
||||||
T: Clone,
|
|
||||||
Slice,
|
|
||||||
A: Array<T,Slice>
|
|
||||||
>
|
|
||||||
Clone for A {
|
|
||||||
fn clone(&self) -> A {
|
|
||||||
self.build(|i| self.i(i).clone())
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
macro_rules! array(
|
macro_rules! array(
|
||||||
(impl<$S:ident> $Self:ty -> [$T:ty, ..$n:expr] $_n:ident) => (
|
(impl<$S:ident> $Self:ty -> [$T:ty, ..$n:expr] $_n:ident) => (
|
||||||
impl<$S: Clone> Array<$T, [$T,..$n]> for $Self {
|
impl<$S: Clone> Array<$T, [$T,..$n]> for $Self {
|
||||||
|
|
|
@ -61,6 +61,7 @@ impl<S: Clone + Num + Primitive> Point3<S> {
|
||||||
let e = v.truncate().mul_s( _1 / v.w );
|
let e = v.truncate().mul_s( _1 / v.w );
|
||||||
Point3::new(e.x.clone(), e.y.clone(), e.z.clone()) //FIXME
|
Point3::new(e.x.clone(), e.y.clone(), e.z.clone()) //FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_homogeneous(&self) -> Vec4<S> {
|
pub fn to_homogeneous(&self) -> Vec4<S> {
|
||||||
Vec4::new(self.x.clone(), self.y.clone(), self.z.clone(), one())
|
Vec4::new(self.x.clone(), self.y.clone(), self.z.clone(), one())
|
||||||
|
@ -76,6 +77,9 @@ pub trait Point
|
||||||
>
|
>
|
||||||
: Array<S, Slice>
|
: Array<S, Slice>
|
||||||
{
|
{
|
||||||
|
#[inline] fn from_vec(v: &V) -> Self { build(|i| v.i(i).clone()) }
|
||||||
|
#[inline] fn to_vec(&self) -> V { build(|i| self.i(i).clone()) }
|
||||||
|
|
||||||
#[inline] fn mul_s(&self, s: S) -> Self { build(|i| self.i(i).mul(&s)) }
|
#[inline] fn mul_s(&self, s: S) -> Self { build(|i| self.i(i).mul(&s)) }
|
||||||
#[inline] fn div_s(&self, s: S) -> Self { build(|i| self.i(i).div(&s)) }
|
#[inline] fn div_s(&self, s: S) -> Self { build(|i| self.i(i).div(&s)) }
|
||||||
#[inline] fn rem_s(&self, s: S) -> Self { build(|i| self.i(i).rem(&s)) }
|
#[inline] fn rem_s(&self, s: S) -> Self { build(|i| self.i(i).rem(&s)) }
|
||||||
|
|
|
@ -32,15 +32,23 @@ pub trait Transform
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
fn identity() -> Self;
|
fn identity() -> Self;
|
||||||
|
|
||||||
fn transform_vec(&self, vec: &V) -> V;
|
fn transform_vec(&self, vec: &V) -> V;
|
||||||
fn transform_point(&self, point: &P) -> P;
|
fn transform_point(&self, point: &P) -> P;
|
||||||
fn invert(&self) -> Option<Self>;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transform_ray(&self, ray: &Ray<P,V>) -> Ray<P,V> {
|
fn transform_ray(&self, ray: &Ray<P,V>) -> Ray<P,V> {
|
||||||
Ray::new( self.transform_point(&ray.origin), self.transform_vec(&ray.direction) )
|
Ray::new( self.transform_point(&ray.origin), self.transform_vec(&ray.direction) )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn concat(&self, other: &Self) -> Self;
|
||||||
|
fn invert(&self) -> Option<Self>;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn concat_self(&mut self, other: &Self) {
|
||||||
|
*self = self.concat(other);
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn invert_self(&mut self)-> bool {
|
fn invert_self(&mut self)-> bool {
|
||||||
match self.invert() {
|
match self.invert() {
|
||||||
|
@ -86,7 +94,15 @@ Transform<S, Slice, V, P> for Decomposed<S,V,R> {
|
||||||
self.rot.rotate_point( &point.mul_s( self.scale.clone() )).add_v( &self.disp )
|
self.rot.rotate_point( &point.mul_s( self.scale.clone() )).add_v( &self.disp )
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
fn concat(&self, other: &Decomposed<S,V,R>) -> Decomposed<S,V,R> {
|
||||||
|
let p = Point::from_vec( &other.disp );
|
||||||
|
Decomposed {
|
||||||
|
scale: self.scale * other.scale,
|
||||||
|
rot: self.rot.concat( &other.rot ),
|
||||||
|
disp: self.transform_point( &p ).to_vec(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn invert(&self) -> Option<Decomposed<S,V,R>> {
|
fn invert(&self) -> Option<Decomposed<S,V,R>> {
|
||||||
if self.scale.approx_eq( &num::zero() ) {
|
if self.scale.approx_eq( &num::zero() ) {
|
||||||
None
|
None
|
||||||
|
@ -143,6 +159,11 @@ Transform<S, [S, ..3], Vec3<S>, Point3<S>> for AffineMatrix3<S> {
|
||||||
Point3::from_homogeneous( &self.mat.mul_v( &point.to_homogeneous() ))
|
Point3::from_homogeneous( &self.mat.mul_v( &point.to_homogeneous() ))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn concat(&self, other: &AffineMatrix3<S>) -> AffineMatrix3<S> {
|
||||||
|
AffineMatrix3 { mat: self.mat.mul_m( &other.mat ) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn invert(&self) -> Option<AffineMatrix3<S>> {
|
fn invert(&self) -> Option<AffineMatrix3<S>> {
|
||||||
self.mat.invert().map(|m| AffineMatrix3{ mat: m })
|
self.mat.invert().map(|m| AffineMatrix3{ mat: m })
|
||||||
|
@ -154,6 +175,8 @@ ToMat4<S> for AffineMatrix3<S> {
|
||||||
#[inline] fn to_mat4(&self) -> Mat4<S> { self.mat.clone() }
|
#[inline] fn to_mat4(&self) -> Mat4<S> { self.mat.clone() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S: Float>
|
||||||
|
Transform3<S> for AffineMatrix3<S> {}
|
||||||
|
|
||||||
|
|
||||||
/// A transformation in three dimensions consisting of a rotation,
|
/// A transformation in three dimensions consisting of a rotation,
|
||||||
|
|
Loading…
Reference in a new issue