commit
1382c2ea4b
1 changed files with 26 additions and 58 deletions
|
@ -15,15 +15,12 @@
|
||||||
|
|
||||||
use std::{fmt, num};
|
use std::{fmt, num};
|
||||||
|
|
||||||
use std::num::one;
|
|
||||||
|
|
||||||
use approx::ApproxEq;
|
use approx::ApproxEq;
|
||||||
use matrix::{Matrix, Matrix4, ToMatrix4};
|
use matrix::{Matrix, Matrix4, ToMatrix4};
|
||||||
use num::{BaseNum, BaseFloat};
|
use num::{BaseNum, BaseFloat};
|
||||||
use point::{Point, Point3};
|
use point::{Point, Point3};
|
||||||
use ray::Ray;
|
use ray::Ray;
|
||||||
use rotation::{Rotation, Rotation3};
|
use rotation::{Rotation, Rotation3};
|
||||||
use quaternion::Quaternion;
|
|
||||||
use vector::{Vector, Vector3};
|
use vector::{Vector, Vector3};
|
||||||
|
|
||||||
/// A trait representing an [affine
|
/// A trait representing an [affine
|
||||||
|
@ -129,8 +126,7 @@ impl<S: BaseFloat, V: Vector<S>, P: Point<S, V>, R: Rotation<S, V, P>> Transform
|
||||||
if self.scale.approx_eq(&num::zero()) {
|
if self.scale.approx_eq(&num::zero()) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let _1 : S = num::one();
|
let s = num::one::<S>() / self.scale;
|
||||||
let s = _1 / self.scale;
|
|
||||||
let r = self.rot.invert();
|
let r = self.rot.invert();
|
||||||
let d = r.rotate_vector(&self.disp).mul_s(-s);
|
let d = r.rotate_vector(&self.disp).mul_s(-s);
|
||||||
Some(Decomposed {
|
Some(Decomposed {
|
||||||
|
@ -161,7 +157,6 @@ impl<S: BaseFloat, R: fmt::Show + Rotation3<S>> fmt::Show for Decomposed<S,Vecto
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// A homogeneous transformation matrix.
|
/// A homogeneous transformation matrix.
|
||||||
pub struct AffineMatrix3<S> {
|
pub struct AffineMatrix3<S> {
|
||||||
pub mat: Matrix4<S>,
|
pub mat: Matrix4<S>,
|
||||||
|
@ -204,30 +199,3 @@ impl<S: BaseNum> ToMatrix4<S> for AffineMatrix3<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> Transform3<S> for AffineMatrix3<S> {}
|
impl<S: BaseFloat> Transform3<S> for AffineMatrix3<S> {}
|
||||||
|
|
||||||
|
|
||||||
/// A transformation in three dimensions consisting of a rotation,
|
|
||||||
/// displacement vector and scale amount.
|
|
||||||
pub struct Transform3D<S>(Decomposed<S,Vector3<S>,Quaternion<S>>);
|
|
||||||
|
|
||||||
impl<S: BaseFloat> Transform3D<S> {
|
|
||||||
#[inline]
|
|
||||||
pub fn new(scale: S, rot: Quaternion<S>, disp: Vector3<S>) -> Transform3D<S> {
|
|
||||||
Transform3D( Decomposed { scale: scale, rot: rot, disp: disp })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn translate(x: S, y: S, z: S) -> Transform3D<S> {
|
|
||||||
Transform3D( Decomposed { scale: one(), rot: Quaternion::zero(), disp: Vector3::new(x, y, z) })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get<'a>(&'a self) -> &'a Decomposed<S,Vector3<S>,Quaternion<S>> {
|
|
||||||
let &Transform3D(ref d) = self;
|
|
||||||
d
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S: BaseFloat> ToMatrix4<S> for Transform3D<S> {
|
|
||||||
fn to_matrix4(&self) -> Matrix4<S> { self.get().to_matrix4() }
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue