summaryrefslogtreecommitdiffstats
path: root/tests/auto/math3d
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-04-15 22:33:32 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-04-15 22:33:32 (GMT)
commit1cb11b428ef1bee070af72676b7eb1fa325bb980 (patch)
treef098bff499691223ba9255a8e0500314cae20e6e /tests/auto/math3d
parent10688c0168fc010671abc59f367c19357bb6776c (diff)
downloadQt-1cb11b428ef1bee070af72676b7eb1fa325bb980.zip
Qt-1cb11b428ef1bee070af72676b7eb1fa325bb980.tar.gz
Qt-1cb11b428ef1bee070af72676b7eb1fa325bb980.tar.bz2
Add the QQuaternion::nlerp() function as a counterpart to slerp()
nlerp() implements "normalized linear interpolation", which is faster than slerp() and gives approximate results that are good enough for some applications. Reviewed-by: trustme
Diffstat (limited to 'tests/auto/math3d')
-rw-r--r--tests/auto/math3d/qquaternion/tst_qquaternion.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/math3d/qquaternion/tst_qquaternion.cpp
index 6a69755..f25f858 100644
--- a/tests/auto/math3d/qquaternion/tst_qquaternion.cpp
+++ b/tests/auto/math3d/qquaternion/tst_qquaternion.cpp
@@ -90,6 +90,9 @@ private slots:
void slerp_data();
void slerp();
+
+ void nlerp_data();
+ void nlerp();
};
// qFuzzyCompare isn't quite "fuzzy" enough to handle conversion
@@ -768,6 +771,60 @@ void tst_QQuaternion::slerp()
QVERIFY(fuzzyCompare(result.scalar(), q3.scalar()));
}
+// Test normalized linear interpolation of quaternions.
+void tst_QQuaternion::nlerp_data()
+{
+ slerp_data();
+}
+void tst_QQuaternion::nlerp()
+{
+ QFETCH(qreal, x1);
+ QFETCH(qreal, y1);
+ QFETCH(qreal, z1);
+ QFETCH(qreal, angle1);
+ QFETCH(qreal, x2);
+ QFETCH(qreal, y2);
+ QFETCH(qreal, z2);
+ QFETCH(qreal, angle2);
+ QFETCH(qreal, t);
+
+ QQuaternion q1 = QQuaternion::fromAxisAndAngle(x1, y1, z1, angle1);
+ QQuaternion q2 = QQuaternion::fromAxisAndAngle(x2, y2, z2, angle2);
+
+ QQuaternion result = QQuaternion::nlerp(q1, q2, t);
+
+ qreal resultx, resulty, resultz, resultscalar;
+ if (t <= 0.0f) {
+ resultx = q1.x();
+ resulty = q1.y();
+ resultz = q1.z();
+ resultscalar = q1.scalar();
+ } else if (t >= 1.0f) {
+ resultx = q2.x();
+ resulty = q2.y();
+ resultz = q2.z();
+ resultscalar = q2.scalar();
+ } else if (qAbs(angle1 - angle2) <= 180.f) {
+ resultx = q1.x() * (1 - t) + q2.x() * t;
+ resulty = q1.y() * (1 - t) + q2.y() * t;
+ resultz = q1.z() * (1 - t) + q2.z() * t;
+ resultscalar = q1.scalar() * (1 - t) + q2.scalar() * t;
+ } else {
+ // Angle greater than 180 degrees: negate q2.
+ resultx = q1.x() * (1 - t) - q2.x() * t;
+ resulty = q1.y() * (1 - t) - q2.y() * t;
+ resultz = q1.z() * (1 - t) - q2.z() * t;
+ resultscalar = q1.scalar() * (1 - t) - q2.scalar() * t;
+ }
+
+ QQuaternion q3 = QQuaternion(resultscalar, resultx, resulty, resultz).normalized();
+
+ QVERIFY(fuzzyCompare(result.x(), q3.x()));
+ QVERIFY(fuzzyCompare(result.y(), q3.y()));
+ QVERIFY(fuzzyCompare(result.z(), q3.z()));
+ QVERIFY(fuzzyCompare(result.scalar(), q3.scalar()));
+}
+
QTEST_APPLESS_MAIN(tst_QQuaternion)
#include "tst_qquaternion.moc"