diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-11-04 20:42:58 +0000 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2015-11-17 19:41:15 +0000 |
commit | ace675a084ab944a245500b9f54be653126c3147 (patch) | |
tree | 583e228b207b7cd7c7e63c38bcfe57fc7b5419ec /src/core/transforms/qtransform.cpp | |
parent | 77164ead9970263a65aac4689f14dcbbc10b3246 (diff) |
Setting matrix property to decompose to S, R, T
Updating the matrix property now decomposes the matrix to
calculate the scale, rotation and translation properties that
get sent to the backend.
The test example will be updated to show how to build a matrix
from a series of "sub transformations" in an imperative way. This
will reinforce in the API the fact that we can't decompose an
affine transform into an arbitrary set of sub transforms. That is
the API will emphasise the one way nature.
The decomposition functions were provided by Konstantin Ritt.
Note: mouse picking unit tests skipped for now
Change-Id: Ibc259dacac7a3dc32f4b03b375607291d998601c
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core/transforms/qtransform.cpp')
-rw-r--r-- | src/core/transforms/qtransform.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/core/transforms/qtransform.cpp b/src/core/transforms/qtransform.cpp index aeb9a57f7..0ca9f61de 100644 --- a/src/core/transforms/qtransform.cpp +++ b/src/core/transforms/qtransform.cpp @@ -37,6 +37,7 @@ #include "qtransform.h" #include "qtransform_p.h" #include "qabstracttransform_p.h" +#include "qmath3d_p.h" #include <Qt3DCore/qscenepropertychange.h> @@ -155,12 +156,36 @@ void QTransform::removeTransform(QAbstractTransform *transform) d->_q_update(); } +void QTransform::setMatrix(const QMatrix4x4 &m) +{ + Q_D(QTransform); + if (m != matrix()) { + d->m_matrix = m; + d->m_matrixDirty = false; + + QVector3D s; + QVector3D t; + QQuaternion r; + decomposeQMatrix4x4(m, t, r, s); + d->m_scale = s; + d->m_rotation = r; + d->m_translation = t; + emit scale3DChanged(); + emit rotationChanged(); + emit translationChanged(); + + const bool wasBlocked = blockNotifications(true); + emit matrixChanged(); + blockNotifications(wasBlocked); + } +} + QMatrix4x4 QTransform::matrix() const { Q_D(const QTransform); - if (d->m_transformsDirty) { - d->m_matrix = d->applyTransforms(); - d->m_transformsDirty = false; + if (d->m_matrixDirty) { + composeQMatrix4x4(d->m_translation, d->m_rotation, d->m_scale, d->m_matrix); + d->m_matrixDirty = false; } return d->m_matrix; } |