author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtOpenGL module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtTest/QtTest> |
|
43 |
#include <QtGui/qmatrix4x4.h> |
|
44 |
||
45 |
class tst_QMatrix4x4 : public QObject |
|
46 |
{ |
|
47 |
Q_OBJECT |
|
48 |
public: |
|
49 |
tst_QMatrix4x4() {} |
|
50 |
~tst_QMatrix4x4() {} |
|
51 |
||
52 |
private slots: |
|
53 |
void multiply_data(); |
|
54 |
void multiply(); |
|
55 |
||
56 |
void multiplyInPlace_data(); |
|
57 |
void multiplyInPlace(); |
|
58 |
||
59 |
void multiplyDirect_data(); |
|
60 |
void multiplyDirect(); |
|
61 |
||
62 |
void mapVector3D_data(); |
|
63 |
void mapVector3D(); |
|
64 |
||
65 |
void mapVector2D_data(); |
|
66 |
void mapVector2D(); |
|
67 |
||
68 |
void mapVectorDirect_data(); |
|
69 |
void mapVectorDirect(); |
|
70 |
||
71 |
void compareTranslate_data(); |
|
72 |
void compareTranslate(); |
|
73 |
||
74 |
void compareTranslateAfterScale_data(); |
|
75 |
void compareTranslateAfterScale(); |
|
76 |
||
77 |
void compareTranslateAfterRotate_data(); |
|
78 |
void compareTranslateAfterRotate(); |
|
79 |
||
80 |
void compareScale_data(); |
|
81 |
void compareScale(); |
|
82 |
||
83 |
void compareScaleAfterTranslate_data(); |
|
84 |
void compareScaleAfterTranslate(); |
|
85 |
||
86 |
void compareScaleAfterRotate_data(); |
|
87 |
void compareScaleAfterRotate(); |
|
88 |
||
89 |
void compareRotate_data(); |
|
90 |
void compareRotate(); |
|
91 |
||
92 |
void compareRotateAfterTranslate_data(); |
|
93 |
void compareRotateAfterTranslate(); |
|
94 |
||
95 |
void compareRotateAfterScale_data(); |
|
96 |
void compareRotateAfterScale(); |
|
97 |
}; |
|
98 |
||
99 |
static qreal const generalValues[16] = |
|
100 |
{1.0f, 2.0f, 3.0f, 4.0f, |
|
101 |
5.0f, 6.0f, 7.0f, 8.0f, |
|
102 |
9.0f, 10.0f, 11.0f, 12.0f, |
|
103 |
13.0f, 14.0f, 15.0f, 16.0f}; |
|
104 |
||
105 |
void tst_QMatrix4x4::multiply_data() |
|
106 |
{ |
|
107 |
QTest::addColumn<QMatrix4x4>("m1"); |
|
108 |
QTest::addColumn<QMatrix4x4>("m2"); |
|
109 |
||
110 |
QTest::newRow("identity * identity") |
|
111 |
<< QMatrix4x4() << QMatrix4x4(); |
|
112 |
QTest::newRow("identity * general") |
|
113 |
<< QMatrix4x4() << QMatrix4x4(generalValues); |
|
114 |
QTest::newRow("general * identity") |
|
115 |
<< QMatrix4x4(generalValues) << QMatrix4x4(); |
|
116 |
QTest::newRow("general * general") |
|
117 |
<< QMatrix4x4(generalValues) << QMatrix4x4(generalValues); |
|
118 |
} |
|
119 |
||
120 |
QMatrix4x4 mresult; |
|
121 |
||
122 |
void tst_QMatrix4x4::multiply() |
|
123 |
{ |
|
124 |
QFETCH(QMatrix4x4, m1); |
|
125 |
QFETCH(QMatrix4x4, m2); |
|
126 |
||
127 |
QMatrix4x4 m3; |
|
128 |
||
129 |
QBENCHMARK { |
|
130 |
m3 = m1 * m2; |
|
131 |
} |
|
132 |
||
133 |
// Force the result to be stored so the compiler doesn't |
|
134 |
// optimize away the contents of the benchmark loop. |
|
135 |
mresult = m3; |
|
136 |
} |
|
137 |
||
138 |
void tst_QMatrix4x4::multiplyInPlace_data() |
|
139 |
{ |
|
140 |
multiply_data(); |
|
141 |
} |
|
142 |
||
143 |
void tst_QMatrix4x4::multiplyInPlace() |
|
144 |
{ |
|
145 |
QFETCH(QMatrix4x4, m1); |
|
146 |
QFETCH(QMatrix4x4, m2); |
|
147 |
||
148 |
QMatrix4x4 m3; |
|
149 |
||
150 |
QBENCHMARK { |
|
151 |
m3 = m1; |
|
152 |
m3 *= m2; |
|
153 |
} |
|
154 |
||
155 |
// Force the result to be stored so the compiler doesn't |
|
156 |
// optimize away the contents of the benchmark loop. |
|
157 |
mresult = m3; |
|
158 |
} |
|
159 |
||
160 |
// Use a direct naive multiplication algorithm. This is used |
|
161 |
// to compare against the optimized routines to see if they are |
|
162 |
// actually faster than the naive implementation. |
|
163 |
void tst_QMatrix4x4::multiplyDirect_data() |
|
164 |
{ |
|
165 |
multiply_data(); |
|
166 |
} |
|
167 |
void tst_QMatrix4x4::multiplyDirect() |
|
168 |
{ |
|
169 |
QFETCH(QMatrix4x4, m1); |
|
170 |
QFETCH(QMatrix4x4, m2); |
|
171 |
||
172 |
QMatrix4x4 m3; |
|
173 |
||
174 |
const qreal *m1data = m1.constData(); |
|
175 |
const qreal *m2data = m2.constData(); |
|
176 |
qreal *m3data = m3.data(); |
|
177 |
||
178 |
QBENCHMARK { |
|
179 |
for (int row = 0; row < 4; ++row) { |
|
180 |
for (int col = 0; col < 4; ++col) { |
|
181 |
m3data[col * 4 + row] = 0.0f; |
|
182 |
for (int j = 0; j < 4; ++j) { |
|
183 |
m3data[col * 4 + row] += |
|
184 |
m1data[j * 4 + row] * m2data[col * 4 + j]; |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
QVector3D vresult; |
|
192 |
||
193 |
void tst_QMatrix4x4::mapVector3D_data() |
|
194 |
{ |
|
195 |
QTest::addColumn<QMatrix4x4>("m1"); |
|
196 |
||
197 |
QTest::newRow("identity") << QMatrix4x4(); |
|
198 |
QTest::newRow("general") << QMatrix4x4(generalValues); |
|
199 |
||
200 |
QMatrix4x4 t1; |
|
201 |
t1.translate(-100.5f, 64.0f, 75.25f); |
|
202 |
QTest::newRow("translate3D") << t1; |
|
203 |
||
204 |
QMatrix4x4 t2; |
|
205 |
t2.translate(-100.5f, 64.0f); |
|
206 |
QTest::newRow("translate2D") << t2; |
|
207 |
||
208 |
QMatrix4x4 s1; |
|
209 |
s1.scale(-100.5f, 64.0f, 75.25f); |
|
210 |
QTest::newRow("scale3D") << s1; |
|
211 |
||
212 |
QMatrix4x4 s2; |
|
213 |
s2.scale(-100.5f, 64.0f); |
|
214 |
QTest::newRow("scale2D") << s2; |
|
215 |
} |
|
216 |
void tst_QMatrix4x4::mapVector3D() |
|
217 |
{ |
|
218 |
QFETCH(QMatrix4x4, m1); |
|
219 |
||
220 |
QVector3D v(10.5f, -2.0f, 3.0f); |
|
221 |
QVector3D result; |
|
222 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
223 |
m1.optimize(); |
0 | 224 |
|
225 |
QBENCHMARK { |
|
226 |
result = m1 * v; |
|
227 |
} |
|
228 |
||
229 |
// Force the result to be stored so the compiler doesn't |
|
230 |
// optimize away the contents of the benchmark loop. |
|
231 |
vresult = result; |
|
232 |
} |
|
233 |
||
234 |
QPointF vresult2; |
|
235 |
||
236 |
void tst_QMatrix4x4::mapVector2D_data() |
|
237 |
{ |
|
238 |
mapVector3D_data(); |
|
239 |
} |
|
240 |
void tst_QMatrix4x4::mapVector2D() |
|
241 |
{ |
|
242 |
QFETCH(QMatrix4x4, m1); |
|
243 |
||
244 |
QPointF v(10.5f, -2.0f); |
|
245 |
QPointF result; |
|
246 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
m1.optimize(); |
0 | 248 |
|
249 |
QBENCHMARK { |
|
250 |
result = m1 * v; |
|
251 |
} |
|
252 |
||
253 |
// Force the result to be stored so the compiler doesn't |
|
254 |
// optimize away the contents of the benchmark loop. |
|
255 |
vresult2 = result; |
|
256 |
} |
|
257 |
||
258 |
// Use a direct naive multiplication algorithm. This is used |
|
259 |
// to compare against the optimized routines to see if they are |
|
260 |
// actually faster than the naive implementation. |
|
261 |
void tst_QMatrix4x4::mapVectorDirect_data() |
|
262 |
{ |
|
263 |
mapVector3D_data(); |
|
264 |
} |
|
265 |
void tst_QMatrix4x4::mapVectorDirect() |
|
266 |
{ |
|
267 |
QFETCH(QMatrix4x4, m1); |
|
268 |
||
269 |
const qreal *m1data = m1.constData(); |
|
270 |
qreal v[4] = {10.5f, -2.0f, 3.0f, 1.0f}; |
|
271 |
qreal result[4]; |
|
272 |
||
273 |
QBENCHMARK { |
|
274 |
for (int row = 0; row < 4; ++row) { |
|
275 |
result[row] = 0.0f; |
|
276 |
for (int col = 0; col < 4; ++col) { |
|
277 |
result[row] += m1data[col * 4 + row] * v[col]; |
|
278 |
} |
|
279 |
} |
|
280 |
result[0] /= result[3]; |
|
281 |
result[1] /= result[3]; |
|
282 |
result[2] /= result[3]; |
|
283 |
} |
|
284 |
} |
|
285 |
||
286 |
// Compare the performance of QTransform::translate() to |
|
287 |
// QMatrix4x4::translate(). |
|
288 |
void tst_QMatrix4x4::compareTranslate_data() |
|
289 |
{ |
|
290 |
QTest::addColumn<bool>("useQTransform"); |
|
291 |
QTest::addColumn<QVector3D>("translation"); |
|
292 |
||
293 |
QTest::newRow("QTransform::translate(0, 0, 0)") |
|
294 |
<< true << QVector3D(0, 0, 0); |
|
295 |
QTest::newRow("QMatrix4x4::translate(0, 0, 0)") |
|
296 |
<< false << QVector3D(0, 0, 0); |
|
297 |
||
298 |
QTest::newRow("QTransform::translate(1, 2, 0)") |
|
299 |
<< true << QVector3D(1, 2, 0); |
|
300 |
QTest::newRow("QMatrix4x4::translate(1, 2, 0)") |
|
301 |
<< false << QVector3D(1, 2, 0); |
|
302 |
||
303 |
QTest::newRow("QTransform::translate(1, 2, 4)") |
|
304 |
<< true << QVector3D(1, 2, 4); |
|
305 |
QTest::newRow("QMatrix4x4::translate(1, 2, 4)") |
|
306 |
<< false << QVector3D(1, 2, 4); |
|
307 |
} |
|
308 |
void tst_QMatrix4x4::compareTranslate() |
|
309 |
{ |
|
310 |
QFETCH(bool, useQTransform); |
|
311 |
QFETCH(QVector3D, translation); |
|
312 |
||
313 |
qreal x = translation.x(); |
|
314 |
qreal y = translation.y(); |
|
315 |
qreal z = translation.z(); |
|
316 |
||
317 |
if (useQTransform) { |
|
318 |
QTransform t; |
|
319 |
QBENCHMARK { |
|
320 |
t.translate(x, y); |
|
321 |
} |
|
322 |
} else if (z == 0.0f) { |
|
323 |
QMatrix4x4 m; |
|
324 |
QBENCHMARK { |
|
325 |
m.translate(x, y); |
|
326 |
} |
|
327 |
} else { |
|
328 |
QMatrix4x4 m; |
|
329 |
QBENCHMARK { |
|
330 |
m.translate(x, y, z); |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
// Compare the performance of QTransform::translate() to |
|
336 |
// QMatrix4x4::translate() after priming the matrix with a scale(). |
|
337 |
void tst_QMatrix4x4::compareTranslateAfterScale_data() |
|
338 |
{ |
|
339 |
compareTranslate_data(); |
|
340 |
} |
|
341 |
void tst_QMatrix4x4::compareTranslateAfterScale() |
|
342 |
{ |
|
343 |
QFETCH(bool, useQTransform); |
|
344 |
QFETCH(QVector3D, translation); |
|
345 |
||
346 |
qreal x = translation.x(); |
|
347 |
qreal y = translation.y(); |
|
348 |
qreal z = translation.z(); |
|
349 |
||
350 |
if (useQTransform) { |
|
351 |
QTransform t; |
|
352 |
t.scale(3, 4); |
|
353 |
QBENCHMARK { |
|
354 |
t.translate(x, y); |
|
355 |
} |
|
356 |
} else if (z == 0.0f) { |
|
357 |
QMatrix4x4 m; |
|
358 |
m.scale(3, 4); |
|
359 |
QBENCHMARK { |
|
360 |
m.translate(x, y); |
|
361 |
} |
|
362 |
} else { |
|
363 |
QMatrix4x4 m; |
|
364 |
m.scale(3, 4, 5); |
|
365 |
QBENCHMARK { |
|
366 |
m.translate(x, y, z); |
|
367 |
} |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
// Compare the performance of QTransform::translate() to |
|
372 |
// QMatrix4x4::translate() after priming the matrix with a rotate(). |
|
373 |
void tst_QMatrix4x4::compareTranslateAfterRotate_data() |
|
374 |
{ |
|
375 |
compareTranslate_data(); |
|
376 |
} |
|
377 |
void tst_QMatrix4x4::compareTranslateAfterRotate() |
|
378 |
{ |
|
379 |
QFETCH(bool, useQTransform); |
|
380 |
QFETCH(QVector3D, translation); |
|
381 |
||
382 |
qreal x = translation.x(); |
|
383 |
qreal y = translation.y(); |
|
384 |
qreal z = translation.z(); |
|
385 |
||
386 |
if (useQTransform) { |
|
387 |
QTransform t; |
|
388 |
t.rotate(45.0f); |
|
389 |
QBENCHMARK { |
|
390 |
t.translate(x, y); |
|
391 |
} |
|
392 |
} else if (z == 0.0f) { |
|
393 |
QMatrix4x4 m; |
|
394 |
m.rotate(45.0f, 0, 0, 1); |
|
395 |
QBENCHMARK { |
|
396 |
m.translate(x, y); |
|
397 |
} |
|
398 |
} else { |
|
399 |
QMatrix4x4 m; |
|
400 |
m.rotate(45.0f, 0, 0, 1); |
|
401 |
QBENCHMARK { |
|
402 |
m.translate(x, y, z); |
|
403 |
} |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
// Compare the performance of QTransform::scale() to |
|
408 |
// QMatrix4x4::scale(). |
|
409 |
void tst_QMatrix4x4::compareScale_data() |
|
410 |
{ |
|
411 |
QTest::addColumn<bool>("useQTransform"); |
|
412 |
QTest::addColumn<QVector3D>("scale"); |
|
413 |
||
414 |
QTest::newRow("QTransform::scale(1, 1, 1)") |
|
415 |
<< true << QVector3D(1, 1, 1); |
|
416 |
QTest::newRow("QMatrix4x4::scale(1, 1, 1)") |
|
417 |
<< false << QVector3D(1, 1, 1); |
|
418 |
||
419 |
QTest::newRow("QTransform::scale(3, 6, 1)") |
|
420 |
<< true << QVector3D(3, 6, 1); |
|
421 |
QTest::newRow("QMatrix4x4::scale(3, 6, 1)") |
|
422 |
<< false << QVector3D(3, 6, 1); |
|
423 |
||
424 |
QTest::newRow("QTransform::scale(3, 6, 4)") |
|
425 |
<< true << QVector3D(3, 6, 4); |
|
426 |
QTest::newRow("QMatrix4x4::scale(3, 6, 4)") |
|
427 |
<< false << QVector3D(3, 6, 4); |
|
428 |
} |
|
429 |
void tst_QMatrix4x4::compareScale() |
|
430 |
{ |
|
431 |
QFETCH(bool, useQTransform); |
|
432 |
QFETCH(QVector3D, scale); |
|
433 |
||
434 |
qreal x = scale.x(); |
|
435 |
qreal y = scale.y(); |
|
436 |
qreal z = scale.z(); |
|
437 |
||
438 |
if (useQTransform) { |
|
439 |
QTransform t; |
|
440 |
QBENCHMARK { |
|
441 |
t.scale(x, y); |
|
442 |
} |
|
443 |
} else if (z == 1.0f) { |
|
444 |
QMatrix4x4 m; |
|
445 |
QBENCHMARK { |
|
446 |
m.scale(x, y); |
|
447 |
} |
|
448 |
} else { |
|
449 |
QMatrix4x4 m; |
|
450 |
QBENCHMARK { |
|
451 |
m.scale(x, y, z); |
|
452 |
} |
|
453 |
} |
|
454 |
} |
|
455 |
||
456 |
// Compare the performance of QTransform::scale() to |
|
457 |
// QMatrix4x4::scale() after priming the matrix with a translate(). |
|
458 |
void tst_QMatrix4x4::compareScaleAfterTranslate_data() |
|
459 |
{ |
|
460 |
compareScale_data(); |
|
461 |
} |
|
462 |
void tst_QMatrix4x4::compareScaleAfterTranslate() |
|
463 |
{ |
|
464 |
QFETCH(bool, useQTransform); |
|
465 |
QFETCH(QVector3D, scale); |
|
466 |
||
467 |
qreal x = scale.x(); |
|
468 |
qreal y = scale.y(); |
|
469 |
qreal z = scale.z(); |
|
470 |
||
471 |
if (useQTransform) { |
|
472 |
QTransform t; |
|
473 |
t.translate(20, 34); |
|
474 |
QBENCHMARK { |
|
475 |
t.scale(x, y); |
|
476 |
} |
|
477 |
} else if (z == 1.0f) { |
|
478 |
QMatrix4x4 m; |
|
479 |
m.translate(20, 34); |
|
480 |
QBENCHMARK { |
|
481 |
m.scale(x, y); |
|
482 |
} |
|
483 |
} else { |
|
484 |
QMatrix4x4 m; |
|
485 |
m.translate(20, 34, 42); |
|
486 |
QBENCHMARK { |
|
487 |
m.scale(x, y, z); |
|
488 |
} |
|
489 |
} |
|
490 |
} |
|
491 |
||
492 |
// Compare the performance of QTransform::scale() to |
|
493 |
// QMatrix4x4::scale() after priming the matrix with a rotate(). |
|
494 |
void tst_QMatrix4x4::compareScaleAfterRotate_data() |
|
495 |
{ |
|
496 |
compareScale_data(); |
|
497 |
} |
|
498 |
void tst_QMatrix4x4::compareScaleAfterRotate() |
|
499 |
{ |
|
500 |
QFETCH(bool, useQTransform); |
|
501 |
QFETCH(QVector3D, scale); |
|
502 |
||
503 |
qreal x = scale.x(); |
|
504 |
qreal y = scale.y(); |
|
505 |
qreal z = scale.z(); |
|
506 |
||
507 |
if (useQTransform) { |
|
508 |
QTransform t; |
|
509 |
t.rotate(45.0f); |
|
510 |
QBENCHMARK { |
|
511 |
t.scale(x, y); |
|
512 |
} |
|
513 |
} else if (z == 1.0f) { |
|
514 |
QMatrix4x4 m; |
|
515 |
m.rotate(45.0f, 0, 0, 1); |
|
516 |
QBENCHMARK { |
|
517 |
m.scale(x, y); |
|
518 |
} |
|
519 |
} else { |
|
520 |
QMatrix4x4 m; |
|
521 |
m.rotate(45.0f, 0, 0, 1); |
|
522 |
QBENCHMARK { |
|
523 |
m.scale(x, y, z); |
|
524 |
} |
|
525 |
} |
|
526 |
} |
|
527 |
||
528 |
// Compare the performance of QTransform::rotate() to |
|
529 |
// QMatrix4x4::rotate(). |
|
530 |
void tst_QMatrix4x4::compareRotate_data() |
|
531 |
{ |
|
532 |
QTest::addColumn<bool>("useQTransform"); |
|
533 |
QTest::addColumn<qreal>("angle"); |
|
534 |
QTest::addColumn<QVector3D>("rotation"); |
|
535 |
QTest::addColumn<int>("axis"); |
|
536 |
||
537 |
QTest::newRow("QTransform::rotate(0, ZAxis)") |
|
538 |
<< true << qreal(0.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); |
|
539 |
QTest::newRow("QMatrix4x4::rotate(0, ZAxis)") |
|
540 |
<< false << qreal(0.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); |
|
541 |
||
542 |
QTest::newRow("QTransform::rotate(45, ZAxis)") |
|
543 |
<< true << qreal(45.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); |
|
544 |
QTest::newRow("QMatrix4x4::rotate(45, ZAxis)") |
|
545 |
<< false << qreal(45.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); |
|
546 |
||
547 |
QTest::newRow("QTransform::rotate(90, ZAxis)") |
|
548 |
<< true << qreal(90.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); |
|
549 |
QTest::newRow("QMatrix4x4::rotate(90, ZAxis)") |
|
550 |
<< false << qreal(90.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); |
|
551 |
||
552 |
QTest::newRow("QTransform::rotate(0, YAxis)") |
|
553 |
<< true << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); |
|
554 |
QTest::newRow("QMatrix4x4::rotate(0, YAxis)") |
|
555 |
<< false << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); |
|
556 |
||
557 |
QTest::newRow("QTransform::rotate(45, YAxis)") |
|
558 |
<< true << qreal(45.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); |
|
559 |
QTest::newRow("QMatrix4x4::rotate(45, YAxis)") |
|
560 |
<< false << qreal(45.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); |
|
561 |
||
562 |
QTest::newRow("QTransform::rotate(90, YAxis)") |
|
563 |
<< true << qreal(90.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); |
|
564 |
QTest::newRow("QMatrix4x4::rotate(90, YAxis)") |
|
565 |
<< false << qreal(90.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); |
|
566 |
||
567 |
QTest::newRow("QTransform::rotate(0, XAxis)") |
|
568 |
<< true << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::XAxis); |
|
569 |
QTest::newRow("QMatrix4x4::rotate(0, XAxis)") |
|
570 |
<< false << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::XAxis); |
|
571 |
||
572 |
QTest::newRow("QTransform::rotate(45, XAxis)") |
|
573 |
<< true << qreal(45.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis); |
|
574 |
QTest::newRow("QMatrix4x4::rotate(45, XAxis)") |
|
575 |
<< false << qreal(45.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis); |
|
576 |
||
577 |
QTest::newRow("QTransform::rotate(90, XAxis)") |
|
578 |
<< true << qreal(90.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis); |
|
579 |
QTest::newRow("QMatrix4x4::rotate(90, XAxis)") |
|
580 |
<< false << qreal(90.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis); |
|
581 |
} |
|
582 |
void tst_QMatrix4x4::compareRotate() |
|
583 |
{ |
|
584 |
QFETCH(bool, useQTransform); |
|
585 |
QFETCH(qreal, angle); |
|
586 |
QFETCH(QVector3D, rotation); |
|
587 |
QFETCH(int, axis); |
|
588 |
||
589 |
qreal x = rotation.x(); |
|
590 |
qreal y = rotation.y(); |
|
591 |
qreal z = rotation.z(); |
|
592 |
||
593 |
if (useQTransform) { |
|
594 |
QTransform t; |
|
595 |
QBENCHMARK { |
|
596 |
t.rotate(angle, Qt::Axis(axis)); |
|
597 |
} |
|
598 |
} else { |
|
599 |
QMatrix4x4 m; |
|
600 |
QBENCHMARK { |
|
601 |
m.rotate(angle, x, y, z); |
|
602 |
} |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
// Compare the performance of QTransform::rotate() to |
|
607 |
// QMatrix4x4::rotate() after priming the matrix with a translate(). |
|
608 |
void tst_QMatrix4x4::compareRotateAfterTranslate_data() |
|
609 |
{ |
|
610 |
compareRotate_data(); |
|
611 |
} |
|
612 |
void tst_QMatrix4x4::compareRotateAfterTranslate() |
|
613 |
{ |
|
614 |
QFETCH(bool, useQTransform); |
|
615 |
QFETCH(qreal, angle); |
|
616 |
QFETCH(QVector3D, rotation); |
|
617 |
QFETCH(int, axis); |
|
618 |
||
619 |
qreal x = rotation.x(); |
|
620 |
qreal y = rotation.y(); |
|
621 |
qreal z = rotation.z(); |
|
622 |
||
623 |
if (useQTransform) { |
|
624 |
QTransform t; |
|
625 |
t.translate(3, 4); |
|
626 |
QBENCHMARK { |
|
627 |
t.rotate(angle, Qt::Axis(axis)); |
|
628 |
} |
|
629 |
} else { |
|
630 |
QMatrix4x4 m; |
|
631 |
m.translate(3, 4, 5); |
|
632 |
QBENCHMARK { |
|
633 |
m.rotate(angle, x, y, z); |
|
634 |
} |
|
635 |
} |
|
636 |
} |
|
637 |
||
638 |
// Compare the performance of QTransform::rotate() to |
|
639 |
// QMatrix4x4::rotate() after priming the matrix with a scale(). |
|
640 |
void tst_QMatrix4x4::compareRotateAfterScale_data() |
|
641 |
{ |
|
642 |
compareRotate_data(); |
|
643 |
} |
|
644 |
void tst_QMatrix4x4::compareRotateAfterScale() |
|
645 |
{ |
|
646 |
QFETCH(bool, useQTransform); |
|
647 |
QFETCH(qreal, angle); |
|
648 |
QFETCH(QVector3D, rotation); |
|
649 |
QFETCH(int, axis); |
|
650 |
||
651 |
qreal x = rotation.x(); |
|
652 |
qreal y = rotation.y(); |
|
653 |
qreal z = rotation.z(); |
|
654 |
||
655 |
if (useQTransform) { |
|
656 |
QTransform t; |
|
657 |
t.scale(3, 4); |
|
658 |
QBENCHMARK { |
|
659 |
t.rotate(angle, Qt::Axis(axis)); |
|
660 |
} |
|
661 |
} else { |
|
662 |
QMatrix4x4 m; |
|
663 |
m.scale(3, 4, 5); |
|
664 |
QBENCHMARK { |
|
665 |
m.rotate(angle, x, y, z); |
|
666 |
} |
|
667 |
} |
|
668 |
} |
|
669 |
||
670 |
QTEST_MAIN(tst_QMatrix4x4) |
|
671 |
||
672 |
#include "tst_qmatrix4x4.moc" |