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 /tests/auto/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 'tests/auto/core')
-rw-r--r-- | tests/auto/core/qtransform/tst_qtransform.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/core/qtransform/tst_qtransform.cpp b/tests/auto/core/qtransform/tst_qtransform.cpp index f5527ebf5..dbdda1ce1 100644 --- a/tests/auto/core/qtransform/tst_qtransform.cpp +++ b/tests/auto/core/qtransform/tst_qtransform.cpp @@ -36,6 +36,15 @@ using namespace Qt3DCore; +class FakeTransform : public Qt3DCore::QTransform +{ +public: + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override + { + Qt3DCore::QTransform::sceneChangeEvent(change); + } +}; + class tst_QTransform : public QObject { Q_OBJECT @@ -49,6 +58,7 @@ private Q_SLOTS: // THEN QCOMPARE(transform.isShareable(), false); QCOMPARE(transform.matrix(), QMatrix4x4()); + QCOMPARE(transform.worldMatrix(), QMatrix4x4()); QCOMPARE(transform.scale(), 1.0f); QCOMPARE(transform.scale3D(), QVector3D(1.0f, 1.0f, 1.0f)); QCOMPARE(transform.rotation(), QQuaternion()); @@ -112,6 +122,7 @@ private Q_SLOTS: QCOMPARE(transform->translation(), cloneData.translation); QCOMPARE(transform->scale3D(), cloneData.scale); QCOMPARE(transform->rotation(), cloneData.rotation); + QCOMPARE(transform->worldMatrix(), QMatrix4x4()); } void checkPropertyUpdates() @@ -342,6 +353,44 @@ private Q_SLOTS: // Note: t.matrix() != t2.matrix() since different matrices // can result in the same scale, rotation, translation } + + void checkUpdateWorldTransform() + { + // GIVEN + TestArbiter arbiter; + FakeTransform t; + arbiter.setArbiterOnNode(&t); + + // WHEN + QSignalSpy spy(&t, SIGNAL(worldMatrixChanged(QMatrix4x4))); + + // THEN + QVERIFY(spy.isValid()); + + // WHEN + Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + valueChange->setPropertyName("worldMatrix"); + const QMatrix4x4 newValue(1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f); + valueChange->setValue(newValue); + t.sceneChangeEvent(valueChange); + + // THEN + QCOMPARE(spy.count(), 1); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(t.worldMatrix(), newValue); + + // WHEN + spy.clear(); + t.sceneChangeEvent(valueChange); + + // THEN + QCOMPARE(spy.count(), 0); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(t.worldMatrix(), newValue); + } }; QTEST_MAIN(tst_QTransform) |