diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-09-22 10:55:02 +1000 |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-09-22 10:55:02 +1000 |
commit | 8416ae1af3f13ad865b25a87e3e94e298b3a0ca2 (patch) | |
tree | 21fd4e9e878792bbc1ba8694aa404e428e98667e /tests/auto/qmatrixnxn | |
parent | 40bdb6a5bed66385c3c2320447b1530e99befeb3 (diff) | |
download | qt4-tools-8416ae1af3f13ad865b25a87e3e94e298b3a0ca2.tar.gz |
QMatrix4x4::mapVector() to transform by top-left 3x3
It is useful to be able to map direction vectors by the top-left
3x3 component of a 4x4 matrix, ignoring the translation and
projection components.
Reviewed-by: Sarah Smith
Diffstat (limited to 'tests/auto/qmatrixnxn')
-rw-r--r-- | tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp index 90db496a90..ff5e00f084 100644 --- a/tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp +++ b/tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp @@ -170,6 +170,9 @@ private slots: void mapRect_data(); void mapRect(); + void mapVector_data(); + void mapVector(); + void properties(); void metaTypes(); @@ -3317,6 +3320,64 @@ void tst_QMatrixNxN::mapRect() QVERIFY(mri == tri); } +void tst_QMatrixNxN::mapVector_data() +{ + QTest::addColumn<void *>("mValues"); + + QTest::newRow("null") + << (void *)nullValues4; + + QTest::newRow("identity") + << (void *)identityValues4; + + QTest::newRow("unique") + << (void *)uniqueValues4; + + static const qreal scale[] = + {2.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 11.0f, 0.0f, 0.0f, + 0.0f, 0.0f, -6.5f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; + QTest::newRow("scale") + << (void *)scale; + + static const qreal scaleTranslate[] = + {2.0f, 0.0f, 0.0f, 1.0f, + 0.0f, 11.0f, 0.0f, 2.0f, + 0.0f, 0.0f, -6.5f, 3.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; + QTest::newRow("scaleTranslate") + << (void *)scaleTranslate; + + static const qreal translate[] = + {1.0f, 0.0f, 0.0f, 1.0f, + 0.0f, 1.0f, 0.0f, 2.0f, + 0.0f, 0.0f, 1.0f, 3.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; + QTest::newRow("translate") + << (void *)translate; +} +void tst_QMatrixNxN::mapVector() +{ + QFETCH(void *, mValues); + + QMatrix4x4 m1((const qreal *)mValues); + m1.inferSpecialType(); + + QVector3D v(3.5f, -1.0f, 2.5f); + + QVector3D expected + (v.x() * m1(0, 0) + v.y() * m1(0, 1) + v.z() * m1(0, 2), + v.x() * m1(1, 0) + v.y() * m1(1, 1) + v.z() * m1(1, 2), + v.x() * m1(2, 0) + v.y() * m1(2, 1) + v.z() * m1(2, 2)); + + QVector3D actual = m1.mapVector(v); + + QVERIFY(fuzzyCompare(actual.x(), expected.x())); + QVERIFY(fuzzyCompare(actual.y(), expected.y())); + QVERIFY(fuzzyCompare(actual.z(), expected.z())); +} + class tst_QMatrixNxN4x4Properties : public QObject { Q_OBJECT |