Browse Source

Math: expect fail on non-uniform scaling in Matrix*::rotation().

Not implemented yet, added TODO.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
fab0aa1544
  1. 3
      src/Math/Matrix3.h
  2. 3
      src/Math/Matrix4.h
  3. 28
      src/Math/Test/Matrix3Test.cpp
  4. 32
      src/Math/Test/Matrix4Test.cpp

3
src/Math/Matrix3.h

@ -157,12 +157,15 @@ template<class T> class Matrix3: public Matrix<3, T> {
*
* Normalized upper-left 2x2 part of the matrix.
* @see rotationScaling() const, rotation(T), Matrix4::rotation() const
* @todo assert uniform scaling (otherwise this would be garbage)
*/
inline Matrix<2, T> rotation() const {
return {(*this)[0].xy().normalized(),
(*this)[1].xy().normalized()};
}
/** @todo uniform scaling extraction */
/**
* @brief Right-pointing 2D vector
*

3
src/Math/Matrix4.h

@ -293,6 +293,7 @@ template<class T> class Matrix4: public Matrix<4, T> {
* Normalized upper-left 3x3 part of the matrix.
* @see rotationScaling() const, rotation(T, const Vector3&),
* Matrix3::rotation() const
* @todo assert uniform scaling (otherwise this would be garbage)
*/
inline Matrix<3, T> rotation() const {
/* Not Matrix3, because it is for affine 2D transformations */
@ -301,6 +302,8 @@ template<class T> class Matrix4: public Matrix<4, T> {
(*this)[2].xyz().normalized()};
}
/** @todo uniform scaling extraction */
/**
* @brief Right-pointing 3D vector
*

28
src/Math/Test/Matrix3Test.cpp

@ -161,14 +161,32 @@ void Matrix3Test::rotationScalingPart() {
}
void Matrix3Test::rotationPart() {
Matrix3 rotation = Matrix3::rotation(Deg(15.0f));
Matrix2 expectedRotationPart(Vector2( 0.965926f, 0.258819f),
Vector2(-0.258819f, 0.965926f));
Matrix3 rotation = Matrix3::rotation(Deg(15.0f));
CORRADE_COMPARE(rotation.rotation(), expectedRotationPart);
Matrix3 rotationTransformed = Matrix3::translation({2.0f, 5.0f})*rotation*Matrix3::scaling(Vector2(9.0f));
CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart);
/* For rotation and translation this is the same as rotationScaling() */
Matrix3 rotationTranslation = rotation*Matrix3::translation({2.0f, 5.0f});
Matrix2 rotationTranslationPart = rotationTranslation.rotation();
CORRADE_COMPARE(rotationTranslationPart, rotationTranslation.rotationScaling());
CORRADE_COMPARE(rotationTranslationPart, expectedRotationPart);
/* Test uniform scaling */
Matrix3 rotationScaling = rotation*Matrix3::scaling(Vector2(9.0f));
Matrix2 rotationScalingPart = rotationScaling.rotation();
CORRADE_COMPARE(rotationScalingPart.determinant(), 1.0f);
CORRADE_COMPARE(rotationScalingPart*rotationScalingPart.transposed(), Matrix2());
CORRADE_COMPARE(rotationScalingPart, expectedRotationPart);
/* Fails on non-uniform scaling */
{
CORRADE_EXPECT_FAIL("Assertion on uniform scaling is not implemented yet.");
std::ostringstream o;
Error::setOutput(&o);
Matrix3 rotationScaling2 = rotation*Matrix3::scaling(Vector2::yScale(3.5f));
CORRADE_COMPARE(o.str(), "Math::Matrix3::rotation(): the matrix doesn't have uniform scaling\n");
CORRADE_COMPARE(rotationScaling2, Matrix3(Matrix3::Zero));
}
}
void Matrix3Test::vectorParts() {

32
src/Math/Test/Matrix4Test.cpp

@ -228,19 +228,33 @@ void Matrix4Test::rotationScalingPart() {
}
void Matrix4Test::rotationPart() {
Matrix4 rotation = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized());
Matrix3 expectedRotationPart(Vector3( 0.35612214f, -0.80181062f, 0.47987163f),
Vector3( 0.47987163f, 0.59757638f, 0.6423595f),
Vector3(-0.80181062f, 0.0015183985f, 0.59757638f));
Matrix4 rotation = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized());
CORRADE_COMPARE(rotation.rotation().determinant(), 1.0f);
CORRADE_COMPARE(rotation.rotation()*rotation.rotation().transposed(), Matrix3());
CORRADE_COMPARE(rotation.rotation(), expectedRotationPart);
Matrix4 rotationTransformed = Matrix4::translation({2.0f, 5.0f, -3.0f})*rotation*Matrix4::scaling(Vector3(9.0f));
CORRADE_COMPARE(rotationTransformed.rotation().determinant(), 1.0f);
CORRADE_COMPARE(rotationTransformed.rotation()*rotationTransformed.rotation().transposed(), Matrix3());
CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart);
/* For rotation and translation this is the same as rotationScaling() */
Matrix4 rotationTranslation = rotation*Matrix4::translation({2.0f, 5.0f, -3.0f});
Matrix3 rotationTranslationPart = rotationTranslation.rotation();
CORRADE_COMPARE(rotationTranslationPart, rotationTranslation.rotationScaling());
CORRADE_COMPARE(rotationTranslationPart, expectedRotationPart);
/* Test uniform scaling */
Matrix4 rotationScaling = rotation*Matrix4::scaling(Vector3(9.0f));
Matrix3 rotationScalingPart = rotationScaling.rotation();
CORRADE_COMPARE(rotationScalingPart.determinant(), 1.0f);
CORRADE_COMPARE(rotationScalingPart*rotationScalingPart.transposed(), Matrix3());
CORRADE_COMPARE(rotationScalingPart, expectedRotationPart);
/* Fails on non-uniform scaling */
{
CORRADE_EXPECT_FAIL("Assertion on uniform scaling is not implemented yet.");
std::ostringstream o;
Error::setOutput(&o);
Matrix4 rotationScaling2 = rotation*Matrix4::scaling(Vector3::yScale(3.5f));
CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): the matrix doesn't have uniform scaling\n");
CORRADE_COMPARE(rotationScaling2, Matrix4(Matrix4::Zero));
}
}
void Matrix4Test::vectorParts() {

Loading…
Cancel
Save