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/transforms/qtransform.cpp | |
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/transforms/qtransform.cpp')
-rw-r--r-- | src/core/transforms/qtransform.cpp | 66 |
1 files changed, 65 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. |