summaryrefslogtreecommitdiffstats
path: root/src/core/transforms/qmath3d_p.h
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-08-06 18:58:46 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-08-16 13:19:23 +0000
commit5c6634f2d1cd9a016142c3641ab6d797f5fe4ba7 (patch)
treeccbad78b2839b26b1f10cf5aa112786df56bd018 /src/core/transforms/qmath3d_p.h
parentb236f982170779a1836f7d391428287921422163 (diff)
Update skinned mesh example to expose joints of object
To do this we add a helper Sqt struct that wraps up an affine transformation as a scale vector, rotation quaternion and a translation vector. This is the format in which the animation aspect will animate the joints later so it's easier to keep the transforms split like this. It's also less data to move around compared with a 4x4 matrix (10 vs 16 floats, 12 including the padding). Change-Id: Iaa30b5ef5d1635cc208ead918827140cf2765908 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core/transforms/qmath3d_p.h')
-rw-r--r--src/core/transforms/qmath3d_p.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/transforms/qmath3d_p.h b/src/core/transforms/qmath3d_p.h
index 8c2afac31..a4f33f0b6 100644
--- a/src/core/transforms/qmath3d_p.h
+++ b/src/core/transforms/qmath3d_p.h
@@ -53,6 +53,7 @@
#include <QtGui/qmatrix4x4.h>
#include <QtGui/qquaternion.h>
#include <QtGui/qvector3d.h>
+#include <Qt3DCore/private/sqt_p.h>
#include <cmath>
@@ -189,6 +190,24 @@ inline void decomposeQMatrix4x4(const QMatrix4x4 &m, QVector3D &position, QQuate
position = QVector3D(m(0, 3), m(1, 3), m(2, 3));
}
+inline void decomposeQMatrix4x4(const QMatrix4x4 &m, Qt3DCore::Sqt &sqt)
+{
+ Q_ASSERT(m.isAffine());
+
+ const QMatrix3x3 m3x3(m.toGenericMatrix<3, 3>());
+
+ QMatrix3x3 rot3x3(Qt::Uninitialized);
+ if (hasScale(m)) {
+ decomposeQMatrix3x3(m3x3, rot3x3, sqt.scale, sqt.translation);
+ } else {
+ // we know there is no scaling part; no need for QDU decomposition
+ sqt.scale = QVector3D(1.0f, 1.0f, 1.0f);
+ rot3x3 = m3x3;
+ }
+ sqt.rotation = QQuaternion::fromRotationMatrix(rot3x3);
+ sqt.translation = QVector3D(m(0, 3), m(1, 3), m(2, 3));
+}
+
QT_END_NAMESPACE
#endif // QT3DCORE_QMATH3D_P_H