Browse Source

SceneGraph: clean up the code a bit.

No need to copy `return static_cast<...>;` all over the place.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
4e7c7925a7
  1. 26
      src/SceneGraph/DualComplexTransformation.h
  2. 26
      src/SceneGraph/DualQuaternionTransformation.h
  3. 18
      src/SceneGraph/MatrixTransformation2D.h
  4. 27
      src/SceneGraph/MatrixTransformation3D.h
  5. 29
      src/SceneGraph/RigidMatrixTransformation2D.h
  6. 38
      src/SceneGraph/RigidMatrixTransformation3D.h

26
src/SceneGraph/DualComplexTransformation.h

@ -60,14 +60,12 @@ template<class T> class BasicDualComplexTransformation: public AbstractBasicTran
CORRADE_ASSERT(transformation.isNormalized(), CORRADE_ASSERT(transformation.isNormalized(),
"SceneGraph::DualComplexTransformation::setTransformation(): the dual complex number is not normalized", "SceneGraph::DualComplexTransformation::setTransformation(): the dual complex number is not normalized",
static_cast<Object<BasicDualComplexTransformation<T>>&>(*this)); static_cast<Object<BasicDualComplexTransformation<T>>&>(*this));
setTransformationInternal(transformation); return setTransformationInternal(transformation);
return static_cast<Object<BasicDualComplexTransformation<T>>&>(*this);
} }
/** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */ /** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */
Object<BasicDualComplexTransformation<T>>& resetTransformation() { Object<BasicDualComplexTransformation<T>>& resetTransformation() {
setTransformationInternal({}); return setTransformationInternal({});
return static_cast<Object<BasicDualComplexTransformation<T>>&>(*this);
} }
/** /**
@ -79,8 +77,7 @@ template<class T> class BasicDualComplexTransformation: public AbstractBasicTran
* @see DualComplex::normalized() * @see DualComplex::normalized()
*/ */
Object<BasicDualComplexTransformation<T>>& normalizeRotation() { Object<BasicDualComplexTransformation<T>>& normalizeRotation() {
setTransformationInternal(_transformation.normalized()); return setTransformationInternal(_transformation.normalized());
return static_cast<Object<BasicDualComplexTransformation<T>>&>(*this);
} }
/** /**
@ -96,8 +93,7 @@ template<class T> class BasicDualComplexTransformation: public AbstractBasicTran
CORRADE_ASSERT(transformation.isNormalized(), CORRADE_ASSERT(transformation.isNormalized(),
"SceneGraph::DualComplexTransformation::transform(): the dual complex number is not normalized", "SceneGraph::DualComplexTransformation::transform(): the dual complex number is not normalized",
static_cast<Object<BasicDualComplexTransformation<T>>&>(*this)); static_cast<Object<BasicDualComplexTransformation<T>>&>(*this));
transformInternal(transformation, type); return transformInternal(transformation, type);
return static_cast<Object<BasicDualComplexTransformation<T>>&>(*this);
} }
/** /**
@ -105,8 +101,7 @@ template<class T> class BasicDualComplexTransformation: public AbstractBasicTran
* Same as calling transform() with DualComplex::translation(). * Same as calling transform() with DualComplex::translation().
*/ */
Object<BasicDualComplexTransformation<T>>& translate(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) { Object<BasicDualComplexTransformation<T>>& translate(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) {
transformInternal(Math::DualComplex<T>::translation(vector), type); return transformInternal(Math::DualComplex<T>::translation(vector), type);
return static_cast<Object<BasicDualComplexTransformation<T>>&>(*this);
} }
/** /**
@ -119,8 +114,7 @@ template<class T> class BasicDualComplexTransformation: public AbstractBasicTran
* @see normalizeRotation() * @see normalizeRotation()
*/ */
Object<BasicDualComplexTransformation<T>>& rotate(Math::Rad<T> angle, TransformationType type = TransformationType::Global) { Object<BasicDualComplexTransformation<T>>& rotate(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
transformInternal(Math::DualComplex<T>::rotation(angle), type); return transformInternal(Math::DualComplex<T>::rotation(angle), type);
return static_cast<Object<BasicDualComplexTransformation<T>>&>(*this);
} }
/** /**
@ -150,7 +144,7 @@ template<class T> class BasicDualComplexTransformation: public AbstractBasicTran
} }
/* No assertions fired, for internal use */ /* No assertions fired, for internal use */
void setTransformationInternal(const Math::DualComplex<T>& transformation) { Object<BasicDualComplexTransformation<T>>& setTransformationInternal(const Math::DualComplex<T>& transformation) {
/* Setting transformation is forbidden for the scene */ /* Setting transformation is forbidden for the scene */
/** @todo Assert for this? */ /** @todo Assert for this? */
/** @todo Do this in some common code so we don't need to include Object? */ /** @todo Do this in some common code so we don't need to include Object? */
@ -158,11 +152,13 @@ template<class T> class BasicDualComplexTransformation: public AbstractBasicTran
_transformation = transformation; _transformation = transformation;
static_cast<Object<BasicDualComplexTransformation<T>>*>(this)->setDirty(); static_cast<Object<BasicDualComplexTransformation<T>>*>(this)->setDirty();
} }
return static_cast<Object<BasicDualComplexTransformation<T>>&>(*this);
} }
/* No assertions fired, for internal use */ /* No assertions fired, for internal use */
void transformInternal(const Math::DualComplex<T>& transformation, TransformationType type) { Object<BasicDualComplexTransformation<T>>& transformInternal(const Math::DualComplex<T>& transformation, TransformationType type) {
setTransformationInternal(type == TransformationType::Global ? return setTransformationInternal(type == TransformationType::Global ?
transformation*_transformation : _transformation*transformation); transformation*_transformation : _transformation*transformation);
} }

