Add methods to set the translation/rotation/transformation directly.
This commit is contained in:
parent
a0b232be0a
commit
2ccd62d558
|
@ -141,6 +141,11 @@ Rotation<Vec1<N>> for Rotmat<Mat2<N>> {
|
|||
fn rotated(&self, rot: &Vec1<N>) -> Rotmat<Mat2<N>> {
|
||||
Rotmat::from_angle(rot.x.clone()) * *self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_rotation(&mut self, rot: Vec1<N>) {
|
||||
*self = Rotmat::from_angle(rot.x)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Clone + Trigonometric + Num + Algebraic>
|
||||
|
@ -165,6 +170,11 @@ Rotation<Vec3<N>> for Rotmat<Mat3<N>> {
|
|||
fn rotated(&self, axisangle: &Vec3<N>) -> Rotmat<Mat3<N>> {
|
||||
Rotmat::from_axis_angle(axisangle.clone()) * *self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_rotation(&mut self, axisangle: Vec3<N>) {
|
||||
*self = Rotmat::from_axis_angle(axisangle)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Clone + Rand + Trigonometric + Neg<N>> Rand for Rotmat<Mat2<N>> {
|
||||
|
|
|
@ -27,6 +27,7 @@ pub struct Transform<M, V> {
|
|||
priv subtrans : V
|
||||
}
|
||||
|
||||
// FIXME: this should be Trasform<V, M>
|
||||
impl<M, V> Transform<M, V> {
|
||||
/// Builds a new transform from a matrix and a vector.
|
||||
#[inline]
|
||||
|
@ -158,6 +159,11 @@ impl<M: Clone, V: Translation<V>> Translation<V> for Transform<M, V> {
|
|||
fn translated(&self, t: &V) -> Transform<M, V> {
|
||||
Transform::new(self.submat.clone(), self.subtrans.translated(t))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_translation(&mut self, t: V) {
|
||||
self.subtrans.set_translation(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Translate<V>, V, _0> Translate<V> for Transform<M, _0> {
|
||||
|
@ -202,6 +208,12 @@ Rotation<AV> for Transform<M, V> {
|
|||
|
||||
Transform::new(self.submat.rotated(rot), delta.rmul(&self.subtrans))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_rotation(&mut self, rot: AV) {
|
||||
// FIXME: should the translation be changed too?
|
||||
self.submat.set_rotation(rot)
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Rotate<V>, V, _0> Rotate<V> for Transform<M, _0> {
|
||||
|
@ -237,6 +249,10 @@ Transformation<Transform<M, V>> for Transform<M, V> {
|
|||
fn transformed(&self, t: &Transform<M, V>) -> Transform<M, V> {
|
||||
t * *self
|
||||
}
|
||||
|
||||
fn set_transformation(&mut self, t: Transform<M, V>) {
|
||||
*self = t
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Ts<V>, V: Add<V, V> + Sub<V, V>>
|
||||
|
|
|
@ -226,6 +226,11 @@ impl<N: Add<N, N> + Neg<N> + Clone> Translation<DVec<N>> for DVec<N> {
|
|||
fn translated(&self, t: &DVec<N>) -> DVec<N> {
|
||||
self + *t
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_translation(&mut self, t: DVec<N>) {
|
||||
*self = t
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Num + Algebraic + Clone> DVec<N> {
|
||||
|
|
|
@ -74,6 +74,11 @@ impl<V: Zero> Translation<V> for mat::Identity {
|
|||
fn translated(&self, _: &V) -> mat::Identity {
|
||||
fail!("Attempted to translate the identity matrix.")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_translation(&mut self, _: V) {
|
||||
fail!("Attempted to translate the identity matrix.")
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: Clone> Translate<V> for mat::Identity {
|
||||
|
@ -108,6 +113,11 @@ impl<V: Zero> Rotation<V> for mat::Identity {
|
|||
fn rotated(&self, _: &V) -> mat::Identity {
|
||||
fail!("Attempted to rotate the identity matrix.")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_rotation(&mut self, _: V) {
|
||||
fail!("Attempted to rotate the identity matrix.")
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: Clone> Rotate<V> for mat::Identity {
|
||||
|
@ -142,6 +152,11 @@ impl<M: One> Transformation<M> for mat::Identity {
|
|||
fn transformed(&self, _: &M) -> mat::Identity {
|
||||
fail!("Attempted to transform the identity matrix.")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_transformation(&mut self, _: M) {
|
||||
fail!("Attempted to transform the identity matrix.")
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: Clone> Transform<V> for mat::Identity {
|
||||
|
|
|
@ -15,6 +15,9 @@ pub trait Rotation<V> {
|
|||
|
||||
/// Appends a rotation.
|
||||
fn rotated(&self, &V) -> Self;
|
||||
|
||||
/// Sets the rotation.
|
||||
fn set_rotation(&mut self, V);
|
||||
}
|
||||
|
||||
/// Trait of objects able to rotate other objects. This is typically implemented by matrices which
|
||||
|
|
|
@ -13,6 +13,9 @@ pub trait Transformation<M> {
|
|||
|
||||
/// Appends a transformation.
|
||||
fn transformed(&self, &M) -> Self;
|
||||
|
||||
/// Sets the transformation.
|
||||
fn set_transformation(&mut self, M);
|
||||
}
|
||||
|
||||
/// Trait of objects able to transform other objects. This is typically implemented by matrices which
|
||||
|
|
|
@ -13,6 +13,9 @@ pub trait Translation<V> {
|
|||
|
||||
/// Appends a translation.
|
||||
fn translated(&self, &V) -> Self;
|
||||
|
||||
/// Sets the translation.
|
||||
fn set_translation(&mut self, V);
|
||||
}
|
||||
|
||||
/// Trait of objects able to rotate other objects. This is typically implemented by matrices which
|
||||
|
|
|
@ -161,6 +161,10 @@ impl<N: Clone + Add<N, N> + Neg<N>> Translation<vec::Vec0<N>> for vec::Vec0<N> {
|
|||
fn translated(&self, t: &vec::Vec0<N>) -> vec::Vec0<N> {
|
||||
self + *t
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_translation(&mut self, _: vec::Vec0<N>) {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Clone + Num + Algebraic> AlgebraicVec<N> for vec::Vec0<N> {
|
||||
|
|
|
@ -358,6 +358,11 @@ macro_rules! translation_impl(
|
|||
fn translated(&self, t: &$t<N>) -> $t<N> {
|
||||
self + *t
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_translation(&mut self, t: $t<N>) {
|
||||
*self = t
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue