Browse Source

Function for getting rotation part of Matrix4.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
071180ebcd
  1. 8
      src/Math/Matrix4.h
  2. 15
      src/Math/Test/Matrix4Test.cpp
  3. 1
      src/Math/Test/Matrix4Test.h

8
src/Math/Matrix4.h

@ -158,6 +158,14 @@ template<class T> class Matrix4: public Matrix<T, 4> {
/** @copydoc Matrix::inversed() */
inline Matrix4<T> inversed() const { return Matrix<T, 4>::inversed(); }
/** @brief Rotation part of the matrix */
inline Matrix3<T> rotation() const {
return Matrix3<T>::from(
(*this)[0].xyz().normalized(),
(*this)[1].xyz().normalized(),
(*this)[2].xyz().normalized());
}
};
#ifndef DOXYGEN_GENERATING_OUTPUT

15
src/Math/Test/Matrix4Test.cpp

@ -29,6 +29,7 @@ using namespace Corrade::Utility;
namespace Magnum { namespace Math { namespace Test {
typedef Math::Matrix4<float> Matrix4;
typedef Math::Matrix3<float> Matrix3;
void Matrix4Test::translation() {
Matrix4 matrix(
@ -63,6 +64,20 @@ void Matrix4Test::rotation() {
QVERIFY(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}) == matrix);
}
void Matrix4Test::rotationPart() {
Matrix3 expectedRotationPart(
0.35612214f, -0.80181062f, 0.47987163f,
0.47987163f, 0.59757638f, 0.6423595f,
-0.80181062f, 0.0015183985f, 0.59757638f
);
Matrix4 rotation = Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f});
QVERIFY(rotation.rotation() == expectedRotationPart);
Matrix4 rotationTransformed = Matrix4::translation({2.0f, 5.0f, -3.0f})*rotation*Matrix4::scaling(Vector3<float>(9.0f));
QVERIFY(rotationTransformed.rotation() == expectedRotationPart);
}
void Matrix4Test::debug() {
Matrix4 m(
3.0f, 5.0f, 8.0f, 4.0f,

1
src/Math/Test/Matrix4Test.h

@ -26,6 +26,7 @@ class Matrix4Test: public QObject {
void translation();
void scaling();
void rotation();
void rotationPart();
void debug();
};

Loading…
Cancel
Save