diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2019-08-09 10:22:25 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2019-08-13 14:32:29 +0200 |
commit | 3cdd4e12eb25757bb5711977ecf7ede419c44dd1 (patch) | |
tree | a41b7df4003f4ed79c2afb838d275a4703778e78 /src/core | |
parent | bb5caa526c242e68ae9ba5cd64933f7f3dea1aef (diff) |
QTransform: add worldMatrix property
Will make it more convenient to retrieve the world transform of a given
QEntity as well as monitor it for changes without having to traverse the
parent hierarchy of QEntity/QTransform
[ChangeLog] Add worldMatrix property on QTransform
Change-Id: Ie9ffb70c03b365850ed08693df2746701ca9a1fb
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/transforms/qtransform.cpp | 66 | ||||
-rw-r--r-- | src/core/transforms/qtransform.h | 5 | ||||
-rw-r--r-- | src/core/transforms/qtransform_p.h | 2 |
3 files changed, 72 insertions, 1 deletions
diff --git a/src/core/transforms/qtransform.cpp b/src/core/transforms/qtransform.cpp index d0e2628f7..bedf108f2 100644 --- a/src/core/transforms/qtransform.cpp +++ b/src/core/transforms/qtransform.cpp @@ -135,6 +135,18 @@ QTransformPrivate::~QTransformPrivate() */ /*! + \qmlproperty matrix4x4 QTransform::worldMatrix + + Holds the world transformation matrix for the transform. This assumes the + Transform component is being referenced by an Entity. This makes it more + convenient to identify when an Entity part of a subtree has been + transformed in the world even though its local transformation might not + have changed. + + \since 5.14 + */ + +/*! \qmlmethod quaternion Transform::fromAxisAndAngle(vector3d axis, real angle) Creates a quaternion from \a axis and \a angle. Returns the resulting quaternion. @@ -222,6 +234,35 @@ QTransform::QTransform(QTransformPrivate &dd, QNode *parent) { } +/*! + \internal + */ +void QTransform::sceneChangeEvent(const QSceneChangePtr &change) +{ + switch (change->type()) { + case PropertyUpdated: { + Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change); + if (propertyChange->propertyName() == QByteArrayLiteral("worldMatrix")) { + const bool blocked = blockNotifications(true); + setWorldMatrix(propertyChange->value().value<QMatrix4x4>()); + blockNotifications(blocked); + } + break; + } + default: + break; + } +} + +void QTransform::setWorldMatrix(const QMatrix4x4 &worldMatrix) +{ + Q_D(QTransform); + if (d->m_worldMatrix == worldMatrix) + return; + d->m_worldMatrix = worldMatrix; + emit worldMatrixChanged(worldMatrix); +} + void QTransform::setMatrix(const QMatrix4x4 &m) { Q_D(QTransform); @@ -240,7 +281,6 @@ void QTransform::setMatrix(const QMatrix4x4 &m) emit scale3DChanged(s); emit rotationChanged(r); emit translationChanged(t); - const bool wasBlocked = blockNotifications(true); emit matrixChanged(); emit scaleChanged(d->m_scale.x()); @@ -330,6 +370,30 @@ QMatrix4x4 QTransform::matrix() const } /*! + \property QTransform::worldMatrix + + Holds the world transformation matrix for the transform. This assumes the + QTransform component is being referenced by a QEntity. This makes it more + convenient to identify when a QEntity part of a subtree has been + transformed in the world even though its local transformation might not + have changed. + + \since 5.14 + */ + +/*! + Returns the world transformation matrix associated to the QTransform when + referenced by a QEntity which may be part of a QEntity hierarchy. + + \since 5.14 + */ +QMatrix4x4 QTransform::worldMatrix() const +{ + Q_D(const QTransform); + return d->m_worldMatrix; +} + +/*! \property Qt3DCore::QTransform::rotationX Holds the x rotation of the transform as Euler angle. diff --git a/src/core/transforms/qtransform.h b/src/core/transforms/qtransform.h index a80385a1b..527760df7 100644 --- a/src/core/transforms/qtransform.h +++ b/src/core/transforms/qtransform.h @@ -61,6 +61,7 @@ class Q_3DCORESHARED_EXPORT QTransform : public QComponent Q_PROPERTY(float rotationX READ rotationX WRITE setRotationX NOTIFY rotationXChanged) Q_PROPERTY(float rotationY READ rotationY WRITE setRotationY NOTIFY rotationYChanged) Q_PROPERTY(float rotationZ READ rotationZ WRITE setRotationZ NOTIFY rotationZChanged) + Q_PROPERTY(QMatrix4x4 worldMatrix READ worldMatrix NOTIFY worldMatrixChanged REVISION 14) public: explicit QTransform(QNode *parent = nullptr); @@ -88,6 +89,7 @@ public: Q_INVOKABLE static QMatrix4x4 rotateFromAxes(const QVector3D &xAxis, const QVector3D &yAxis, const QVector3D &zAxis); QMatrix4x4 matrix() const; + QMatrix4x4 worldMatrix() const; float rotationX() const; float rotationY() const; @@ -113,9 +115,12 @@ Q_SIGNALS: void rotationXChanged(float rotationX); void rotationYChanged(float rotationY); void rotationZChanged(float rotationZ); + void worldMatrixChanged(const QMatrix4x4 &worldMatrix); protected: explicit QTransform(QTransformPrivate &dd, QNode *parent = nullptr); + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override; + void setWorldMatrix(const QMatrix4x4 &worldMatrix); private: Q_DECLARE_PRIVATE(QTransform) diff --git a/src/core/transforms/qtransform_p.h b/src/core/transforms/qtransform_p.h index 89bc55491..d44e5e157 100644 --- a/src/core/transforms/qtransform_p.h +++ b/src/core/transforms/qtransform_p.h @@ -75,6 +75,8 @@ public: mutable QMatrix4x4 m_matrix; mutable bool m_matrixDirty; + + QMatrix4x4 m_worldMatrix; }; struct QTransformData |