From aec8ef98dd6379af03ee7bdf46a80f504ae0e289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 23 Apr 2012 00:09:41 +0200 Subject: [PATCH] Function for returning rotation and scaling part of Matrix4. --- src/Math/Matrix4.h | 8 ++++++++ src/Math/Test/Matrix4Test.cpp | 17 +++++++++++++++++ src/Math/Test/Matrix4Test.h | 1 + 3 files changed, 26 insertions(+) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 08cde955b..a5d8eb4ed 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -169,6 +169,14 @@ template class Matrix4: public Matrix { /** @copydoc Matrix::inverted() */ inline Matrix4 inverted() const { return Matrix::inverted(); } + /** @brief Rotation and scaling part of the matrix */ + inline Matrix3 rotationScaling() const { + return Matrix3::from( + (*this)[0].xyz(), + (*this)[1].xyz(), + (*this)[2].xyz()); + } + /** @brief Rotation part of the matrix */ inline Matrix3 rotation() const { return Matrix3::from( diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index ecbac538f..a93036b31 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -88,6 +88,23 @@ void Matrix4Test::rotation() { QVERIFY(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}) == matrix); } +void Matrix4Test::rotationScalingPart() { + Matrix4 m( + 3.0f, 5.0f, 8.0f, 4.0f, + 4.0f, 4.0f, 7.0f, 3.0f, + 7.0f, -1.0f, 8.0f, 0.0f, + 9.0f, 4.0f, 5.0f, 9.0f + ); + + Matrix3 expected( + 3.0f, 5.0f, 8.0f, + 4.0f, 4.0f, 7.0f, + 7.0f, -1.0f, 8.0f + ); + + QVERIFY(m.rotationScaling() == expected); +} + void Matrix4Test::rotationPart() { Matrix3 expectedRotationPart( 0.35612214f, -0.80181062f, 0.47987163f, diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h index 857ace581..026533dba 100644 --- a/src/Math/Test/Matrix4Test.h +++ b/src/Math/Test/Matrix4Test.h @@ -28,6 +28,7 @@ class Matrix4Test: public QObject { void translation(); void scaling(); void rotation(); + void rotationScalingPart(); void rotationPart(); void debug();