Browse Source

SceneGraph: test that TRS transforms properly decompose reflection.

They do not.
pull/537/head
Vladimír Vondruš 5 years ago
parent
commit
1f55165941
  1. 22
      src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation2DTest.cpp
  2. 24
      src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation3DTest.cpp

22
src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation2DTest.cpp

@ -42,6 +42,7 @@ struct TranslationRotationScalingTransformation2DTest: TestSuite::Tester {
template<class T> void defaults();
template<class T> void setTransformation();
template<class T> void setTransformationRotateALot();
template<class T> void setTransformationReflection();
template<class T> void resetTransformation();
template<class T> void translate();
@ -66,6 +67,8 @@ TranslationRotationScalingTransformation2DTest::TranslationRotationScalingTransf
&TranslationRotationScalingTransformation2DTest::setTransformation<Double>,
&TranslationRotationScalingTransformation2DTest::setTransformationRotateALot<Float>,
&TranslationRotationScalingTransformation2DTest::setTransformationRotateALot<Double>,
&TranslationRotationScalingTransformation2DTest::setTransformationReflection<Float>,
&TranslationRotationScalingTransformation2DTest::setTransformationReflection<Double>,
&TranslationRotationScalingTransformation2DTest::resetTransformation<Float>,
&TranslationRotationScalingTransformation2DTest::resetTransformation<Double>,
@ -169,6 +172,25 @@ template<class T> void TranslationRotationScalingTransformation2DTest::setTransf
Math::Matrix3<T>::scaling({T(1.5), T(0.5)}));
}
template<class T> void TranslationRotationScalingTransformation2DTest::setTransformationReflection() {
setTestCaseTemplateName(Math::TypeTraits<T>::name());
Object2D<T> o;
o.setTransformation(
Math::Matrix3<T>::translation({T(7.0), T(-1.0)})*
Math::Matrix3<T>::rotation(Math::Deg<T>{T(17.0)})*
Math::Matrix3<T>::scaling({T(-1.5), T(0.5)}));
CORRADE_COMPARE(o.translation(), (Math::Vector2<T>{T(7.0), T(-1.0)}));
/* The negative scaling should get properly extracted from the rotation
without getting lost */
CORRADE_COMPARE(o.rotation(), Math::Complex<T>::rotation(Math::Deg<T>{T(17.0)}));
CORRADE_COMPARE(o.scaling(), (Math::Vector2<T>{T(-1.5), T(0.5)}));
CORRADE_COMPARE(o.transformationMatrix(),
Math::Matrix3<T>::translation({T(7.0), T(-1.0)})*
Math::Matrix3<T>::rotation(Math::Deg<T>{T(17.0)})*
Math::Matrix3<T>::scaling({T(-1.5), T(0.5)}));
}
template<class T> void TranslationRotationScalingTransformation2DTest::resetTransformation() {
setTestCaseTemplateName(Math::TypeTraits<T>::name());

24
src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation3DTest.cpp

@ -42,6 +42,7 @@ struct TranslationRotationScalingTransformation3DTest: TestSuite::Tester {
template<class T> void defaults();
template<class T> void setTransformation();
template<class T> void setTransformationRotateALot();
template<class T> void setTransformationReflection();
template<class T> void resetTransformation();
template<class T> void translate();
@ -66,6 +67,8 @@ TranslationRotationScalingTransformation3DTest::TranslationRotationScalingTransf
&TranslationRotationScalingTransformation3DTest::setTransformation<Double>,
&TranslationRotationScalingTransformation3DTest::setTransformationRotateALot<Float>,
&TranslationRotationScalingTransformation3DTest::setTransformationRotateALot<Double>,
&TranslationRotationScalingTransformation3DTest::setTransformationReflection<Float>,
&TranslationRotationScalingTransformation3DTest::setTransformationReflection<Double>,
&TranslationRotationScalingTransformation3DTest::resetTransformation<Float>,
&TranslationRotationScalingTransformation3DTest::resetTransformation<Double>,
@ -169,6 +172,27 @@ template<class T> void TranslationRotationScalingTransformation3DTest::setTransf
Math::Matrix4<T>::scaling({T(1.5), T(0.5), T(3.0)}));
}
template<class T> void TranslationRotationScalingTransformation3DTest::setTransformationReflection() {
setTestCaseTemplateName(Math::TypeTraits<T>::name());
Object3D<T> o;
o.setTransformation(
Math::Matrix4<T>::translation({T(7.0), T(-1.0), T(2.2)})*
Math::Matrix4<T>::rotationX(Math::Deg<T>{T(17.0)})*
Math::Matrix4<T>::scaling({T(1.5), T(-0.5), T(3.0)}));
CORRADE_COMPARE(o.translation(), (Math::Vector3<T>{T(7.0), T(-1.0), T(2.2)}));
/* The negative scaling should get properly extracted from the rotation
without causing the rotation to go crazy. Well, some equivalent representation of it. */
CORRADE_COMPARE(o.rotation(), Math::Quaternion<T>::rotation(Math::Deg<T>{T(180.0)}, {T(0.0), T(-0.147809411129611), T(0.989015863361917)}));
CORRADE_COMPARE(o.scaling(), (Math::Vector3<T>{T(-1.5), T(0.5), T(3.0)}));
/* The combineúd matrix is however the same as if we'd have the Y axis
reflected */
CORRADE_COMPARE(o.transformationMatrix(),
Math::Matrix4<T>::translation({T(7.0), T(-1.0), T(2.2)})*
Math::Matrix4<T>::rotationX(Math::Deg<T>{T(17.0)})*
Math::Matrix4<T>::scaling({T(1.5), T(-0.5), T(3.0)}));
}
template<class T> void TranslationRotationScalingTransformation3DTest::resetTransformation() {
setTestCaseTemplateName(Math::TypeTraits<T>::name());

Loading…
Cancel
Save