26
src/SceneGraph/DualQuaternionTransformation.h

@ -60,14 +60,12 @@ template<class T> class BasicDualQuaternionTransformation: public AbstractBasicT
CORRADE_ASSERT(transformation.isNormalized(), CORRADE_ASSERT(transformation.isNormalized(),
"SceneGraph::DualQuaternionTransformation::setTransformation(): the dual quaternion is not normalized", "SceneGraph::DualQuaternionTransformation::setTransformation(): the dual quaternion is not normalized",
static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this)); static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this));
setTransformationInternal(transformation); return setTransformationInternal(transformation);
return static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this);
} }
/** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */ /** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */
Object<BasicDualQuaternionTransformation<T>>& resetTransformation() { Object<BasicDualQuaternionTransformation<T>>& resetTransformation() {
setTransformationInternal({}); return setTransformationInternal({});
return static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this);
} }
/** /**
@ -79,8 +77,7 @@ template<class T> class BasicDualQuaternionTransformation: public AbstractBasicT
* @see DualQuaternion::normalized() * @see DualQuaternion::normalized()
*/ */
Object<BasicDualQuaternionTransformation<T>>& normalizeRotation() { Object<BasicDualQuaternionTransformation<T>>& normalizeRotation() {
setTransformationInternal(_transformation.normalized()); return setTransformationInternal(_transformation.normalized());
return static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this);
} }
/** /**
@ -96,8 +93,7 @@ template<class T> class BasicDualQuaternionTransformation: public AbstractBasicT
CORRADE_ASSERT(transformation.isNormalized(), CORRADE_ASSERT(transformation.isNormalized(),
"SceneGraph::DualQuaternionTransformation::transform(): the dual quaternion is not normalized", "SceneGraph::DualQuaternionTransformation::transform(): the dual quaternion is not normalized",
static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this)); static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this));
transformInternal(transformation, type); return transformInternal(transformation, type);
return static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this);
} }
/** /**
@ -105,8 +101,7 @@ template<class T> class BasicDualQuaternionTransformation: public AbstractBasicT
* Same as calling transform() with DualQuaternion::translation(). * Same as calling transform() with DualQuaternion::translation().
*/ */
Object<BasicDualQuaternionTransformation<T>>& translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) { Object<BasicDualQuaternionTransformation<T>>& translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) {
transformInternal(Math::DualQuaternion<T>::translation(vector), type); return transformInternal(Math::DualQuaternion<T>::translation(vector), type);
return static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this);
} }
/** /**
@ -121,8 +116,7 @@ template<class T> class BasicDualQuaternionTransformation: public AbstractBasicT
* normalizeRotation() * normalizeRotation()
*/ */
Object<BasicDualQuaternionTransformation<T>>& rotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) { Object<BasicDualQuaternionTransformation<T>>& rotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) {
transformInternal(Math::DualQuaternion<T>::rotation(angle, normalizedAxis), type); return transformInternal(Math::DualQuaternion<T>::rotation(angle, normalizedAxis), type);
return static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this);
} }
/* Overloads to remove WTF-factor from method chaining order */ /* Overloads to remove WTF-factor from method chaining order */
@ -154,7 +148,7 @@ template<class T> class BasicDualQuaternionTransformation: public AbstractBasicT
} }
/* No assertions fired, for internal use */ /* No assertions fired, for internal use */
void setTransformationInternal(const Math::DualQuaternion<T>& transformation) { Object<BasicDualQuaternionTransformation<T>>& setTransformationInternal(const Math::DualQuaternion<T>& transformation) {
/* Setting transformation is forbidden for the scene */ /* Setting transformation is forbidden for the scene */
/** @todo Assert for this? */ /** @todo Assert for this? */
/** @todo Do this in some common code so we don't need to include Object? */ /** @todo Do this in some common code so we don't need to include Object? */
@ -162,11 +156,13 @@ template<class T> class BasicDualQuaternionTransformation: public AbstractBasicT
_transformation = transformation; _transformation = transformation;
static_cast<Object<BasicDualQuaternionTransformation<T>>*>(this)->setDirty(); static_cast<Object<BasicDualQuaternionTransformation<T>>*>(this)->setDirty();
} }
return static_cast<Object<BasicDualQuaternionTransformation<T>>&>(*this);
} }
/* No assertions fired, for internal use */ /* No assertions fired, for internal use */
void transformInternal(const Math::DualQuaternion<T>& transformation, TransformationType type) { Object<BasicDualQuaternionTransformation<T>>& transformInternal(const Math::DualQuaternion<T>& transformation, TransformationType type) {
setTransformationInternal(type == TransformationType::Global ? return setTransformationInternal(type == TransformationType::Global ?
transformation*_transformation : _transformation*transformation); transformation*_transformation : _transformation*transformation);
} }

