253 else |
255 else |
254 expected.rotate(angle, axis); |
256 expected.rotate(angle, axis); |
255 |
257 |
256 QVERIFY(fuzzyCompare(transform2D(rotation), expected)); |
258 QVERIFY(fuzzyCompare(transform2D(rotation), expected)); |
257 |
259 |
|
260 // Check that "rotation" produces the 4x4 form of the 3x3 matrix. |
|
261 // i.e. third row and column are 0 0 1 0. |
|
262 t.setToIdentity(); |
|
263 rotation.applyTo(&t); |
|
264 QMatrix4x4 r(expected); |
|
265 if (sizeof(qreal) == sizeof(float) && angle == 268) { |
|
266 // This test fails, on only this angle, when qreal == float |
|
267 // because the deg2rad value in QTransform is not accurate |
|
268 // enough to match what QMatrix4x4 is doing. |
|
269 } else { |
|
270 QVERIFY(qFuzzyCompare(t, r)); |
|
271 } |
|
272 |
258 //now let's check that a null vector will not change the transform |
273 //now let's check that a null vector will not change the transform |
259 rotation.setAxis(QVector3D(0, 0, 0)); |
274 rotation.setAxis(QVector3D(0, 0, 0)); |
260 rotation.setOrigin(QVector3D(10, 10, 0)); |
275 rotation.setOrigin(QVector3D(10, 10, 0)); |
261 |
276 |
262 t.setIdentity(); |
277 t.setToIdentity(); |
263 rotation.applyTo(&t); |
278 rotation.applyTo(&t); |
264 |
279 |
265 QVERIFY(t.isIdentity()); |
280 QVERIFY(t.isIdentity()); |
266 QVERIFY(transform2D(rotation).isIdentity()); |
281 QVERIFY(transform2D(rotation).isIdentity()); |
267 |
282 |
272 |
287 |
273 rotation.setOrigin(QVector3D(0, 0, 0)); |
288 rotation.setOrigin(QVector3D(0, 0, 0)); |
274 |
289 |
275 QVERIFY(t.isIdentity()); |
290 QVERIFY(t.isIdentity()); |
276 QVERIFY(transform2D(rotation).isIdentity()); |
291 QVERIFY(transform2D(rotation).isIdentity()); |
|
292 } |
|
293 |
|
294 void tst_QGraphicsTransform::rotation3dArbitraryAxis_data() |
|
295 { |
|
296 QTest::addColumn<QVector3D>("axis"); |
|
297 QTest::addColumn<qreal>("angle"); |
|
298 |
|
299 QVector3D axis1 = QVector3D(1.0f, 1.0f, 1.0f); |
|
300 QVector3D axis2 = QVector3D(2.0f, -3.0f, 0.5f); |
|
301 QVector3D axis3 = QVector3D(-2.0f, 0.0f, -0.5f); |
|
302 QVector3D axis4 = QVector3D(0.0001f, 0.0001f, 0.0001f); |
|
303 QVector3D axis5 = QVector3D(0.01f, 0.01f, 0.01f); |
|
304 |
|
305 for (int angle = 0; angle <= 360; angle++) { |
|
306 QTest::newRow("test rotation on (1, 1, 1)") << axis1 << qreal(angle); |
|
307 QTest::newRow("test rotation on (2, -3, .5)") << axis2 << qreal(angle); |
|
308 QTest::newRow("test rotation on (-2, 0, -.5)") << axis3 << qreal(angle); |
|
309 QTest::newRow("test rotation on (.0001, .0001, .0001)") << axis4 << qreal(angle); |
|
310 QTest::newRow("test rotation on (.01, .01, .01)") << axis5 << qreal(angle); |
|
311 } |
|
312 } |
|
313 |
|
314 void tst_QGraphicsTransform::rotation3dArbitraryAxis() |
|
315 { |
|
316 QFETCH(QVector3D, axis); |
|
317 QFETCH(qreal, angle); |
|
318 |
|
319 QGraphicsRotation rotation; |
|
320 rotation.setAxis(axis); |
|
321 |
|
322 QMatrix4x4 t; |
|
323 rotation.applyTo(&t); |
|
324 |
|
325 QVERIFY(t.isIdentity()); |
|
326 QVERIFY(transform2D(rotation).isIdentity()); |
|
327 |
|
328 rotation.setAngle(angle); |
|
329 |
|
330 // Compute the expected answer using QMatrix4x4 and a projection. |
|
331 // These two steps are performed in one hit by QGraphicsRotation. |
|
332 QMatrix4x4 exp; |
|
333 exp.rotate(angle, axis); |
|
334 QTransform expected = exp.toTransform(1024.0f); |
|
335 |
|
336 QVERIFY(fuzzyCompare(transform2D(rotation), expected)); |
|
337 |
|
338 // Check that "rotation" produces the 4x4 form of the 3x3 matrix. |
|
339 // i.e. third row and column are 0 0 1 0. |
|
340 t.setToIdentity(); |
|
341 rotation.applyTo(&t); |
|
342 QMatrix4x4 r(expected); |
|
343 QVERIFY(qFuzzyCompare(t, r)); |
277 } |
344 } |
278 |
345 |
279 |
346 |
280 QTEST_MAIN(tst_QGraphicsTransform) |
347 QTEST_MAIN(tst_QGraphicsTransform) |
281 #include "tst_qgraphicstransform.moc" |
348 #include "tst_qgraphicstransform.moc" |