diff --git a/src/SceneGraph/DualComplexTransformation.h b/src/SceneGraph/DualComplexTransformation.h index 199c6ac74..3edf7b8ef 100644 --- a/src/SceneGraph/DualComplexTransformation.h +++ b/src/SceneGraph/DualComplexTransformation.h @@ -60,14 +60,12 @@ template class BasicDualComplexTransformation: public AbstractBasicTran CORRADE_ASSERT(transformation.isNormalized(), "SceneGraph::DualComplexTransformation::setTransformation(): the dual complex number is not normalized", static_cast>&>(*this)); - setTransformationInternal(transformation); - return static_cast>&>(*this); + return setTransformationInternal(transformation); } /** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */ Object>& resetTransformation() { - setTransformationInternal({}); - return static_cast>&>(*this); + return setTransformationInternal({}); } /** @@ -79,8 +77,7 @@ template class BasicDualComplexTransformation: public AbstractBasicTran * @see DualComplex::normalized() */ Object>& normalizeRotation() { - setTransformationInternal(_transformation.normalized()); - return static_cast>&>(*this); + return setTransformationInternal(_transformation.normalized()); } /** @@ -96,8 +93,7 @@ template class BasicDualComplexTransformation: public AbstractBasicTran CORRADE_ASSERT(transformation.isNormalized(), "SceneGraph::DualComplexTransformation::transform(): the dual complex number is not normalized", static_cast>&>(*this)); - transformInternal(transformation, type); - return static_cast>&>(*this); + return transformInternal(transformation, type); } /** @@ -105,8 +101,7 @@ template class BasicDualComplexTransformation: public AbstractBasicTran * Same as calling transform() with DualComplex::translation(). */ Object>& translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { - transformInternal(Math::DualComplex::translation(vector), type); - return static_cast>&>(*this); + return transformInternal(Math::DualComplex::translation(vector), type); } /** @@ -119,8 +114,7 @@ template class BasicDualComplexTransformation: public AbstractBasicTran * @see normalizeRotation() */ Object>& rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { - transformInternal(Math::DualComplex::rotation(angle), type); - return static_cast>&>(*this); + return transformInternal(Math::DualComplex::rotation(angle), type); } /** @@ -150,7 +144,7 @@ template class BasicDualComplexTransformation: public AbstractBasicTran } /* No assertions fired, for internal use */ - void setTransformationInternal(const Math::DualComplex& transformation) { + Object>& setTransformationInternal(const Math::DualComplex& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ @@ -158,11 +152,13 @@ template class BasicDualComplexTransformation: public AbstractBasicTran _transformation = transformation; static_cast>*>(this)->setDirty(); } + + return static_cast>&>(*this); } /* No assertions fired, for internal use */ - void transformInternal(const Math::DualComplex& transformation, TransformationType type) { - setTransformationInternal(type == TransformationType::Global ? + Object>& transformInternal(const Math::DualComplex& transformation, TransformationType type) { + return setTransformationInternal(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); } diff --git a/src/SceneGraph/DualQuaternionTransformation.h b/src/SceneGraph/DualQuaternionTransformation.h index 5f00ad2bb..6f4a4bf98 100644 --- a/src/SceneGraph/DualQuaternionTransformation.h +++ b/src/SceneGraph/DualQuaternionTransformation.h @@ -60,14 +60,12 @@ template class BasicDualQuaternionTransformation: public AbstractBasicT CORRADE_ASSERT(transformation.isNormalized(), "SceneGraph::DualQuaternionTransformation::setTransformation(): the dual quaternion is not normalized", static_cast>&>(*this)); - setTransformationInternal(transformation); - return static_cast>&>(*this); + return setTransformationInternal(transformation); } /** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */ Object>& resetTransformation() { - setTransformationInternal({}); - return static_cast>&>(*this); + return setTransformationInternal({}); } /** @@ -79,8 +77,7 @@ template class BasicDualQuaternionTransformation: public AbstractBasicT * @see DualQuaternion::normalized() */ Object>& normalizeRotation() { - setTransformationInternal(_transformation.normalized()); - return static_cast>&>(*this); + return setTransformationInternal(_transformation.normalized()); } /** @@ -96,8 +93,7 @@ template class BasicDualQuaternionTransformation: public AbstractBasicT CORRADE_ASSERT(transformation.isNormalized(), "SceneGraph::DualQuaternionTransformation::transform(): the dual quaternion is not normalized", static_cast>&>(*this)); - transformInternal(transformation, type); - return static_cast>&>(*this); + return transformInternal(transformation, type); } /** @@ -105,8 +101,7 @@ template class BasicDualQuaternionTransformation: public AbstractBasicT * Same as calling transform() with DualQuaternion::translation(). */ Object>& translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { - transformInternal(Math::DualQuaternion::translation(vector), type); - return static_cast>&>(*this); + return transformInternal(Math::DualQuaternion::translation(vector), type); } /** @@ -121,8 +116,7 @@ template class BasicDualQuaternionTransformation: public AbstractBasicT * normalizeRotation() */ Object>& rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { - transformInternal(Math::DualQuaternion::rotation(angle, normalizedAxis), type); - return static_cast>&>(*this); + return transformInternal(Math::DualQuaternion::rotation(angle, normalizedAxis), type); } /* Overloads to remove WTF-factor from method chaining order */ @@ -154,7 +148,7 @@ template class BasicDualQuaternionTransformation: public AbstractBasicT } /* No assertions fired, for internal use */ - void setTransformationInternal(const Math::DualQuaternion& transformation) { + Object>& setTransformationInternal(const Math::DualQuaternion& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ @@ -162,11 +156,13 @@ template class BasicDualQuaternionTransformation: public AbstractBasicT _transformation = transformation; static_cast>*>(this)->setDirty(); } + + return static_cast>&>(*this); } /* No assertions fired, for internal use */ - void transformInternal(const Math::DualQuaternion& transformation, TransformationType type) { - setTransformationInternal(type == TransformationType::Global ? + Object>& transformInternal(const Math::DualQuaternion& transformation, TransformationType type) { + return setTransformationInternal(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); } diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index 05eb7e898..a2d0656b4 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -71,15 +71,13 @@ template class BasicMatrixTransformation2D: public AbstractBasicTransla * @return Reference to self (for method chaining) */ Object>& transform(const Math::Matrix3& transformation, TransformationType type = TransformationType::Global) { - setTransformation(type == TransformationType::Global ? + return setTransformation(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); - return static_cast>&>(*this); } /** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */ Object>& resetTransformation() { - setTransformation({}); - return static_cast>&>(*this); + return setTransformation({}); } /** @@ -87,8 +85,7 @@ template class BasicMatrixTransformation2D: public AbstractBasicTransla * Same as calling transform() with Matrix3::translation(). */ Object>& translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { - transform(Math::Matrix3::translation(vector), type); - return static_cast>&>(*this); + return transform(Math::Matrix3::translation(vector), type); } /** @@ -96,8 +93,7 @@ template class BasicMatrixTransformation2D: public AbstractBasicTransla * Same as calling transform() with Matrix3::rotation(). */ Object>& rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { - transform(Math::Matrix3::rotation(angle), type); - return static_cast>&>(*this); + return transform(Math::Matrix3::rotation(angle), type); } /** @@ -105,8 +101,7 @@ template class BasicMatrixTransformation2D: public AbstractBasicTransla * Same as calling transform() with Matrix3::scaling(). */ Object>& scale(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { - transform(Math::Matrix3::scaling(vector), type); - return static_cast>&>(*this); + return transform(Math::Matrix3::scaling(vector), type); } /** @@ -119,8 +114,7 @@ template class BasicMatrixTransformation2D: public AbstractBasicTransla * Same as calling transform() with Matrix3::reflection(). */ Object>& reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { - transform(Math::Matrix3::reflection(normal), type); - return static_cast>&>(*this); + return transform(Math::Matrix3::reflection(normal), type); } /** diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 69c9a9658..0c711b51c 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -66,8 +66,7 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla /** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */ Object>& resetTransformation() { - setTransformation({}); - return static_cast>&>(*this); + return setTransformation({}); } /** @@ -77,9 +76,8 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla * @return Reference to self (for method chaining) */ Object>& transform(const Math::Matrix4& transformation, TransformationType type = TransformationType::Global) { - setTransformation(type == TransformationType::Global ? + return setTransformation(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); - return static_cast>&>(*this); } /** @@ -87,8 +85,7 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla * Same as calling transform() with Matrix4::translation(). */ Object>& translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { - transform(Math::Matrix4::translation(vector), type); - return static_cast>&>(*this); + return transform(Math::Matrix4::translation(vector), type); } /** @@ -96,8 +93,7 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla * Same as calling transform() with Matrix4::rotation(). */ Object>& rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { - transform(Math::Matrix4::rotation(angle, normalizedAxis), type); - return static_cast>&>(*this); + return transform(Math::Matrix4::rotation(angle, normalizedAxis), type); } /** @@ -109,8 +105,7 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla * Same as calling transform() with Matrix4::rotationX(). */ Object>& rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { - transform(Math::Matrix4::rotationX(angle), type); - return static_cast>&>(*this); + return transform(Math::Matrix4::rotationX(angle), type); } /** @@ -122,8 +117,7 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla * Same as calling transform() with Matrix4::rotationY(). */ Object>& rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { - transform(Math::Matrix4::rotationY(angle), type); - return static_cast>&>(*this); + return transform(Math::Matrix4::rotationY(angle), type); } /** @@ -135,8 +129,7 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla * Same as calling transform() with Matrix4::rotationZ(). */ Object>& rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { - transform(Math::Matrix4::rotationZ(angle), type); - return static_cast>&>(*this); + return transform(Math::Matrix4::rotationZ(angle), type); } /** @@ -144,8 +137,7 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla * Same as calling transform() with Matrix4::scaling(). */ Object>& scale(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { - transform(Math::Matrix4::scaling(vector), type); - return static_cast>&>(*this); + return transform(Math::Matrix4::scaling(vector), type); } /** @@ -158,8 +150,7 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla * Same as calling transform() with Matrix4::reflection(). */ Object>& reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { - transform(Math::Matrix4::reflection(normal), type); - return static_cast>&>(*this); + return transform(Math::Matrix4::reflection(normal), type); } protected: diff --git a/src/SceneGraph/RigidMatrixTransformation2D.h b/src/SceneGraph/RigidMatrixTransformation2D.h index c52f04363..388491b00 100644 --- a/src/SceneGraph/RigidMatrixTransformation2D.h +++ b/src/SceneGraph/RigidMatrixTransformation2D.h @@ -63,14 +63,12 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr CORRADE_ASSERT(transformation.isRigidTransformation(), "SceneGraph::RigidMatrixTransformation2D::setTransformation(): the matrix doesn't represent rigid transformation", static_cast>&>(*this)); - setTransformationInternal(transformation); - return static_cast>&>(*this); + return setTransformationInternal(transformation); } /** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */ Object>& resetTransformation() { - setTransformationInternal({}); - return static_cast>&>(*this); + return setTransformationInternal({}); } /** @@ -81,10 +79,9 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr * to prevent rounding errors when rotating the object subsequently. */ Object>& normalizeRotation() { - setTransformationInternal(Math::Matrix3::from( + return setTransformationInternal(Math::Matrix3::from( Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); - return static_cast>&>(*this); } /** @@ -100,8 +97,7 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr CORRADE_ASSERT(transformation.isRigidTransformation(), "SceneGraph::RigidMatrixTransformation2D::transform(): the matrix doesn't represent rigid transformation", static_cast>&>(*this)); - transformInternal(transformation, type); - return static_cast>&>(*this); + return transformInternal(transformation, type); } /** @@ -109,8 +105,7 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr * Same as calling transform() with Matrix3::translation(). */ Object>& translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { - transformInternal(Math::Matrix3::translation(vector), type); - return static_cast>&>(*this); + return transformInternal(Math::Matrix3::translation(vector), type); } /** @@ -123,8 +118,7 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr * @see normalizeRotation() */ Object>& rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { - transformInternal(Math::Matrix3::rotation(angle), type); - return static_cast>&>(*this); + return transformInternal(Math::Matrix3::rotation(angle), type); } /** @@ -137,8 +131,7 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr * Same as calling transform() with Matrix3::reflection(). */ Object>& reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { - transformInternal(Math::Matrix3::reflection(normal), type); - return static_cast>&>(*this); + return transformInternal(Math::Matrix3::reflection(normal), type); } /** @@ -168,7 +161,7 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr } /* No assertions fired, for internal use */ - void setTransformationInternal(const Math::Matrix3& transformation) { + Object>& setTransformationInternal(const Math::Matrix3& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ @@ -176,11 +169,13 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr _transformation = transformation; static_cast>*>(this)->setDirty(); } + + return static_cast>&>(*this); } /* No assertions fired, for internal use */ - void transformInternal(const Math::Matrix3& transformation, TransformationType type) { - setTransformationInternal(type == TransformationType::Global ? + Object>& transformInternal(const Math::Matrix3& transformation, TransformationType type) { + return setTransformationInternal(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); } diff --git a/src/SceneGraph/RigidMatrixTransformation3D.h b/src/SceneGraph/RigidMatrixTransformation3D.h index 1ccb08452..0d0e4dc55 100644 --- a/src/SceneGraph/RigidMatrixTransformation3D.h +++ b/src/SceneGraph/RigidMatrixTransformation3D.h @@ -63,14 +63,12 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr CORRADE_ASSERT(transformation.isRigidTransformation(), "SceneGraph::RigidMatrixTransformation3D::setTransformation(): the matrix doesn't represent rigid transformation", static_cast>&>(*this)); - setTransformationInternal(transformation); - return static_cast>&>(*this); + return setTransformationInternal(transformation); } /** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */ Object>& resetTransformation() { - setTransformationInternal({}); - return static_cast>&>(*this); + return setTransformationInternal({}); } /** @@ -81,10 +79,9 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr * to prevent rounding errors when rotating the object subsequently. */ Object>& normalizeRotation() { - setTransformationInternal(Math::Matrix4::from( + return setTransformationInternal(Math::Matrix4::from( Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); - return static_cast>&>(*this); } /** @@ -100,8 +97,7 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr CORRADE_ASSERT(transformation.isRigidTransformation(), "SceneGraph::RigidMatrixTransformation3D::transform(): the matrix doesn't represent rigid transformation", static_cast>&>(*this)); - transformInternal(transformation, type); - return static_cast>&>(*this); + return transformInternal(transformation, type); } /** @@ -109,8 +105,7 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr * Same as calling transform() with Matrix4::translation(). */ Object>& translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { - transformInternal(Math::Matrix4::translation(vector), type); - return static_cast>&>(*this); + return transformInternal(Math::Matrix4::translation(vector), type); } /** @@ -125,8 +120,7 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr * Vector3::yAxis(), Vector3::zAxis(), normalizeRotation() */ Object>& rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { - transformInternal(Math::Matrix4::rotation(angle, normalizedAxis), type); - return static_cast>&>(*this); + return transformInternal(Math::Matrix4::rotation(angle, normalizedAxis), type); } /** @@ -139,8 +133,7 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr * @see normalizeRotation() */ Object>& rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { - transformInternal(Math::Matrix4::rotationX(angle), type); - return static_cast>&>(*this); + return transformInternal(Math::Matrix4::rotationX(angle), type); } /** @@ -153,8 +146,7 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr * @see normalizeRotation() */ Object>& rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { - transformInternal(Math::Matrix4::rotationY(angle), type); - return static_cast>&>(*this); + return transformInternal(Math::Matrix4::rotationY(angle), type); } /** @@ -167,8 +159,7 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr * @see normalizeRotation() */ Object>& rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { - transformInternal(Math::Matrix4::rotationZ(angle), type); - return static_cast>&>(*this); + return transformInternal(Math::Matrix4::rotationZ(angle), type); } /** @@ -181,8 +172,7 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr * Same as calling transform() with Matrix4::reflection(). */ Object>& reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { - transformInternal(Math::Matrix4::reflection(normal), type); - return static_cast>&>(*this); + return transformInternal(Math::Matrix4::reflection(normal), type); } protected: @@ -213,7 +203,7 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr } /* No assertions fired, for internal use */ - void setTransformationInternal(const Math::Matrix4& transformation) { + Object>& setTransformationInternal(const Math::Matrix4& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ @@ -221,11 +211,13 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr _transformation = transformation; static_cast>*>(this)->setDirty(); } + + return static_cast>&>(*this); } /* No assertions fired, for internal use */ - void transformInternal(const Math::Matrix4& transformation, TransformationType type) { - setTransformationInternal(type == TransformationType::Global ? + Object>& transformInternal(const Math::Matrix4& transformation, TransformationType type) { + return setTransformationInternal(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); }