18
src/SceneGraph/MatrixTransformation2D.h

@ -71,15 +71,13 @@ template<class T> class BasicMatrixTransformation2D: public AbstractBasicTransla
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
Object<BasicMatrixTransformation2D<T>>& transform(const Math::Matrix3<T>& transformation, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation2D<T>>& transform(const Math::Matrix3<T>& transformation, TransformationType type = TransformationType::Global) {
setTransformation(type == TransformationType::Global ? return setTransformation(type == TransformationType::Global ?
transformation*_transformation : _transformation*transformation); transformation*_transformation : _transformation*transformation);
return static_cast<Object<BasicMatrixTransformation2D<T>>&>(*this);
} }
/** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */ /** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */
Object<BasicMatrixTransformation2D<T>>& resetTransformation() { Object<BasicMatrixTransformation2D<T>>& resetTransformation() {
setTransformation({}); return setTransformation({});
return static_cast<Object<BasicMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -87,8 +85,7 @@ template<class T> class BasicMatrixTransformation2D: public AbstractBasicTransla
* Same as calling transform() with Matrix3::translation(). * Same as calling transform() with Matrix3::translation().
*/ */
Object<BasicMatrixTransformation2D<T>>& translate(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation2D<T>>& translate(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) {
transform(Math::Matrix3<T>::translation(vector), type); return transform(Math::Matrix3<T>::translation(vector), type);
return static_cast<Object<BasicMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -96,8 +93,7 @@ template<class T> class BasicMatrixTransformation2D: public AbstractBasicTransla
* Same as calling transform() with Matrix3::rotation(). * Same as calling transform() with Matrix3::rotation().
*/ */
Object<BasicMatrixTransformation2D<T>>& rotate(Math::Rad<T> angle, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation2D<T>>& rotate(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
transform(Math::Matrix3<T>::rotation(angle), type); return transform(Math::Matrix3<T>::rotation(angle), type);
return static_cast<Object<BasicMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -105,8 +101,7 @@ template<class T> class BasicMatrixTransformation2D: public AbstractBasicTransla
* Same as calling transform() with Matrix3::scaling(). * Same as calling transform() with Matrix3::scaling().
*/ */
Object<BasicMatrixTransformation2D<T>>& scale(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation2D<T>>& scale(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) {
transform(Math::Matrix3<T>::scaling(vector), type); return transform(Math::Matrix3<T>::scaling(vector), type);
return static_cast<Object<BasicMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -119,8 +114,7 @@ template<class T> class BasicMatrixTransformation2D: public AbstractBasicTransla
* Same as calling transform() with Matrix3::reflection(). * Same as calling transform() with Matrix3::reflection().
*/ */
Object<BasicMatrixTransformation2D<T>>& reflect(const Math::Vector2<T>& normal, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation2D<T>>& reflect(const Math::Vector2<T>& normal, TransformationType type = TransformationType::Global) {
transform(Math::Matrix3<T>::reflection(normal), type); return transform(Math::Matrix3<T>::reflection(normal), type);
return static_cast<Object<BasicMatrixTransformation2D<T>>&>(*this);
} }
/** /**

27
src/SceneGraph/MatrixTransformation3D.h

@ -66,8 +66,7 @@ template<class T> class BasicMatrixTransformation3D: public AbstractBasicTransla
/** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */ /** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */
Object<BasicMatrixTransformation3D<T>>& resetTransformation() { Object<BasicMatrixTransformation3D<T>>& resetTransformation() {
setTransformation({}); return setTransformation({});
return static_cast<Object<BasicMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -77,9 +76,8 @@ template<class T> class BasicMatrixTransformation3D: public AbstractBasicTransla
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
Object<BasicMatrixTransformation3D<T>>& transform(const Math::Matrix4<T>& transformation, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation3D<T>>& transform(const Math::Matrix4<T>& transformation, TransformationType type = TransformationType::Global) {
setTransformation(type == TransformationType::Global ? return setTransformation(type == TransformationType::Global ?
transformation*_transformation : _transformation*transformation); transformation*_transformation : _transformation*transformation);
return static_cast<Object<BasicMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -87,8 +85,7 @@ template<class T> class BasicMatrixTransformation3D: public AbstractBasicTransla
* Same as calling transform() with Matrix4::translation(). * Same as calling transform() with Matrix4::translation().
*/ */
Object<BasicMatrixTransformation3D<T>>& translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation3D<T>>& translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) {
transform(Math::Matrix4<T>::translation(vector), type); return transform(Math::Matrix4<T>::translation(vector), type);
return static_cast<Object<BasicMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -96,8 +93,7 @@ template<class T> class BasicMatrixTransformation3D: public AbstractBasicTransla
* Same as calling transform() with Matrix4::rotation(). * Same as calling transform() with Matrix4::rotation().
*/ */
Object<BasicMatrixTransformation3D<T>>& rotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation3D<T>>& rotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) {
transform(Math::Matrix4<T>::rotation(angle, normalizedAxis), type); return transform(Math::Matrix4<T>::rotation(angle, normalizedAxis), type);
return static_cast<Object<BasicMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -109,8 +105,7 @@ template<class T> class BasicMatrixTransformation3D: public AbstractBasicTransla
* Same as calling transform() with Matrix4::rotationX(). * Same as calling transform() with Matrix4::rotationX().
*/ */
Object<BasicMatrixTransformation3D<T>>& rotateX(Math::Rad<T> angle, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation3D<T>>& rotateX(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
transform(Math::Matrix4<T>::rotationX(angle), type); return transform(Math::Matrix4<T>::rotationX(angle), type);
return static_cast<Object<BasicMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -122,8 +117,7 @@ template<class T> class BasicMatrixTransformation3D: public AbstractBasicTransla
* Same as calling transform() with Matrix4::rotationY(). * Same as calling transform() with Matrix4::rotationY().
*/ */
Object<BasicMatrixTransformation3D<T>>& rotateY(Math::Rad<T> angle, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation3D<T>>& rotateY(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
transform(Math::Matrix4<T>::rotationY(angle), type); return transform(Math::Matrix4<T>::rotationY(angle), type);
return static_cast<Object<BasicMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -135,8 +129,7 @@ template<class T> class BasicMatrixTransformation3D: public AbstractBasicTransla
* Same as calling transform() with Matrix4::rotationZ(). * Same as calling transform() with Matrix4::rotationZ().
*/ */
Object<BasicMatrixTransformation3D<T>>& rotateZ(Math::Rad<T> angle, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation3D<T>>& rotateZ(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
transform(Math::Matrix4<T>::rotationZ(angle), type); return transform(Math::Matrix4<T>::rotationZ(angle), type);
return static_cast<Object<BasicMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -144,8 +137,7 @@ template<class T> class BasicMatrixTransformation3D: public AbstractBasicTransla
* Same as calling transform() with Matrix4::scaling(). * Same as calling transform() with Matrix4::scaling().
*/ */
Object<BasicMatrixTransformation3D<T>>& scale(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation3D<T>>& scale(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) {
transform(Math::Matrix4<T>::scaling(vector), type); return transform(Math::Matrix4<T>::scaling(vector), type);
return static_cast<Object<BasicMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -158,8 +150,7 @@ template<class T> class BasicMatrixTransformation3D: public AbstractBasicTransla
* Same as calling transform() with Matrix4::reflection(). * Same as calling transform() with Matrix4::reflection().
*/ */
Object<BasicMatrixTransformation3D<T>>& reflect(const Math::Vector3<T>& normal, TransformationType type = TransformationType::Global) { Object<BasicMatrixTransformation3D<T>>& reflect(const Math::Vector3<T>& normal, TransformationType type = TransformationType::Global) {
transform(Math::Matrix4<T>::reflection(normal), type); return transform(Math::Matrix4<T>::reflection(normal), type);
return static_cast<Object<BasicMatrixTransformation3D<T>>&>(*this);
} }
protected: protected:

29
src/SceneGraph/RigidMatrixTransformation2D.h

@ -63,14 +63,12 @@ template<class T> class BasicRigidMatrixTransformation2D: public AbstractBasicTr
CORRADE_ASSERT(transformation.isRigidTransformation(), CORRADE_ASSERT(transformation.isRigidTransformation(),
"SceneGraph::RigidMatrixTransformation2D::setTransformation(): the matrix doesn't represent rigid transformation", "SceneGraph::RigidMatrixTransformation2D::setTransformation(): the matrix doesn't represent rigid transformation",
static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this)); static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this));
setTransformationInternal(transformation); return setTransformationInternal(transformation);
return static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this);
} }
/** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */ /** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */
Object<BasicRigidMatrixTransformation2D<T>>& resetTransformation() { Object<BasicRigidMatrixTransformation2D<T>>& resetTransformation() {
setTransformationInternal({}); return setTransformationInternal({});
return static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -81,10 +79,9 @@ template<class T> class BasicRigidMatrixTransformation2D: public AbstractBasicTr
* to prevent rounding errors when rotating the object subsequently. * to prevent rounding errors when rotating the object subsequently.
*/ */
Object<BasicRigidMatrixTransformation2D<T>>& normalizeRotation() { Object<BasicRigidMatrixTransformation2D<T>>& normalizeRotation() {
setTransformationInternal(Math::Matrix3<T>::from( return setTransformationInternal(Math::Matrix3<T>::from(
Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()),
_transformation.translation())); _transformation.translation()));
return static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -100,8 +97,7 @@ template<class T> class BasicRigidMatrixTransformation2D: public AbstractBasicTr
CORRADE_ASSERT(transformation.isRigidTransformation(), CORRADE_ASSERT(transformation.isRigidTransformation(),
"SceneGraph::RigidMatrixTransformation2D::transform(): the matrix doesn't represent rigid transformation", "SceneGraph::RigidMatrixTransformation2D::transform(): the matrix doesn't represent rigid transformation",
static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this)); static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this));
transformInternal(transformation, type); return transformInternal(transformation, type);
return static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -109,8 +105,7 @@ template<class T> class BasicRigidMatrixTransformation2D: public AbstractBasicTr
* Same as calling transform() with Matrix3::translation(). * Same as calling transform() with Matrix3::translation().
*/ */
Object<BasicRigidMatrixTransformation2D<T>>& translate(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) { Object<BasicRigidMatrixTransformation2D<T>>& translate(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) {
transformInternal(Math::Matrix3<T>::translation(vector), type); return transformInternal(Math::Matrix3<T>::translation(vector), type);
return static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -123,8 +118,7 @@ template<class T> class BasicRigidMatrixTransformation2D: public AbstractBasicTr
* @see normalizeRotation() * @see normalizeRotation()
*/ */
Object<BasicRigidMatrixTransformation2D<T>>& rotate(Math::Rad<T> angle, TransformationType type = TransformationType::Global) { Object<BasicRigidMatrixTransformation2D<T>>& rotate(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
transformInternal(Math::Matrix3<T>::rotation(angle), type); return transformInternal(Math::Matrix3<T>::rotation(angle), type);
return static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -137,8 +131,7 @@ template<class T> class BasicRigidMatrixTransformation2D: public AbstractBasicTr
* Same as calling transform() with Matrix3::reflection(). * Same as calling transform() with Matrix3::reflection().
*/ */
Object<BasicRigidMatrixTransformation2D<T>>& reflect(const Math::Vector2<T>& normal, TransformationType type = TransformationType::Global) { Object<BasicRigidMatrixTransformation2D<T>>& reflect(const Math::Vector2<T>& normal, TransformationType type = TransformationType::Global) {
transformInternal(Math::Matrix3<T>::reflection(normal), type); return transformInternal(Math::Matrix3<T>::reflection(normal), type);
return static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this);
} }
/** /**
@ -168,7 +161,7 @@ template<class T> class BasicRigidMatrixTransformation2D: public AbstractBasicTr
} }
/* No assertions fired, for internal use */ /* No assertions fired, for internal use */
void setTransformationInternal(const Math::Matrix3<T>& transformation) { Object<BasicRigidMatrixTransformation2D<T>>& setTransformationInternal(const Math::Matrix3<T>& transformation) {
/* Setting transformation is forbidden for the scene */ /* Setting transformation is forbidden for the scene */
/** @todo Assert for this? */ /** @todo Assert for this? */
/** @todo Do this in some common code so we don't need to include Object? */ /** @todo Do this in some common code so we don't need to include Object? */
@ -176,11 +169,13 @@ template<class T> class BasicRigidMatrixTransformation2D: public AbstractBasicTr
_transformation = transformation; _transformation = transformation;
static_cast<Object<BasicRigidMatrixTransformation2D<T>>*>(this)->setDirty(); static_cast<Object<BasicRigidMatrixTransformation2D<T>>*>(this)->setDirty();
} }
return static_cast<Object<BasicRigidMatrixTransformation2D<T>>&>(*this);
} }
/* No assertions fired, for internal use */ /* No assertions fired, for internal use */
void transformInternal(const Math::Matrix3<T>& transformation, TransformationType type) { Object<BasicRigidMatrixTransformation2D<T>>& transformInternal(const Math::Matrix3<T>& transformation, TransformationType type) {
setTransformationInternal(type == TransformationType::Global ? return setTransformationInternal(type == TransformationType::Global ?
transformation*_transformation : _transformation*transformation); transformation*_transformation : _transformation*transformation);
} }

38
src/SceneGraph/RigidMatrixTransformation3D.h

@ -63,14 +63,12 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
CORRADE_ASSERT(transformation.isRigidTransformation(), CORRADE_ASSERT(transformation.isRigidTransformation(),
"SceneGraph::RigidMatrixTransformation3D::setTransformation(): the matrix doesn't represent rigid transformation", "SceneGraph::RigidMatrixTransformation3D::setTransformation(): the matrix doesn't represent rigid transformation",
static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this)); static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this));
setTransformationInternal(transformation); return setTransformationInternal(transformation);
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */ /** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */
Object<BasicRigidMatrixTransformation3D<T>>& resetTransformation() { Object<BasicRigidMatrixTransformation3D<T>>& resetTransformation() {
setTransformationInternal({}); return setTransformationInternal({});
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -81,10 +79,9 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
* to prevent rounding errors when rotating the object subsequently. * to prevent rounding errors when rotating the object subsequently.
*/ */
Object<BasicRigidMatrixTransformation3D<T>>& normalizeRotation() { Object<BasicRigidMatrixTransformation3D<T>>& normalizeRotation() {
setTransformationInternal(Math::Matrix4<T>::from( return setTransformationInternal(Math::Matrix4<T>::from(
Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()),
_transformation.translation())); _transformation.translation()));
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -100,8 +97,7 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
CORRADE_ASSERT(transformation.isRigidTransformation(), CORRADE_ASSERT(transformation.isRigidTransformation(),
"SceneGraph::RigidMatrixTransformation3D::transform(): the matrix doesn't represent rigid transformation", "SceneGraph::RigidMatrixTransformation3D::transform(): the matrix doesn't represent rigid transformation",
static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this)); static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this));
transformInternal(transformation, type); return transformInternal(transformation, type);
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -109,8 +105,7 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
* Same as calling transform() with Matrix4::translation(). * Same as calling transform() with Matrix4::translation().
*/ */
Object<BasicRigidMatrixTransformation3D<T>>& translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) { Object<BasicRigidMatrixTransformation3D<T>>& translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) {
transformInternal(Math::Matrix4<T>::translation(vector), type); return transformInternal(Math::Matrix4<T>::translation(vector), type);
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -125,8 +120,7 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
* Vector3::yAxis(), Vector3::zAxis(), normalizeRotation() * Vector3::yAxis(), Vector3::zAxis(), normalizeRotation()
*/ */
Object<BasicRigidMatrixTransformation3D<T>>& rotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) { Object<BasicRigidMatrixTransformation3D<T>>& rotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) {
transformInternal(Math::Matrix4<T>::rotation(angle, normalizedAxis), type); return transformInternal(Math::Matrix4<T>::rotation(angle, normalizedAxis), type);
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -139,8 +133,7 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
* @see normalizeRotation() * @see normalizeRotation()
*/ */
Object<BasicRigidMatrixTransformation3D<T>>& rotateX(Math::Rad<T> angle, TransformationType type = TransformationType::Global) { Object<BasicRigidMatrixTransformation3D<T>>& rotateX(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
transformInternal(Math::Matrix4<T>::rotationX(angle), type); return transformInternal(Math::Matrix4<T>::rotationX(angle), type);
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -153,8 +146,7 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
* @see normalizeRotation() * @see normalizeRotation()
*/ */
Object<BasicRigidMatrixTransformation3D<T>>& rotateY(Math::Rad<T> angle, TransformationType type = TransformationType::Global) { Object<BasicRigidMatrixTransformation3D<T>>& rotateY(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
transformInternal(Math::Matrix4<T>::rotationY(angle), type); return transformInternal(Math::Matrix4<T>::rotationY(angle), type);
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -167,8 +159,7 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
* @see normalizeRotation() * @see normalizeRotation()
*/ */
Object<BasicRigidMatrixTransformation3D<T>>& rotateZ(Math::Rad<T> angle, TransformationType type = TransformationType::Global) { Object<BasicRigidMatrixTransformation3D<T>>& rotateZ(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
transformInternal(Math::Matrix4<T>::rotationZ(angle), type); return transformInternal(Math::Matrix4<T>::rotationZ(angle), type);
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/** /**
@ -181,8 +172,7 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
* Same as calling transform() with Matrix4::reflection(). * Same as calling transform() with Matrix4::reflection().
*/ */
Object<BasicRigidMatrixTransformation3D<T>>& reflect(const Math::Vector3<T>& normal, TransformationType type = TransformationType::Global) { Object<BasicRigidMatrixTransformation3D<T>>& reflect(const Math::Vector3<T>& normal, TransformationType type = TransformationType::Global) {
transformInternal(Math::Matrix4<T>::reflection(normal), type); return transformInternal(Math::Matrix4<T>::reflection(normal), type);
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
protected: protected:
@ -213,7 +203,7 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
} }
/* No assertions fired, for internal use */ /* No assertions fired, for internal use */
void setTransformationInternal(const Math::Matrix4<T>& transformation) { Object<BasicRigidMatrixTransformation3D<T>>& setTransformationInternal(const Math::Matrix4<T>& transformation) {
/* Setting transformation is forbidden for the scene */ /* Setting transformation is forbidden for the scene */
/** @todo Assert for this? */ /** @todo Assert for this? */
/** @todo Do this in some common code so we don't need to include Object? */ /** @todo Do this in some common code so we don't need to include Object? */
@ -221,11 +211,13 @@ template<class T> class BasicRigidMatrixTransformation3D: public AbstractBasicTr
_transformation = transformation; _transformation = transformation;
static_cast<Object<BasicRigidMatrixTransformation3D<T>>*>(this)->setDirty(); static_cast<Object<BasicRigidMatrixTransformation3D<T>>*>(this)->setDirty();
} }
return static_cast<Object<BasicRigidMatrixTransformation3D<T>>&>(*this);
} }
/* No assertions fired, for internal use */ /* No assertions fired, for internal use */
void transformInternal(const Math::Matrix4<T>& transformation, TransformationType type) { Object<BasicRigidMatrixTransformation3D<T>>& transformInternal(const Math::Matrix4<T>& transformation, TransformationType type) {
setTransformationInternal(type == TransformationType::Global ? return setTransformationInternal(type == TransformationType::Global ?
transformation*_transformation : _transformation*transformation); transformation*_transformation : _transformation*transformation);
} }

Loading…
Cancel
Save