Browse Source

Function for returning rotation and scaling part of Matrix4.

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

8
src/Math/Matrix4.h

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

17
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,

1
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();

Loading…
Cancel
Save