qmatrix4x4.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/math3d/qmatrix4x4.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qmatrix4x4.h"-
35#include <QtCore/qmath.h>-
36#include <QtCore/qvariant.h>-
37#include <QtGui/qmatrix.h>-
38#include <QtGui/qtransform.h>-
39-
40#include <cmath>-
41-
42QT_BEGIN_NAMESPACE-
43-
44#ifndef QT_NO_MATRIX4X4-
45-
46/*!-
47 \class QMatrix4x4-
48 \brief The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.-
49 \since 4.6-
50 \ingroup painting-3D-
51 \inmodule QtGui-
52-
53 The QMatrix4x4 class in general is treated as a row-major matrix, in that the-
54 constructors and operator() functions take data in row-major format, as is-
55 familiar in C-style usage.-
56-
57 Internally the data is stored as column-major format, so as to be optimal for-
58 passing to OpenGL functions, which expect column-major data.-
59-
60 When using these functions be aware that they return data in \b{column-major}-
61 format:-
62 \list-
63 \li data()-
64 \li constData()-
65 \endlist-
66-
67 \sa QVector3D, QGenericMatrix-
68*/-
69-
70static const float inv_dist_to_plane = 1.0f / 1024.0f;-
71-
72/*!-
73 \fn QMatrix4x4::QMatrix4x4()-
74-
75 Constructs an identity matrix.-
76*/-
77-
78/*!-
79 \fn QMatrix4x4::QMatrix4x4(Qt::Initialization)-
80 \since 5.5-
81 \internal-
82-
83 Constructs a matrix without initializing the contents.-
84*/-
85-
86/*!-
87 Constructs a matrix from the given 16 floating-point \a values.-
88 The contents of the array \a values is assumed to be in-
89 row-major order.-
90-
91 If the matrix has a special type (identity, translate, scale, etc),-
92 the programmer should follow this constructor with a call to-
93 optimize() if they wish QMatrix4x4 to optimize further-
94 calls to translate(), scale(), etc.-
95-
96 \sa copyDataTo(), optimize()-
97*/-
98QMatrix4x4::QMatrix4x4(const float *values)-
99{-
100 for (int row = 0; row < 4; ++row)
row < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
101 for (int col = 0; col < 4; ++col)
col < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
102 m[col][row] = values[row * 4 + col];
never executed: m[col][row] = values[row * 4 + col];
0
103 flagBits = General;-
104}
never executed: end of block
0
105-
106/*!-
107 \fn QMatrix4x4::QMatrix4x4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)-
108-
109 Constructs a matrix from the 16 elements \a m11, \a m12, \a m13, \a m14,-
110 \a m21, \a m22, \a m23, \a m24, \a m31, \a m32, \a m33, \a m34,-
111 \a m41, \a m42, \a m43, and \a m44. The elements are specified in-
112 row-major order.-
113-
114 If the matrix has a special type (identity, translate, scale, etc),-
115 the programmer should follow this constructor with a call to-
116 optimize() if they wish QMatrix4x4 to optimize further-
117 calls to translate(), scale(), etc.-
118-
119 \sa optimize()-
120*/-
121-
122/*!-
123 \fn QMatrix4x4::QMatrix4x4(const QGenericMatrix<N, M, float>& matrix)-
124-
125 Constructs a 4x4 matrix from the left-most 4 columns and top-most-
126 4 rows of \a matrix. If \a matrix has less than 4 columns or rows,-
127 the remaining elements are filled with elements from the identity-
128 matrix.-
129-
130 \sa toGenericMatrix()-
131*/-
132-
133/*!-
134 \fn QGenericMatrix<N, M, float> QMatrix4x4::toGenericMatrix() const-
135-
136 Constructs a NxM generic matrix from the left-most N columns and-
137 top-most M rows of this 4x4 matrix. If N or M is greater than 4,-
138 then the remaining elements are filled with elements from the-
139 identity matrix.-
140*/-
141-
142/*!-
143 \fn QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix<N, M, float>& matrix)-
144 \relates QMatrix4x4-
145 \obsolete-
146-
147 Returns a 4x4 matrix constructed from the left-most 4 columns and-
148 top-most 4 rows of \a matrix. If \a matrix has less than 4 columns-
149 or rows, the remaining elements are filled with elements from the-
150 identity matrix.-
151*/-
152-
153/*!-
154 \fn QGenericMatrix<N, M, float> qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix)-
155 \relates QMatrix4x4-
156 \obsolete-
157-
158 Returns a NxM generic matrix constructed from the left-most N columns-
159 and top-most M rows of \a matrix. If N or M is greater than 4,-
160 then the remaining elements are filled with elements from the-
161 identity matrix.-
162-
163 \sa QMatrix4x4::toGenericMatrix()-
164*/-
165-
166/*!-
167 \internal-
168*/-
169QMatrix4x4::QMatrix4x4(const float *values, int cols, int rows)-
170{-
171 for (int col = 0; col < 4; ++col) {
col < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
172 for (int row = 0; row < 4; ++row) {
row < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
173 if (col < cols && row < rows)
col < colsDescription
TRUEnever evaluated
FALSEnever evaluated
row < rowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
174 m[col][row] = values[col * rows + row];
never executed: m[col][row] = values[col * rows + row];
0
175 else if (col == row)
col == rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
176 m[col][row] = 1.0f;
never executed: m[col][row] = 1.0f;
0
177 else-
178 m[col][row] = 0.0f;
never executed: m[col][row] = 0.0f;
0
179 }-
180 }
never executed: end of block
0
181 flagBits = General;-
182}
never executed: end of block
0
183-
184/*!-
185 Constructs a 4x4 matrix from a conventional Qt 2D affine-
186 transformation \a matrix.-
187-
188 If \a matrix has a special type (identity, translate, scale, etc),-
189 the programmer should follow this constructor with a call to-
190 optimize() if they wish QMatrix4x4 to optimize further-
191 calls to translate(), scale(), etc.-
192-
193 \sa toAffine(), optimize()-
194*/-
195QMatrix4x4::QMatrix4x4(const QMatrix& matrix)-
196{-
197 m[0][0] = matrix.m11();-
198 m[0][1] = matrix.m12();-
199 m[0][2] = 0.0f;-
200 m[0][3] = 0.0f;-
201 m[1][0] = matrix.m21();-
202 m[1][1] = matrix.m22();-
203 m[1][2] = 0.0f;-
204 m[1][3] = 0.0f;-
205 m[2][0] = 0.0f;-
206 m[2][1] = 0.0f;-
207 m[2][2] = 1.0f;-
208 m[2][3] = 0.0f;-
209 m[3][0] = matrix.dx();-
210 m[3][1] = matrix.dy();-
211 m[3][2] = 0.0f;-
212 m[3][3] = 1.0f;-
213 flagBits = Translation | Scale | Rotation2D;-
214}
never executed: end of block
0
215-
216/*!-
217 Constructs a 4x4 matrix from the conventional Qt 2D-
218 transformation matrix \a transform.-
219-
220 If \a transform has a special type (identity, translate, scale, etc),-
221 the programmer should follow this constructor with a call to-
222 optimize() if they wish QMatrix4x4 to optimize further-
223 calls to translate(), scale(), etc.-
224-
225 \sa toTransform(), optimize()-
226*/-
227QMatrix4x4::QMatrix4x4(const QTransform& transform)-
228{-
229 m[0][0] = transform.m11();-
230 m[0][1] = transform.m12();-
231 m[0][2] = 0.0f;-
232 m[0][3] = transform.m13();-
233 m[1][0] = transform.m21();-
234 m[1][1] = transform.m22();-
235 m[1][2] = 0.0f;-
236 m[1][3] = transform.m23();-
237 m[2][0] = 0.0f;-
238 m[2][1] = 0.0f;-
239 m[2][2] = 1.0f;-
240 m[2][3] = 0.0f;-
241 m[3][0] = transform.dx();-
242 m[3][1] = transform.dy();-
243 m[3][2] = 0.0f;-
244 m[3][3] = transform.m33();-
245 flagBits = General;-
246}
never executed: end of block
0
247-
248/*!-
249 \fn const float& QMatrix4x4::operator()(int row, int column) const-
250-
251 Returns a constant reference to the element at position-
252 (\a row, \a column) in this matrix.-
253-
254 \sa column(), row()-
255*/-
256-
257/*!-
258 \fn float& QMatrix4x4::operator()(int row, int column)-
259-
260 Returns a reference to the element at position (\a row, \a column)-
261 in this matrix so that the element can be assigned to.-
262-
263 \sa optimize(), setColumn(), setRow()-
264*/-
265-
266/*!-
267 \fn QVector4D QMatrix4x4::column(int index) const-
268-
269 Returns the elements of column \a index as a 4D vector.-
270-
271 \sa setColumn(), row()-
272*/-
273-
274/*!-
275 \fn void QMatrix4x4::setColumn(int index, const QVector4D& value)-
276-
277 Sets the elements of column \a index to the components of \a value.-
278-
279 \sa column(), setRow()-
280*/-
281-
282/*!-
283 \fn QVector4D QMatrix4x4::row(int index) const-
284-
285 Returns the elements of row \a index as a 4D vector.-
286-
287 \sa setRow(), column()-
288*/-
289-
290/*!-
291 \fn void QMatrix4x4::setRow(int index, const QVector4D& value)-
292-
293 Sets the elements of row \a index to the components of \a value.-
294-
295 \sa row(), setColumn()-
296*/-
297-
298/*!-
299 \fn bool QMatrix4x4::isAffine() const-
300 \since 5.5-
301-
302 Returns \c true if this matrix is affine matrix; false otherwise.-
303-
304 An affine matrix is a 4x4 matrix with row 3 equal to (0, 0, 0, 1),-
305 e.g. no projective coefficients.-
306-
307 \sa isIdentity()-
308*/-
309-
310/*!-
311 \fn bool QMatrix4x4::isIdentity() const-
312-
313 Returns \c true if this matrix is the identity; false otherwise.-
314-
315 \sa setToIdentity()-
316*/-
317-
318/*!-
319 \fn void QMatrix4x4::setToIdentity()-
320-
321 Sets this matrix to the identity.-
322-
323 \sa isIdentity()-
324*/-
325-
326/*!-
327 \fn void QMatrix4x4::fill(float value)-
328-
329 Fills all elements of this matrx with \a value.-
330*/-
331-
332static inline double matrixDet2(const double m[4][4], int col0, int col1, int row0, int row1)-
333{-
334 return m[col0][row0] * m[col1][row1] - m[col0][row1] * m[col1][row0];
never executed: return m[col0][row0] * m[col1][row1] - m[col0][row1] * m[col1][row0];
0
335}-
336-
337-
338// The 4x4 matrix inverse algorithm is based on that described at:-
339// http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q24-
340// Some optimization has been done to avoid making copies of 3x3-
341// sub-matrices and to unroll the loops.-
342-
343// Calculate the determinant of a 3x3 sub-matrix.-
344// | A B C |-
345// M = | D E F | det(M) = A * (EI - HF) - B * (DI - GF) + C * (DH - GE)-
346// | G H I |-
347static inline double matrixDet3-
348 (const double m[4][4], int col0, int col1, int col2,-
349 int row0, int row1, int row2)-
350{-
351 return m[col0][row0] * matrixDet2(m, col1, col2, row1, row2)
never executed: return m[col0][row0] * matrixDet2(m, col1, col2, row1, row2) - m[col1][row0] * matrixDet2(m, col0, col2, row1, row2) + m[col2][row0] * matrixDet2(m, col0, col1, row1, row2);
0
352 - m[col1][row0] * matrixDet2(m, col0, col2, row1, row2)
never executed: return m[col0][row0] * matrixDet2(m, col1, col2, row1, row2) - m[col1][row0] * matrixDet2(m, col0, col2, row1, row2) + m[col2][row0] * matrixDet2(m, col0, col1, row1, row2);
0
353 + m[col2][row0] * matrixDet2(m, col0, col1, row1, row2);
never executed: return m[col0][row0] * matrixDet2(m, col1, col2, row1, row2) - m[col1][row0] * matrixDet2(m, col0, col2, row1, row2) + m[col2][row0] * matrixDet2(m, col0, col1, row1, row2);
0
354}-
355-
356// Calculate the determinant of a 4x4 matrix.-
357static inline double matrixDet4(const double m[4][4])-
358{-
359 double det;-
360 det = m[0][0] * matrixDet3(m, 1, 2, 3, 1, 2, 3);-
361 det -= m[1][0] * matrixDet3(m, 0, 2, 3, 1, 2, 3);-
362 det += m[2][0] * matrixDet3(m, 0, 1, 3, 1, 2, 3);-
363 det -= m[3][0] * matrixDet3(m, 0, 1, 2, 1, 2, 3);-
364 return det;
never executed: return det;
0
365}-
366-
367static inline void copyToDoubles(const float m[4][4], double mm[4][4])-
368{-
369 for (int i = 0; i < 4; ++i)
i < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
370 for (int j = 0; j < 4; ++j)
j < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
371 mm[i][j] = double(m[i][j]);
never executed: mm[i][j] = double(m[i][j]);
0
372}
never executed: end of block
0
373-
374/*!-
375 Returns the determinant of this matrix.-
376*/-
377double QMatrix4x4::determinant() const-
378{-
379 if ((flagBits & ~(Translation | Rotation2D | Rotation)) == Identity)
(flagBits & ~(...)) == IdentityDescription
TRUEnever evaluated
FALSEnever evaluated
0
380 return 1.0;
never executed: return 1.0;
0
381-
382 double mm[4][4];-
383 copyToDoubles(m, mm);-
384 if (flagBits < Rotation2D)
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
385 return mm[0][0] * mm[1][1] * mm[2][2]; // Translation | Scale
never executed: return mm[0][0] * mm[1][1] * mm[2][2];
0
386 if (flagBits < Perspective)
flagBits < PerspectiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
387 return matrixDet3(mm, 0, 1, 2, 0, 1, 2);
never executed: return matrixDet3(mm, 0, 1, 2, 0, 1, 2);
0
388 return matrixDet4(mm);
never executed: return matrixDet4(mm);
0
389}-
390-
391/*!-
392 Returns the inverse of this matrix. Returns the identity if-
393 this matrix cannot be inverted; i.e. determinant() is zero.-
394 If \a invertible is not null, then true will be written to-
395 that location if the matrix can be inverted; false otherwise.-
396-
397 If the matrix is recognized as the identity or an orthonormal-
398 matrix, then this function will quickly invert the matrix-
399 using optimized routines.-
400-
401 \sa determinant(), normalMatrix()-
402*/-
403QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const-
404{-
405 // Handle some of the easy cases first.-
406 if (flagBits == Identity) {
flagBits == IdentityDescription
TRUEnever evaluated
FALSEnever evaluated
0
407 if (invertible)
invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
408 *invertible = true;
never executed: *invertible = true;
0
409 return QMatrix4x4();
never executed: return QMatrix4x4();
0
410 } else if (flagBits == Translation) {
flagBits == TranslationDescription
TRUEnever evaluated
FALSEnever evaluated
0
411 QMatrix4x4 inv;-
412 inv.m[3][0] = -m[3][0];-
413 inv.m[3][1] = -m[3][1];-
414 inv.m[3][2] = -m[3][2];-
415 inv.flagBits = Translation;-
416 if (invertible)
invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
417 *invertible = true;
never executed: *invertible = true;
0
418 return inv;
never executed: return inv;
0
419 } else if (flagBits < Rotation2D) {
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
420 // Translation | Scale-
421 if (m[0][0] == 0 || m[1][1] == 0 || m[2][2] == 0) {
m[0][0] == 0Description
TRUEnever evaluated
FALSEnever evaluated
m[1][1] == 0Description
TRUEnever evaluated
FALSEnever evaluated
m[2][2] == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
422 if (invertible)
invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
423 *invertible = false;
never executed: *invertible = false;
0
424 return QMatrix4x4();
never executed: return QMatrix4x4();
0
425 }-
426 QMatrix4x4 inv;-
427 inv.m[0][0] = 1.0f / m[0][0];-
428 inv.m[1][1] = 1.0f / m[1][1];-
429 inv.m[2][2] = 1.0f / m[2][2];-
430 inv.m[3][0] = -m[3][0] * inv.m[0][0];-
431 inv.m[3][1] = -m[3][1] * inv.m[1][1];-
432 inv.m[3][2] = -m[3][2] * inv.m[2][2];-
433 inv.flagBits = flagBits;-
434-
435 if (invertible)
invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
436 *invertible = true;
never executed: *invertible = true;
0
437 return inv;
never executed: return inv;
0
438 } else if ((flagBits & ~(Translation | Rotation2D | Rotation)) == Identity) {
(flagBits & ~(...)) == IdentityDescription
TRUEnever evaluated
FALSEnever evaluated
0
439 if (invertible)
invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
440 *invertible = true;
never executed: *invertible = true;
0
441 return orthonormalInverse();
never executed: return orthonormalInverse();
0
442 } else if (flagBits < Perspective) {
flagBits < PerspectiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
443 QMatrix4x4 inv(1); // The "1" says to not load the identity.-
444-
445 double mm[4][4];-
446 copyToDoubles(m, mm);-
447-
448 double det = matrixDet3(mm, 0, 1, 2, 0, 1, 2);-
449 if (det == 0.0f) {
det == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
450 if (invertible)
invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
451 *invertible = false;
never executed: *invertible = false;
0
452 return QMatrix4x4();
never executed: return QMatrix4x4();
0
453 }-
454 det = 1.0f / det;-
455-
456 inv.m[0][0] = matrixDet2(mm, 1, 2, 1, 2) * det;-
457 inv.m[0][1] = -matrixDet2(mm, 0, 2, 1, 2) * det;-
458 inv.m[0][2] = matrixDet2(mm, 0, 1, 1, 2) * det;-
459 inv.m[0][3] = 0;-
460 inv.m[1][0] = -matrixDet2(mm, 1, 2, 0, 2) * det;-
461 inv.m[1][1] = matrixDet2(mm, 0, 2, 0, 2) * det;-
462 inv.m[1][2] = -matrixDet2(mm, 0, 1, 0, 2) * det;-
463 inv.m[1][3] = 0;-
464 inv.m[2][0] = matrixDet2(mm, 1, 2, 0, 1) * det;-
465 inv.m[2][1] = -matrixDet2(mm, 0, 2, 0, 1) * det;-
466 inv.m[2][2] = matrixDet2(mm, 0, 1, 0, 1) * det;-
467 inv.m[2][3] = 0;-
468 inv.m[3][0] = -inv.m[0][0] * m[3][0] - inv.m[1][0] * m[3][1] - inv.m[2][0] * m[3][2];-
469 inv.m[3][1] = -inv.m[0][1] * m[3][0] - inv.m[1][1] * m[3][1] - inv.m[2][1] * m[3][2];-
470 inv.m[3][2] = -inv.m[0][2] * m[3][0] - inv.m[1][2] * m[3][1] - inv.m[2][2] * m[3][2];-
471 inv.m[3][3] = 1;-
472 inv.flagBits = flagBits;-
473-
474 if (invertible)
invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
475 *invertible = true;
never executed: *invertible = true;
0
476 return inv;
never executed: return inv;
0
477 }-
478-
479 QMatrix4x4 inv(1); // The "1" says to not load the identity.-
480-
481 double mm[4][4];-
482 copyToDoubles(m, mm);-
483-
484 double det = matrixDet4(mm);-
485 if (det == 0.0f) {
det == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
486 if (invertible)
invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
487 *invertible = false;
never executed: *invertible = false;
0
488 return QMatrix4x4();
never executed: return QMatrix4x4();
0
489 }-
490 det = 1.0f / det;-
491-
492 inv.m[0][0] = matrixDet3(mm, 1, 2, 3, 1, 2, 3) * det;-
493 inv.m[0][1] = -matrixDet3(mm, 0, 2, 3, 1, 2, 3) * det;-
494 inv.m[0][2] = matrixDet3(mm, 0, 1, 3, 1, 2, 3) * det;-
495 inv.m[0][3] = -matrixDet3(mm, 0, 1, 2, 1, 2, 3) * det;-
496 inv.m[1][0] = -matrixDet3(mm, 1, 2, 3, 0, 2, 3) * det;-
497 inv.m[1][1] = matrixDet3(mm, 0, 2, 3, 0, 2, 3) * det;-
498 inv.m[1][2] = -matrixDet3(mm, 0, 1, 3, 0, 2, 3) * det;-
499 inv.m[1][3] = matrixDet3(mm, 0, 1, 2, 0, 2, 3) * det;-
500 inv.m[2][0] = matrixDet3(mm, 1, 2, 3, 0, 1, 3) * det;-
501 inv.m[2][1] = -matrixDet3(mm, 0, 2, 3, 0, 1, 3) * det;-
502 inv.m[2][2] = matrixDet3(mm, 0, 1, 3, 0, 1, 3) * det;-
503 inv.m[2][3] = -matrixDet3(mm, 0, 1, 2, 0, 1, 3) * det;-
504 inv.m[3][0] = -matrixDet3(mm, 1, 2, 3, 0, 1, 2) * det;-
505 inv.m[3][1] = matrixDet3(mm, 0, 2, 3, 0, 1, 2) * det;-
506 inv.m[3][2] = -matrixDet3(mm, 0, 1, 3, 0, 1, 2) * det;-
507 inv.m[3][3] = matrixDet3(mm, 0, 1, 2, 0, 1, 2) * det;-
508 inv.flagBits = flagBits;-
509-
510 if (invertible)
invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
511 *invertible = true;
never executed: *invertible = true;
0
512 return inv;
never executed: return inv;
0
513}-
514-
515/*!-
516 Returns the normal matrix corresponding to this 4x4 transformation.-
517 The normal matrix is the transpose of the inverse of the top-left-
518 3x3 part of this 4x4 matrix. If the 3x3 sub-matrix is not invertible,-
519 this function returns the identity.-
520-
521 \sa inverted()-
522*/-
523QMatrix3x3 QMatrix4x4::normalMatrix() const-
524{-
525 QMatrix3x3 inv;-
526-
527 // Handle the simple cases first.-
528 if (flagBits < Scale) {
flagBits < ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
529 // Translation-
530 return inv;
never executed: return inv;
0
531 } else if (flagBits < Rotation2D) {
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
532 // Translation | Scale-
533 if (m[0][0] == 0.0f || m[1][1] == 0.0f || m[2][2] == 0.0f)
m[0][0] == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
m[1][1] == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
m[2][2] == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
534 return inv;
never executed: return inv;
0
535 inv.data()[0] = 1.0f / m[0][0];-
536 inv.data()[4] = 1.0f / m[1][1];-
537 inv.data()[8] = 1.0f / m[2][2];-
538 return inv;
never executed: return inv;
0
539 } else if ((flagBits & ~(Translation | Rotation2D | Rotation)) == Identity) {
(flagBits & ~(...)) == IdentityDescription
TRUEnever evaluated
FALSEnever evaluated
0
540 float *invm = inv.data();-
541 invm[0 + 0 * 3] = m[0][0];-
542 invm[1 + 0 * 3] = m[0][1];-
543 invm[2 + 0 * 3] = m[0][2];-
544 invm[0 + 1 * 3] = m[1][0];-
545 invm[1 + 1 * 3] = m[1][1];-
546 invm[2 + 1 * 3] = m[1][2];-
547 invm[0 + 2 * 3] = m[2][0];-
548 invm[1 + 2 * 3] = m[2][1];-
549 invm[2 + 2 * 3] = m[2][2];-
550 return inv;
never executed: return inv;
0
551 }-
552-
553 double mm[4][4];-
554 copyToDoubles(m, mm);-
555 double det = matrixDet3(mm, 0, 1, 2, 0, 1, 2);-
556 if (det == 0.0f)
det == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
557 return inv;
never executed: return inv;
0
558 det = 1.0f / det;-
559-
560 float *invm = inv.data();-
561-
562 // Invert and transpose in a single step.-
563 invm[0 + 0 * 3] = (mm[1][1] * mm[2][2] - mm[2][1] * mm[1][2]) * det;-
564 invm[1 + 0 * 3] = -(mm[1][0] * mm[2][2] - mm[1][2] * mm[2][0]) * det;-
565 invm[2 + 0 * 3] = (mm[1][0] * mm[2][1] - mm[1][1] * mm[2][0]) * det;-
566 invm[0 + 1 * 3] = -(mm[0][1] * mm[2][2] - mm[2][1] * mm[0][2]) * det;-
567 invm[1 + 1 * 3] = (mm[0][0] * mm[2][2] - mm[0][2] * mm[2][0]) * det;-
568 invm[2 + 1 * 3] = -(mm[0][0] * mm[2][1] - mm[0][1] * mm[2][0]) * det;-
569 invm[0 + 2 * 3] = (mm[0][1] * mm[1][2] - mm[0][2] * mm[1][1]) * det;-
570 invm[1 + 2 * 3] = -(mm[0][0] * mm[1][2] - mm[0][2] * mm[1][0]) * det;-
571 invm[2 + 2 * 3] = (mm[0][0] * mm[1][1] - mm[1][0] * mm[0][1]) * det;-
572-
573 return inv;
never executed: return inv;
0
574}-
575-
576/*!-
577 Returns this matrix, transposed about its diagonal.-
578*/-
579QMatrix4x4 QMatrix4x4::transposed() const-
580{-
581 QMatrix4x4 result(1); // The "1" says to not load the identity.-
582 for (int row = 0; row < 4; ++row) {
row < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
583 for (int col = 0; col < 4; ++col) {
col < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
584 result.m[col][row] = m[row][col];-
585 }
never executed: end of block
0
586 }
never executed: end of block
0
587 // When a translation is transposed, it becomes a perspective transformation.-
588 result.flagBits = (flagBits & Translation ? General : flagBits);
flagBits & TranslationDescription
TRUEnever evaluated
FALSEnever evaluated
0
589 return result;
never executed: return result;
0
590}-
591-
592/*!-
593 \fn QMatrix4x4& QMatrix4x4::operator+=(const QMatrix4x4& other)-
594-
595 Adds the contents of \a other to this matrix.-
596*/-
597-
598/*!-
599 \fn QMatrix4x4& QMatrix4x4::operator-=(const QMatrix4x4& other)-
600-
601 Subtracts the contents of \a other from this matrix.-
602*/-
603-
604/*!-
605 \fn QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& other)-
606-
607 Multiplies the contents of \a other by this matrix.-
608*/-
609-
610/*!-
611 \fn QMatrix4x4& QMatrix4x4::operator*=(float factor)-
612 \overload-
613-
614 Multiplies all elements of this matrix by \a factor.-
615*/-
616-
617/*!-
618 \overload-
619-
620 Divides all elements of this matrix by \a divisor.-
621*/-
622QMatrix4x4& QMatrix4x4::operator/=(float divisor)-
623{-
624 m[0][0] /= divisor;-
625 m[0][1] /= divisor;-
626 m[0][2] /= divisor;-
627 m[0][3] /= divisor;-
628 m[1][0] /= divisor;-
629 m[1][1] /= divisor;-
630 m[1][2] /= divisor;-
631 m[1][3] /= divisor;-
632 m[2][0] /= divisor;-
633 m[2][1] /= divisor;-
634 m[2][2] /= divisor;-
635 m[2][3] /= divisor;-
636 m[3][0] /= divisor;-
637 m[3][1] /= divisor;-
638 m[3][2] /= divisor;-
639 m[3][3] /= divisor;-
640 flagBits = General;-
641 return *this;
never executed: return *this;
0
642}-
643-
644/*!-
645 \fn bool QMatrix4x4::operator==(const QMatrix4x4& other) const-
646-
647 Returns \c true if this matrix is identical to \a other; false otherwise.-
648 This operator uses an exact floating-point comparison.-
649*/-
650-
651/*!-
652 \fn bool QMatrix4x4::operator!=(const QMatrix4x4& other) const-
653-
654 Returns \c true if this matrix is not identical to \a other; false otherwise.-
655 This operator uses an exact floating-point comparison.-
656*/-
657-
658/*!-
659 \fn QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2)-
660 \relates QMatrix4x4-
661-
662 Returns the sum of \a m1 and \a m2.-
663*/-
664-
665/*!-
666 \fn QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2)-
667 \relates QMatrix4x4-
668-
669 Returns the difference of \a m1 and \a m2.-
670*/-
671-
672/*!-
673 \fn QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)-
674 \relates QMatrix4x4-
675-
676 Returns the product of \a m1 and \a m2.-
677*/-
678-
679#ifndef QT_NO_VECTOR3D-
680-
681/*!-
682 \fn QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)-
683 \relates QMatrix4x4-
684-
685 Returns the result of transforming \a vector according to \a matrix,-
686 with the matrix applied post-vector.-
687*/-
688-
689/*!-
690 \fn QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)-
691 \relates QMatrix4x4-
692-
693 Returns the result of transforming \a vector according to \a matrix,-
694 with the matrix applied pre-vector.-
695*/-
696-
697#endif-
698-
699#ifndef QT_NO_VECTOR4D-
700-
701/*!-
702 \fn QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)-
703 \relates QMatrix4x4-
704-
705 Returns the result of transforming \a vector according to \a matrix,-
706 with the matrix applied post-vector.-
707*/-
708-
709/*!-
710 \fn QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector)-
711 \relates QMatrix4x4-
712-
713 Returns the result of transforming \a vector according to \a matrix,-
714 with the matrix applied pre-vector.-
715*/-
716-
717#endif-
718-
719/*!-
720 \fn QPoint operator*(const QPoint& point, const QMatrix4x4& matrix)-
721 \relates QMatrix4x4-
722-
723 Returns the result of transforming \a point according to \a matrix,-
724 with the matrix applied post-point.-
725*/-
726-
727/*!-
728 \fn QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)-
729 \relates QMatrix4x4-
730-
731 Returns the result of transforming \a point according to \a matrix,-
732 with the matrix applied post-point.-
733*/-
734-
735/*!-
736 \fn QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)-
737 \relates QMatrix4x4-
738-
739 Returns the result of transforming \a point according to \a matrix,-
740 with the matrix applied pre-point.-
741*/-
742-
743/*!-
744 \fn QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)-
745 \relates QMatrix4x4-
746-
747 Returns the result of transforming \a point according to \a matrix,-
748 with the matrix applied pre-point.-
749*/-
750-
751/*!-
752 \fn QMatrix4x4 operator-(const QMatrix4x4& matrix)-
753 \overload-
754 \relates QMatrix4x4-
755-
756 Returns the negation of \a matrix.-
757*/-
758-
759/*!-
760 \fn QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix)-
761 \relates QMatrix4x4-
762-
763 Returns the result of multiplying all elements of \a matrix by \a factor.-
764*/-
765-
766/*!-
767 \fn QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor)-
768 \relates QMatrix4x4-
769-
770 Returns the result of multiplying all elements of \a matrix by \a factor.-
771*/-
772-
773/*!-
774 \relates QMatrix4x4-
775-
776 Returns the result of dividing all elements of \a matrix by \a divisor.-
777*/-
778QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor)-
779{-
780 QMatrix4x4 m(1); // The "1" says to not load the identity.-
781 m.m[0][0] = matrix.m[0][0] / divisor;-
782 m.m[0][1] = matrix.m[0][1] / divisor;-
783 m.m[0][2] = matrix.m[0][2] / divisor;-
784 m.m[0][3] = matrix.m[0][3] / divisor;-
785 m.m[1][0] = matrix.m[1][0] / divisor;-
786 m.m[1][1] = matrix.m[1][1] / divisor;-
787 m.m[1][2] = matrix.m[1][2] / divisor;-
788 m.m[1][3] = matrix.m[1][3] / divisor;-
789 m.m[2][0] = matrix.m[2][0] / divisor;-
790 m.m[2][1] = matrix.m[2][1] / divisor;-
791 m.m[2][2] = matrix.m[2][2] / divisor;-
792 m.m[2][3] = matrix.m[2][3] / divisor;-
793 m.m[3][0] = matrix.m[3][0] / divisor;-
794 m.m[3][1] = matrix.m[3][1] / divisor;-
795 m.m[3][2] = matrix.m[3][2] / divisor;-
796 m.m[3][3] = matrix.m[3][3] / divisor;-
797 m.flagBits = QMatrix4x4::General;-
798 return m;
never executed: return m;
0
799}-
800-
801/*!-
802 \fn bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2)-
803 \relates QMatrix4x4-
804-
805 Returns \c true if \a m1 and \a m2 are equal, allowing for a small-
806 fuzziness factor for floating-point comparisons; false otherwise.-
807*/-
808-
809#ifndef QT_NO_VECTOR3D-
810-
811/*!-
812 Multiplies this matrix by another that scales coordinates by-
813 the components of \a vector.-
814-
815 \sa translate(), rotate()-
816*/-
817void QMatrix4x4::scale(const QVector3D& vector)-
818{-
819 float vx = vector.x();-
820 float vy = vector.y();-
821 float vz = vector.z();-
822 if (flagBits < Scale) {
flagBits < ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
823 m[0][0] = vx;-
824 m[1][1] = vy;-
825 m[2][2] = vz;-
826 } else if (flagBits < Rotation2D) {
never executed: end of block
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
827 m[0][0] *= vx;-
828 m[1][1] *= vy;-
829 m[2][2] *= vz;-
830 } else if (flagBits < Rotation) {
never executed: end of block
flagBits < RotationDescription
TRUEnever evaluated
FALSEnever evaluated
0
831 m[0][0] *= vx;-
832 m[0][1] *= vx;-
833 m[1][0] *= vy;-
834 m[1][1] *= vy;-
835 m[2][2] *= vz;-
836 } else {
never executed: end of block
0
837 m[0][0] *= vx;-
838 m[0][1] *= vx;-
839 m[0][2] *= vx;-
840 m[0][3] *= vx;-
841 m[1][0] *= vy;-
842 m[1][1] *= vy;-
843 m[1][2] *= vy;-
844 m[1][3] *= vy;-
845 m[2][0] *= vz;-
846 m[2][1] *= vz;-
847 m[2][2] *= vz;-
848 m[2][3] *= vz;-
849 }
never executed: end of block
0
850 flagBits |= Scale;-
851}
never executed: end of block
0
852-
853#endif-
854-
855/*!-
856 \overload-
857-
858 Multiplies this matrix by another that scales coordinates by the-
859 components \a x, and \a y.-
860-
861 \sa translate(), rotate()-
862*/-
863void QMatrix4x4::scale(float x, float y)-
864{-
865 if (flagBits < Scale) {
flagBits < ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
866 m[0][0] = x;-
867 m[1][1] = y;-
868 } else if (flagBits < Rotation2D) {
never executed: end of block
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
869 m[0][0] *= x;-
870 m[1][1] *= y;-
871 } else if (flagBits < Rotation) {
never executed: end of block
flagBits < RotationDescription
TRUEnever evaluated
FALSEnever evaluated
0
872 m[0][0] *= x;-
873 m[0][1] *= x;-
874 m[1][0] *= y;-
875 m[1][1] *= y;-
876 } else {
never executed: end of block
0
877 m[0][0] *= x;-
878 m[0][1] *= x;-
879 m[0][2] *= x;-
880 m[0][3] *= x;-
881 m[1][0] *= y;-
882 m[1][1] *= y;-
883 m[1][2] *= y;-
884 m[1][3] *= y;-
885 }
never executed: end of block
0
886 flagBits |= Scale;-
887}
never executed: end of block
0
888-
889/*!-
890 \overload-
891-
892 Multiplies this matrix by another that scales coordinates by the-
893 components \a x, \a y, and \a z.-
894-
895 \sa translate(), rotate()-
896*/-
897void QMatrix4x4::scale(float x, float y, float z)-
898{-
899 if (flagBits < Scale) {
flagBits < ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
900 m[0][0] = x;-
901 m[1][1] = y;-
902 m[2][2] = z;-
903 } else if (flagBits < Rotation2D) {
never executed: end of block
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
904 m[0][0] *= x;-
905 m[1][1] *= y;-
906 m[2][2] *= z;-
907 } else if (flagBits < Rotation) {
never executed: end of block
flagBits < RotationDescription
TRUEnever evaluated
FALSEnever evaluated
0
908 m[0][0] *= x;-
909 m[0][1] *= x;-
910 m[1][0] *= y;-
911 m[1][1] *= y;-
912 m[2][2] *= z;-
913 } else {
never executed: end of block
0
914 m[0][0] *= x;-
915 m[0][1] *= x;-
916 m[0][2] *= x;-
917 m[0][3] *= x;-
918 m[1][0] *= y;-
919 m[1][1] *= y;-
920 m[1][2] *= y;-
921 m[1][3] *= y;-
922 m[2][0] *= z;-
923 m[2][1] *= z;-
924 m[2][2] *= z;-
925 m[2][3] *= z;-
926 }
never executed: end of block
0
927 flagBits |= Scale;-
928}
never executed: end of block
0
929-
930/*!-
931 \overload-
932-
933 Multiplies this matrix by another that scales coordinates by the-
934 given \a factor.-
935-
936 \sa translate(), rotate()-
937*/-
938void QMatrix4x4::scale(float factor)-
939{-
940 if (flagBits < Scale) {
flagBits < ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
941 m[0][0] = factor;-
942 m[1][1] = factor;-
943 m[2][2] = factor;-
944 } else if (flagBits < Rotation2D) {
never executed: end of block
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
945 m[0][0] *= factor;-
946 m[1][1] *= factor;-
947 m[2][2] *= factor;-
948 } else if (flagBits < Rotation) {
never executed: end of block
flagBits < RotationDescription
TRUEnever evaluated
FALSEnever evaluated
0
949 m[0][0] *= factor;-
950 m[0][1] *= factor;-
951 m[1][0] *= factor;-
952 m[1][1] *= factor;-
953 m[2][2] *= factor;-
954 } else {
never executed: end of block
0
955 m[0][0] *= factor;-
956 m[0][1] *= factor;-
957 m[0][2] *= factor;-
958 m[0][3] *= factor;-
959 m[1][0] *= factor;-
960 m[1][1] *= factor;-
961 m[1][2] *= factor;-
962 m[1][3] *= factor;-
963 m[2][0] *= factor;-
964 m[2][1] *= factor;-
965 m[2][2] *= factor;-
966 m[2][3] *= factor;-
967 }
never executed: end of block
0
968 flagBits |= Scale;-
969}
never executed: end of block
0
970-
971#ifndef QT_NO_VECTOR3D-
972/*!-
973 Multiplies this matrix by another that translates coordinates by-
974 the components of \a vector.-
975-
976 \sa scale(), rotate()-
977*/-
978-
979void QMatrix4x4::translate(const QVector3D& vector)-
980{-
981 float vx = vector.x();-
982 float vy = vector.y();-
983 float vz = vector.z();-
984 if (flagBits == Identity) {
flagBits == IdentityDescription
TRUEnever evaluated
FALSEnever evaluated
0
985 m[3][0] = vx;-
986 m[3][1] = vy;-
987 m[3][2] = vz;-
988 } else if (flagBits == Translation) {
never executed: end of block
flagBits == TranslationDescription
TRUEnever evaluated
FALSEnever evaluated
0
989 m[3][0] += vx;-
990 m[3][1] += vy;-
991 m[3][2] += vz;-
992 } else if (flagBits == Scale) {
never executed: end of block
flagBits == ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
993 m[3][0] = m[0][0] * vx;-
994 m[3][1] = m[1][1] * vy;-
995 m[3][2] = m[2][2] * vz;-
996 } else if (flagBits == (Translation | Scale)) {
never executed: end of block
flagBits == (T...ation | Scale)Description
TRUEnever evaluated
FALSEnever evaluated
0
997 m[3][0] += m[0][0] * vx;-
998 m[3][1] += m[1][1] * vy;-
999 m[3][2] += m[2][2] * vz;-
1000 } else if (flagBits < Rotation) {
never executed: end of block
flagBits < RotationDescription
TRUEnever evaluated
FALSEnever evaluated
0
1001 m[3][0] += m[0][0] * vx + m[1][0] * vy;-
1002 m[3][1] += m[0][1] * vx + m[1][1] * vy;-
1003 m[3][2] += m[2][2] * vz;-
1004 } else {
never executed: end of block
0
1005 m[3][0] += m[0][0] * vx + m[1][0] * vy + m[2][0] * vz;-
1006 m[3][1] += m[0][1] * vx + m[1][1] * vy + m[2][1] * vz;-
1007 m[3][2] += m[0][2] * vx + m[1][2] * vy + m[2][2] * vz;-
1008 m[3][3] += m[0][3] * vx + m[1][3] * vy + m[2][3] * vz;-
1009 }
never executed: end of block
0
1010 flagBits |= Translation;-
1011}
never executed: end of block
0
1012#endif-
1013-
1014/*!-
1015 \overload-
1016-
1017 Multiplies this matrix by another that translates coordinates-
1018 by the components \a x, and \a y.-
1019-
1020 \sa scale(), rotate()-
1021*/-
1022void QMatrix4x4::translate(float x, float y)-
1023{-
1024 if (flagBits == Identity) {
flagBits == IdentityDescription
TRUEnever evaluated
FALSEnever evaluated
0
1025 m[3][0] = x;-
1026 m[3][1] = y;-
1027 } else if (flagBits == Translation) {
never executed: end of block
flagBits == TranslationDescription
TRUEnever evaluated
FALSEnever evaluated
0
1028 m[3][0] += x;-
1029 m[3][1] += y;-
1030 } else if (flagBits == Scale) {
never executed: end of block
flagBits == ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1031 m[3][0] = m[0][0] * x;-
1032 m[3][1] = m[1][1] * y;-
1033 } else if (flagBits == (Translation | Scale)) {
never executed: end of block
flagBits == (T...ation | Scale)Description
TRUEnever evaluated
FALSEnever evaluated
0
1034 m[3][0] += m[0][0] * x;-
1035 m[3][1] += m[1][1] * y;-
1036 } else if (flagBits < Rotation) {
never executed: end of block
flagBits < RotationDescription
TRUEnever evaluated
FALSEnever evaluated
0
1037 m[3][0] += m[0][0] * x + m[1][0] * y;-
1038 m[3][1] += m[0][1] * x + m[1][1] * y;-
1039 } else {
never executed: end of block
0
1040 m[3][0] += m[0][0] * x + m[1][0] * y;-
1041 m[3][1] += m[0][1] * x + m[1][1] * y;-
1042 m[3][2] += m[0][2] * x + m[1][2] * y;-
1043 m[3][3] += m[0][3] * x + m[1][3] * y;-
1044 }
never executed: end of block
0
1045 flagBits |= Translation;-
1046}
never executed: end of block
0
1047-
1048/*!-
1049 \overload-
1050-
1051 Multiplies this matrix by another that translates coordinates-
1052 by the components \a x, \a y, and \a z.-
1053-
1054 \sa scale(), rotate()-
1055*/-
1056void QMatrix4x4::translate(float x, float y, float z)-
1057{-
1058 if (flagBits == Identity) {
flagBits == IdentityDescription
TRUEnever evaluated
FALSEnever evaluated
0
1059 m[3][0] = x;-
1060 m[3][1] = y;-
1061 m[3][2] = z;-
1062 } else if (flagBits == Translation) {
never executed: end of block
flagBits == TranslationDescription
TRUEnever evaluated
FALSEnever evaluated
0
1063 m[3][0] += x;-
1064 m[3][1] += y;-
1065 m[3][2] += z;-
1066 } else if (flagBits == Scale) {
never executed: end of block
flagBits == ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1067 m[3][0] = m[0][0] * x;-
1068 m[3][1] = m[1][1] * y;-
1069 m[3][2] = m[2][2] * z;-
1070 } else if (flagBits == (Translation | Scale)) {
never executed: end of block
flagBits == (T...ation | Scale)Description
TRUEnever evaluated
FALSEnever evaluated
0
1071 m[3][0] += m[0][0] * x;-
1072 m[3][1] += m[1][1] * y;-
1073 m[3][2] += m[2][2] * z;-
1074 } else if (flagBits < Rotation) {
never executed: end of block
flagBits < RotationDescription
TRUEnever evaluated
FALSEnever evaluated
0
1075 m[3][0] += m[0][0] * x + m[1][0] * y;-
1076 m[3][1] += m[0][1] * x + m[1][1] * y;-
1077 m[3][2] += m[2][2] * z;-
1078 } else {
never executed: end of block
0
1079 m[3][0] += m[0][0] * x + m[1][0] * y + m[2][0] * z;-
1080 m[3][1] += m[0][1] * x + m[1][1] * y + m[2][1] * z;-
1081 m[3][2] += m[0][2] * x + m[1][2] * y + m[2][2] * z;-
1082 m[3][3] += m[0][3] * x + m[1][3] * y + m[2][3] * z;-
1083 }
never executed: end of block
0
1084 flagBits |= Translation;-
1085}
never executed: end of block
0
1086-
1087#ifndef QT_NO_VECTOR3D-
1088/*!-
1089 Multiples this matrix by another that rotates coordinates through-
1090 \a angle degrees about \a vector.-
1091-
1092 \sa scale(), translate()-
1093*/-
1094-
1095void QMatrix4x4::rotate(float angle, const QVector3D& vector)-
1096{-
1097 rotate(angle, vector.x(), vector.y(), vector.z());-
1098}
never executed: end of block
0
1099-
1100#endif-
1101-
1102/*!-
1103 \overload-
1104-
1105 Multiplies this matrix by another that rotates coordinates through-
1106 \a angle degrees about the vector (\a x, \a y, \a z).-
1107-
1108 \sa scale(), translate()-
1109*/-
1110void QMatrix4x4::rotate(float angle, float x, float y, float z)-
1111{-
1112 if (angle == 0.0f)
angle == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1113 return;
never executed: return;
0
1114 float c, s;-
1115 if (angle == 90.0f || angle == -270.0f) {
angle == 90.0fDescription
TRUEnever evaluated
FALSEnever evaluated
angle == -270.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1116 s = 1.0f;-
1117 c = 0.0f;-
1118 } else if (angle == -90.0f || angle == 270.0f) {
never executed: end of block
angle == -90.0fDescription
TRUEnever evaluated
FALSEnever evaluated
angle == 270.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1119 s = -1.0f;-
1120 c = 0.0f;-
1121 } else if (angle == 180.0f || angle == -180.0f) {
never executed: end of block
angle == 180.0fDescription
TRUEnever evaluated
FALSEnever evaluated
angle == -180.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1122 s = 0.0f;-
1123 c = -1.0f;-
1124 } else {
never executed: end of block
0
1125 float a = angle * M_PI / 180.0f;-
1126 c = std::cos(a);-
1127 s = std::sin(a);-
1128 }
never executed: end of block
0
1129 if (x == 0.0f) {
x == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1130 if (y == 0.0f) {
y == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1131 if (z != 0.0f) {
z != 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1132 // Rotate around the Z axis.-
1133 if (z < 0)
z < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1134 s = -s;
never executed: s = -s;
0
1135 float tmp;-
1136 m[0][0] = (tmp = m[0][0]) * c + m[1][0] * s;-
1137 m[1][0] = m[1][0] * c - tmp * s;-
1138 m[0][1] = (tmp = m[0][1]) * c + m[1][1] * s;-
1139 m[1][1] = m[1][1] * c - tmp * s;-
1140 m[0][2] = (tmp = m[0][2]) * c + m[1][2] * s;-
1141 m[1][2] = m[1][2] * c - tmp * s;-
1142 m[0][3] = (tmp = m[0][3]) * c + m[1][3] * s;-
1143 m[1][3] = m[1][3] * c - tmp * s;-
1144-
1145 flagBits |= Rotation2D;-
1146 return;
never executed: return;
0
1147 }-
1148 } else if (z == 0.0f) {
never executed: end of block
z == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1149 // Rotate around the Y axis.-
1150 if (y < 0)
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1151 s = -s;
never executed: s = -s;
0
1152 float tmp;-
1153 m[2][0] = (tmp = m[2][0]) * c + m[0][0] * s;-
1154 m[0][0] = m[0][0] * c - tmp * s;-
1155 m[2][1] = (tmp = m[2][1]) * c + m[0][1] * s;-
1156 m[0][1] = m[0][1] * c - tmp * s;-
1157 m[2][2] = (tmp = m[2][2]) * c + m[0][2] * s;-
1158 m[0][2] = m[0][2] * c - tmp * s;-
1159 m[2][3] = (tmp = m[2][3]) * c + m[0][3] * s;-
1160 m[0][3] = m[0][3] * c - tmp * s;-
1161-
1162 flagBits |= Rotation;-
1163 return;
never executed: return;
0
1164 }-
1165 } else if (y == 0.0f && z == 0.0f) {
never executed: end of block
y == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
z == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1166 // Rotate around the X axis.-
1167 if (x < 0)
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1168 s = -s;
never executed: s = -s;
0
1169 float tmp;-
1170 m[1][0] = (tmp = m[1][0]) * c + m[2][0] * s;-
1171 m[2][0] = m[2][0] * c - tmp * s;-
1172 m[1][1] = (tmp = m[1][1]) * c + m[2][1] * s;-
1173 m[2][1] = m[2][1] * c - tmp * s;-
1174 m[1][2] = (tmp = m[1][2]) * c + m[2][2] * s;-
1175 m[2][2] = m[2][2] * c - tmp * s;-
1176 m[1][3] = (tmp = m[1][3]) * c + m[2][3] * s;-
1177 m[2][3] = m[2][3] * c - tmp * s;-
1178-
1179 flagBits |= Rotation;-
1180 return;
never executed: return;
0
1181 }-
1182-
1183 double len = double(x) * double(x) +-
1184 double(y) * double(y) +-
1185 double(z) * double(z);-
1186 if (!qFuzzyCompare(len, 1.0) && !qFuzzyIsNull(len)) {
!qFuzzyCompare(len, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
!qFuzzyIsNull(len)Description
TRUEnever evaluated
FALSEnever evaluated
0
1187 len = std::sqrt(len);-
1188 x = float(double(x) / len);-
1189 y = float(double(y) / len);-
1190 z = float(double(z) / len);-
1191 }
never executed: end of block
0
1192 float ic = 1.0f - c;-
1193 QMatrix4x4 rot(1); // The "1" says to not load the identity.-
1194 rot.m[0][0] = x * x * ic + c;-
1195 rot.m[1][0] = x * y * ic - z * s;-
1196 rot.m[2][0] = x * z * ic + y * s;-
1197 rot.m[3][0] = 0.0f;-
1198 rot.m[0][1] = y * x * ic + z * s;-
1199 rot.m[1][1] = y * y * ic + c;-
1200 rot.m[2][1] = y * z * ic - x * s;-
1201 rot.m[3][1] = 0.0f;-
1202 rot.m[0][2] = x * z * ic - y * s;-
1203 rot.m[1][2] = y * z * ic + x * s;-
1204 rot.m[2][2] = z * z * ic + c;-
1205 rot.m[3][2] = 0.0f;-
1206 rot.m[0][3] = 0.0f;-
1207 rot.m[1][3] = 0.0f;-
1208 rot.m[2][3] = 0.0f;-
1209 rot.m[3][3] = 1.0f;-
1210 rot.flagBits = Rotation;-
1211 *this *= rot;-
1212}
never executed: end of block
0
1213-
1214/*!-
1215 \internal-
1216*/-
1217void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)-
1218{-
1219 // Used by QGraphicsRotation::applyTo() to perform a rotation-
1220 // and projection back to 2D in a single step.-
1221 if (angle == 0.0f)
angle == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1222 return;
never executed: return;
0
1223 float c, s;-
1224 if (angle == 90.0f || angle == -270.0f) {
angle == 90.0fDescription
TRUEnever evaluated
FALSEnever evaluated
angle == -270.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1225 s = 1.0f;-
1226 c = 0.0f;-
1227 } else if (angle == -90.0f || angle == 270.0f) {
never executed: end of block
angle == -90.0fDescription
TRUEnever evaluated
FALSEnever evaluated
angle == 270.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1228 s = -1.0f;-
1229 c = 0.0f;-
1230 } else if (angle == 180.0f || angle == -180.0f) {
never executed: end of block
angle == 180.0fDescription
TRUEnever evaluated
FALSEnever evaluated
angle == -180.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1231 s = 0.0f;-
1232 c = -1.0f;-
1233 } else {
never executed: end of block
0
1234 float a = angle * M_PI / 180.0f;-
1235 c = std::cos(a);-
1236 s = std::sin(a);-
1237 }
never executed: end of block
0
1238 if (x == 0.0f) {
x == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1239 if (y == 0.0f) {
y == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1240 if (z != 0.0f) {
z != 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1241 // Rotate around the Z axis.-
1242 if (z < 0)
z < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1243 s = -s;
never executed: s = -s;
0
1244 float tmp;-
1245 m[0][0] = (tmp = m[0][0]) * c + m[1][0] * s;-
1246 m[1][0] = m[1][0] * c - tmp * s;-
1247 m[0][1] = (tmp = m[0][1]) * c + m[1][1] * s;-
1248 m[1][1] = m[1][1] * c - tmp * s;-
1249 m[0][2] = (tmp = m[0][2]) * c + m[1][2] * s;-
1250 m[1][2] = m[1][2] * c - tmp * s;-
1251 m[0][3] = (tmp = m[0][3]) * c + m[1][3] * s;-
1252 m[1][3] = m[1][3] * c - tmp * s;-
1253-
1254 flagBits |= Rotation2D;-
1255 return;
never executed: return;
0
1256 }-
1257 } else if (z == 0.0f) {
never executed: end of block
z == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1258 // Rotate around the Y axis.-
1259 if (y < 0)
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1260 s = -s;
never executed: s = -s;
0
1261 m[0][0] = m[0][0] * c + m[3][0] * s * inv_dist_to_plane;-
1262 m[0][1] = m[0][1] * c + m[3][1] * s * inv_dist_to_plane;-
1263 m[0][2] = m[0][2] * c + m[3][2] * s * inv_dist_to_plane;-
1264 m[0][3] = m[0][3] * c + m[3][3] * s * inv_dist_to_plane;-
1265 flagBits = General;-
1266 return;
never executed: return;
0
1267 }-
1268 } else if (y == 0.0f && z == 0.0f) {
never executed: end of block
y == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
z == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1269 // Rotate around the X axis.-
1270 if (x < 0)
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1271 s = -s;
never executed: s = -s;
0
1272 m[1][0] = m[1][0] * c - m[3][0] * s * inv_dist_to_plane;-
1273 m[1][1] = m[1][1] * c - m[3][1] * s * inv_dist_to_plane;-
1274 m[1][2] = m[1][2] * c - m[3][2] * s * inv_dist_to_plane;-
1275 m[1][3] = m[1][3] * c - m[3][3] * s * inv_dist_to_plane;-
1276 flagBits = General;-
1277 return;
never executed: return;
0
1278 }-
1279 double len = double(x) * double(x) +-
1280 double(y) * double(y) +-
1281 double(z) * double(z);-
1282 if (!qFuzzyCompare(len, 1.0) && !qFuzzyIsNull(len)) {
!qFuzzyCompare(len, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
!qFuzzyIsNull(len)Description
TRUEnever evaluated
FALSEnever evaluated
0
1283 len = std::sqrt(len);-
1284 x = float(double(x) / len);-
1285 y = float(double(y) / len);-
1286 z = float(double(z) / len);-
1287 }
never executed: end of block
0
1288 float ic = 1.0f - c;-
1289 QMatrix4x4 rot(1); // The "1" says to not load the identity.-
1290 rot.m[0][0] = x * x * ic + c;-
1291 rot.m[1][0] = x * y * ic - z * s;-
1292 rot.m[2][0] = 0.0f;-
1293 rot.m[3][0] = 0.0f;-
1294 rot.m[0][1] = y * x * ic + z * s;-
1295 rot.m[1][1] = y * y * ic + c;-
1296 rot.m[2][1] = 0.0f;-
1297 rot.m[3][1] = 0.0f;-
1298 rot.m[0][2] = 0.0f;-
1299 rot.m[1][2] = 0.0f;-
1300 rot.m[2][2] = 1.0f;-
1301 rot.m[3][2] = 0.0f;-
1302 rot.m[0][3] = (x * z * ic - y * s) * -inv_dist_to_plane;-
1303 rot.m[1][3] = (y * z * ic + x * s) * -inv_dist_to_plane;-
1304 rot.m[2][3] = 0.0f;-
1305 rot.m[3][3] = 1.0f;-
1306 rot.flagBits = General;-
1307 *this *= rot;-
1308}
never executed: end of block
0
1309-
1310#ifndef QT_NO_QUATERNION-
1311-
1312/*!-
1313 Multiples this matrix by another that rotates coordinates according-
1314 to a specified \a quaternion. The \a quaternion is assumed to have-
1315 been normalized.-
1316-
1317 \sa scale(), translate(), QQuaternion-
1318*/-
1319void QMatrix4x4::rotate(const QQuaternion& quaternion)-
1320{-
1321 // Algorithm from:-
1322 // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54-
1323-
1324 QMatrix4x4 m(Qt::Uninitialized);-
1325-
1326 const float f2x = quaternion.x() + quaternion.x();-
1327 const float f2y = quaternion.y() + quaternion.y();-
1328 const float f2z = quaternion.z() + quaternion.z();-
1329 const float f2xw = f2x * quaternion.scalar();-
1330 const float f2yw = f2y * quaternion.scalar();-
1331 const float f2zw = f2z * quaternion.scalar();-
1332 const float f2xx = f2x * quaternion.x();-
1333 const float f2xy = f2x * quaternion.y();-
1334 const float f2xz = f2x * quaternion.z();-
1335 const float f2yy = f2y * quaternion.y();-
1336 const float f2yz = f2y * quaternion.z();-
1337 const float f2zz = f2z * quaternion.z();-
1338-
1339 m.m[0][0] = 1.0f - (f2yy + f2zz);-
1340 m.m[1][0] = f2xy - f2zw;-
1341 m.m[2][0] = f2xz + f2yw;-
1342 m.m[3][0] = 0.0f;-
1343 m.m[0][1] = f2xy + f2zw;-
1344 m.m[1][1] = 1.0f - (f2xx + f2zz);-
1345 m.m[2][1] = f2yz - f2xw;-
1346 m.m[3][1] = 0.0f;-
1347 m.m[0][2] = f2xz - f2yw;-
1348 m.m[1][2] = f2yz + f2xw;-
1349 m.m[2][2] = 1.0f - (f2xx + f2yy);-
1350 m.m[3][2] = 0.0f;-
1351 m.m[0][3] = 0.0f;-
1352 m.m[1][3] = 0.0f;-
1353 m.m[2][3] = 0.0f;-
1354 m.m[3][3] = 1.0f;-
1355 m.flagBits = Rotation;-
1356 *this *= m;-
1357}
never executed: end of block
0
1358-
1359#endif-
1360-
1361/*!-
1362 \overload-
1363-
1364 Multiplies this matrix by another that applies an orthographic-
1365 projection for a window with boundaries specified by \a rect.-
1366 The near and far clipping planes will be -1 and 1 respectively.-
1367-
1368 \sa frustum(), perspective()-
1369*/-
1370void QMatrix4x4::ortho(const QRect& rect)-
1371{-
1372 // Note: rect.right() and rect.bottom() subtract 1 in QRect,-
1373 // which gives the location of a pixel within the rectangle,-
1374 // instead of the extent of the rectangle. We want the extent.-
1375 // QRectF expresses the extent properly.-
1376 ortho(rect.x(), rect.x() + rect.width(), rect.y() + rect.height(), rect.y(), -1.0f, 1.0f);-
1377}
never executed: end of block
0
1378-
1379/*!-
1380 \overload-
1381-
1382 Multiplies this matrix by another that applies an orthographic-
1383 projection for a window with boundaries specified by \a rect.-
1384 The near and far clipping planes will be -1 and 1 respectively.-
1385-
1386 \sa frustum(), perspective()-
1387*/-
1388void QMatrix4x4::ortho(const QRectF& rect)-
1389{-
1390 ortho(rect.left(), rect.right(), rect.bottom(), rect.top(), -1.0f, 1.0f);-
1391}
never executed: end of block
0
1392-
1393/*!-
1394 Multiplies this matrix by another that applies an orthographic-
1395 projection for a window with lower-left corner (\a left, \a bottom),-
1396 upper-right corner (\a right, \a top), and the specified \a nearPlane-
1397 and \a farPlane clipping planes.-
1398-
1399 \sa frustum(), perspective()-
1400*/-
1401void QMatrix4x4::ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane)-
1402{-
1403 // Bail out if the projection volume is zero-sized.-
1404 if (left == right || bottom == top || nearPlane == farPlane)
left == rightDescription
TRUEnever evaluated
FALSEnever evaluated
bottom == topDescription
TRUEnever evaluated
FALSEnever evaluated
nearPlane == farPlaneDescription
TRUEnever evaluated
FALSEnever evaluated
0
1405 return;
never executed: return;
0
1406-
1407 // Construct the projection.-
1408 float width = right - left;-
1409 float invheight = top - bottom;-
1410 float clip = farPlane - nearPlane;-
1411 QMatrix4x4 m(1);-
1412 m.m[0][0] = 2.0f / width;-
1413 m.m[1][0] = 0.0f;-
1414 m.m[2][0] = 0.0f;-
1415 m.m[3][0] = -(left + right) / width;-
1416 m.m[0][1] = 0.0f;-
1417 m.m[1][1] = 2.0f / invheight;-
1418 m.m[2][1] = 0.0f;-
1419 m.m[3][1] = -(top + bottom) / invheight;-
1420 m.m[0][2] = 0.0f;-
1421 m.m[1][2] = 0.0f;-
1422 m.m[2][2] = -2.0f / clip;-
1423 m.m[3][2] = -(nearPlane + farPlane) / clip;-
1424 m.m[0][3] = 0.0f;-
1425 m.m[1][3] = 0.0f;-
1426 m.m[2][3] = 0.0f;-
1427 m.m[3][3] = 1.0f;-
1428 m.flagBits = Translation | Scale;-
1429-
1430 // Apply the projection.-
1431 *this *= m;-
1432}
never executed: end of block
0
1433-
1434/*!-
1435 Multiplies this matrix by another that applies a perspective-
1436 frustum projection for a window with lower-left corner (\a left, \a bottom),-
1437 upper-right corner (\a right, \a top), and the specified \a nearPlane-
1438 and \a farPlane clipping planes.-
1439-
1440 \sa ortho(), perspective()-
1441*/-
1442void QMatrix4x4::frustum(float left, float right, float bottom, float top, float nearPlane, float farPlane)-
1443{-
1444 // Bail out if the projection volume is zero-sized.-
1445 if (left == right || bottom == top || nearPlane == farPlane)
left == rightDescription
TRUEnever evaluated
FALSEnever evaluated
bottom == topDescription
TRUEnever evaluated
FALSEnever evaluated
nearPlane == farPlaneDescription
TRUEnever evaluated
FALSEnever evaluated
0
1446 return;
never executed: return;
0
1447-
1448 // Construct the projection.-
1449 QMatrix4x4 m(1);-
1450 float width = right - left;-
1451 float invheight = top - bottom;-
1452 float clip = farPlane - nearPlane;-
1453 m.m[0][0] = 2.0f * nearPlane / width;-
1454 m.m[1][0] = 0.0f;-
1455 m.m[2][0] = (left + right) / width;-
1456 m.m[3][0] = 0.0f;-
1457 m.m[0][1] = 0.0f;-
1458 m.m[1][1] = 2.0f * nearPlane / invheight;-
1459 m.m[2][1] = (top + bottom) / invheight;-
1460 m.m[3][1] = 0.0f;-
1461 m.m[0][2] = 0.0f;-
1462 m.m[1][2] = 0.0f;-
1463 m.m[2][2] = -(nearPlane + farPlane) / clip;-
1464 m.m[3][2] = -2.0f * nearPlane * farPlane / clip;-
1465 m.m[0][3] = 0.0f;-
1466 m.m[1][3] = 0.0f;-
1467 m.m[2][3] = -1.0f;-
1468 m.m[3][3] = 0.0f;-
1469 m.flagBits = General;-
1470-
1471 // Apply the projection.-
1472 *this *= m;-
1473}
never executed: end of block
0
1474-
1475/*!-
1476 Multiplies this matrix by another that applies a perspective-
1477 projection. The vertical field of view will be \a verticalAngle degrees-
1478 within a window with a given \a aspectRatio that determines the horizontal-
1479 field of view.-
1480 The projection will have the specified \a nearPlane and \a farPlane clipping-
1481 planes which are the distances from the viewer to the corresponding planes.-
1482-
1483 \sa ortho(), frustum()-
1484*/-
1485void QMatrix4x4::perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane)-
1486{-
1487 // Bail out if the projection volume is zero-sized.-
1488 if (nearPlane == farPlane || aspectRatio == 0.0f)
nearPlane == farPlaneDescription
TRUEnever evaluated
FALSEnever evaluated
aspectRatio == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1489 return;
never executed: return;
0
1490-
1491 // Construct the projection.-
1492 QMatrix4x4 m(1);-
1493 float radians = (verticalAngle / 2.0f) * M_PI / 180.0f;-
1494 float sine = std::sin(radians);-
1495 if (sine == 0.0f)
sine == 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1496 return;
never executed: return;
0
1497 float cotan = std::cos(radians) / sine;-
1498 float clip = farPlane - nearPlane;-
1499 m.m[0][0] = cotan / aspectRatio;-
1500 m.m[1][0] = 0.0f;-
1501 m.m[2][0] = 0.0f;-
1502 m.m[3][0] = 0.0f;-
1503 m.m[0][1] = 0.0f;-
1504 m.m[1][1] = cotan;-
1505 m.m[2][1] = 0.0f;-
1506 m.m[3][1] = 0.0f;-
1507 m.m[0][2] = 0.0f;-
1508 m.m[1][2] = 0.0f;-
1509 m.m[2][2] = -(nearPlane + farPlane) / clip;-
1510 m.m[3][2] = -(2.0f * nearPlane * farPlane) / clip;-
1511 m.m[0][3] = 0.0f;-
1512 m.m[1][3] = 0.0f;-
1513 m.m[2][3] = -1.0f;-
1514 m.m[3][3] = 0.0f;-
1515 m.flagBits = General;-
1516-
1517 // Apply the projection.-
1518 *this *= m;-
1519}
never executed: end of block
0
1520-
1521#ifndef QT_NO_VECTOR3D-
1522-
1523/*!-
1524 Multiplies this matrix by a viewing matrix derived from an eye-
1525 point. The \a center value indicates the center of the view that-
1526 the \a eye is looking at. The \a up value indicates which direction-
1527 should be considered up with respect to the \a eye.-
1528-
1529 \note The \a up vector must not be parallel to the line of sight-
1530 from \a eye to \a center.-
1531*/-
1532void QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up)-
1533{-
1534 QVector3D forward = center - eye;-
1535 if (qFuzzyIsNull(forward.x()) && qFuzzyIsNull(forward.y()) && qFuzzyIsNull(forward.z()))
qFuzzyIsNull(forward.x())Description
TRUEnever evaluated
FALSEnever evaluated
qFuzzyIsNull(forward.y())Description
TRUEnever evaluated
FALSEnever evaluated
qFuzzyIsNull(forward.z())Description
TRUEnever evaluated
FALSEnever evaluated
0
1536 return;
never executed: return;
0
1537-
1538 forward.normalize();-
1539 QVector3D side = QVector3D::crossProduct(forward, up).normalized();-
1540 QVector3D upVector = QVector3D::crossProduct(side, forward);-
1541-
1542 QMatrix4x4 m(1);-
1543 m.m[0][0] = side.x();-
1544 m.m[1][0] = side.y();-
1545 m.m[2][0] = side.z();-
1546 m.m[3][0] = 0.0f;-
1547 m.m[0][1] = upVector.x();-
1548 m.m[1][1] = upVector.y();-
1549 m.m[2][1] = upVector.z();-
1550 m.m[3][1] = 0.0f;-
1551 m.m[0][2] = -forward.x();-
1552 m.m[1][2] = -forward.y();-
1553 m.m[2][2] = -forward.z();-
1554 m.m[3][2] = 0.0f;-
1555 m.m[0][3] = 0.0f;-
1556 m.m[1][3] = 0.0f;-
1557 m.m[2][3] = 0.0f;-
1558 m.m[3][3] = 1.0f;-
1559 m.flagBits = Rotation;-
1560-
1561 *this *= m;-
1562 translate(-eye);-
1563}
never executed: end of block
0
1564-
1565#endif-
1566-
1567/*!-
1568 \fn void QMatrix4x4::viewport(const QRectF &rect)-
1569 \overload-
1570-
1571 Sets up viewport transform for viewport bounded by \a rect and with near and far set-
1572 to 0 and 1 respectively.-
1573*/-
1574-
1575/*!-
1576 Multiplies this matrix by another that performs the scale and bias-
1577 transformation used by OpenGL to transform from normalized device-
1578 coordinates (NDC) to viewport (window) coordinates. That is it maps-
1579 points from the cube ranging over [-1, 1] in each dimension to the-
1580 viewport with it's near-lower-left corner at (\a left, \a bottom, \a nearPlane)-
1581 and with size (\a width, \a height, \a farPlane - \a nearPlane).-
1582-
1583 This matches the transform used by the fixed function OpenGL viewport-
1584 transform controlled by the functions glViewport() and glDepthRange().-
1585 */-
1586void QMatrix4x4::viewport(float left, float bottom, float width, float height, float nearPlane, float farPlane)-
1587{-
1588 const float w2 = width / 2.0f;-
1589 const float h2 = height / 2.0f;-
1590-
1591 QMatrix4x4 m(1);-
1592 m.m[0][0] = w2;-
1593 m.m[1][0] = 0.0f;-
1594 m.m[2][0] = 0.0f;-
1595 m.m[3][0] = left + w2;-
1596 m.m[0][1] = 0.0f;-
1597 m.m[1][1] = h2;-
1598 m.m[2][1] = 0.0f;-
1599 m.m[3][1] = bottom + h2;-
1600 m.m[0][2] = 0.0f;-
1601 m.m[1][2] = 0.0f;-
1602 m.m[2][2] = (farPlane - nearPlane) / 2.0f;-
1603 m.m[3][2] = (nearPlane + farPlane) / 2.0f;-
1604 m.m[0][3] = 0.0f;-
1605 m.m[1][3] = 0.0f;-
1606 m.m[2][3] = 0.0f;-
1607 m.m[3][3] = 1.0f;-
1608 m.flagBits = General;-
1609-
1610 *this *= m;-
1611}
never executed: end of block
0
1612-
1613/*!-
1614 \deprecated-
1615-
1616 Flips between right-handed and left-handed coordinate systems-
1617 by multiplying the y and z co-ordinates by -1. This is normally-
1618 used to create a left-handed orthographic view without scaling-
1619 the viewport as ortho() does.-
1620-
1621 \sa ortho()-
1622*/-
1623void QMatrix4x4::flipCoordinates()-
1624{-
1625 // Multiplying the y and z coordinates with -1 does NOT flip between right-handed and-
1626 // left-handed coordinate systems, it just rotates 180 degrees around the x axis, so-
1627 // I'm deprecating this function.-
1628 if (flagBits < Rotation2D) {
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
1629 // Translation | Scale-
1630 m[1][1] = -m[1][1];-
1631 m[2][2] = -m[2][2];-
1632 } else {
never executed: end of block
0
1633 m[1][0] = -m[1][0];-
1634 m[1][1] = -m[1][1];-
1635 m[1][2] = -m[1][2];-
1636 m[1][3] = -m[1][3];-
1637 m[2][0] = -m[2][0];-
1638 m[2][1] = -m[2][1];-
1639 m[2][2] = -m[2][2];-
1640 m[2][3] = -m[2][3];-
1641 }
never executed: end of block
0
1642 flagBits |= Scale;-
1643}
never executed: end of block
0
1644-
1645/*!-
1646 Retrieves the 16 items in this matrix and copies them to \a values-
1647 in row-major order.-
1648*/-
1649void QMatrix4x4::copyDataTo(float *values) const-
1650{-
1651 for (int row = 0; row < 4; ++row)
row < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
1652 for (int col = 0; col < 4; ++col)
col < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
1653 values[row * 4 + col] = float(m[col][row]);
never executed: values[row * 4 + col] = float(m[col][row]);
0
1654}
never executed: end of block
0
1655-
1656/*!-
1657 Returns the conventional Qt 2D affine transformation matrix that-
1658 corresponds to this matrix. It is assumed that this matrix-
1659 only contains 2D affine transformation elements.-
1660-
1661 \sa toTransform()-
1662*/-
1663QMatrix QMatrix4x4::toAffine() const-
1664{-
1665 return QMatrix(m[0][0], m[0][1],
never executed: return QMatrix(m[0][0], m[0][1], m[1][0], m[1][1], m[3][0], m[3][1]);
0
1666 m[1][0], m[1][1],
never executed: return QMatrix(m[0][0], m[0][1], m[1][0], m[1][1], m[3][0], m[3][1]);
0
1667 m[3][0], m[3][1]);
never executed: return QMatrix(m[0][0], m[0][1], m[1][0], m[1][1], m[3][0], m[3][1]);
0
1668}-
1669-
1670/*!-
1671 Returns the conventional Qt 2D transformation matrix that-
1672 corresponds to this matrix.-
1673-
1674 The returned QTransform is formed by simply dropping the-
1675 third row and third column of the QMatrix4x4. This is suitable-
1676 for implementing orthographic projections where the z co-ordinate-
1677 should be dropped rather than projected.-
1678-
1679 \sa toAffine()-
1680*/-
1681QTransform QMatrix4x4::toTransform() const-
1682{-
1683 return QTransform(m[0][0], m[0][1], m[0][3],
never executed: return QTransform(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[3][0], m[3][1], m[3][3]);
0
1684 m[1][0], m[1][1], m[1][3],
never executed: return QTransform(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[3][0], m[3][1], m[3][3]);
0
1685 m[3][0], m[3][1], m[3][3]);
never executed: return QTransform(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[3][0], m[3][1], m[3][3]);
0
1686}-
1687-
1688/*!-
1689 Returns the conventional Qt 2D transformation matrix that-
1690 corresponds to this matrix.-
1691-
1692 If \a distanceToPlane is non-zero, it indicates a projection-
1693 factor to use to adjust for the z co-ordinate. The value of-
1694 1024 corresponds to the projection factor used-
1695 by QTransform::rotate() for the x and y axes.-
1696-
1697 If \a distanceToPlane is zero, then the returned QTransform-
1698 is formed by simply dropping the third row and third column-
1699 of the QMatrix4x4. This is suitable for implementing-
1700 orthographic projections where the z co-ordinate should-
1701 be dropped rather than projected.-
1702-
1703 \sa toAffine()-
1704*/-
1705QTransform QMatrix4x4::toTransform(float distanceToPlane) const-
1706{-
1707 if (distanceToPlane == 1024.0f) {
distanceToPlane == 1024.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1708 // Optimize the common case with constants.-
1709 return QTransform(m[0][0], m[0][1], m[0][3] - m[0][2] * inv_dist_to_plane,
never executed: return QTransform(m[0][0], m[0][1], m[0][3] - m[0][2] * inv_dist_to_plane, m[1][0], m[1][1], m[1][3] - m[1][2] * inv_dist_to_plane, m[3][0], m[3][1], m[3][3] - m[3][2] * inv_dist_to_plane);
0
1710 m[1][0], m[1][1], m[1][3] - m[1][2] * inv_dist_to_plane,
never executed: return QTransform(m[0][0], m[0][1], m[0][3] - m[0][2] * inv_dist_to_plane, m[1][0], m[1][1], m[1][3] - m[1][2] * inv_dist_to_plane, m[3][0], m[3][1], m[3][3] - m[3][2] * inv_dist_to_plane);
0
1711 m[3][0], m[3][1], m[3][3] - m[3][2] * inv_dist_to_plane);
never executed: return QTransform(m[0][0], m[0][1], m[0][3] - m[0][2] * inv_dist_to_plane, m[1][0], m[1][1], m[1][3] - m[1][2] * inv_dist_to_plane, m[3][0], m[3][1], m[3][3] - m[3][2] * inv_dist_to_plane);
0
1712 } else if (distanceToPlane != 0.0f) {
distanceToPlane != 0.0fDescription
TRUEnever evaluated
FALSEnever evaluated
0
1713 // The following projection matrix is pre-multiplied with "matrix":-
1714 // | 1 0 0 0 |-
1715 // | 0 1 0 0 |-
1716 // | 0 0 1 0 |-
1717 // | 0 0 d 1 |-
1718 // where d = -1 / distanceToPlane. After projection, row 3 and-
1719 // column 3 are dropped to form the final QTransform.-
1720 float d = 1.0f / distanceToPlane;-
1721 return QTransform(m[0][0], m[0][1], m[0][3] - m[0][2] * d,
never executed: return QTransform(m[0][0], m[0][1], m[0][3] - m[0][2] * d, m[1][0], m[1][1], m[1][3] - m[1][2] * d, m[3][0], m[3][1], m[3][3] - m[3][2] * d);
0
1722 m[1][0], m[1][1], m[1][3] - m[1][2] * d,
never executed: return QTransform(m[0][0], m[0][1], m[0][3] - m[0][2] * d, m[1][0], m[1][1], m[1][3] - m[1][2] * d, m[3][0], m[3][1], m[3][3] - m[3][2] * d);
0
1723 m[3][0], m[3][1], m[3][3] - m[3][2] * d);
never executed: return QTransform(m[0][0], m[0][1], m[0][3] - m[0][2] * d, m[1][0], m[1][1], m[1][3] - m[1][2] * d, m[3][0], m[3][1], m[3][3] - m[3][2] * d);
0
1724 } else {-
1725 // Orthographic projection: drop row 3 and column 3.-
1726 return QTransform(m[0][0], m[0][1], m[0][3],
never executed: return QTransform(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[3][0], m[3][1], m[3][3]);
0
1727 m[1][0], m[1][1], m[1][3],
never executed: return QTransform(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[3][0], m[3][1], m[3][3]);
0
1728 m[3][0], m[3][1], m[3][3]);
never executed: return QTransform(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[3][0], m[3][1], m[3][3]);
0
1729 }-
1730}-
1731-
1732/*!-
1733 \fn QPoint QMatrix4x4::map(const QPoint& point) const-
1734-
1735 Maps \a point by multiplying this matrix by \a point.-
1736-
1737 \sa mapRect()-
1738*/-
1739-
1740/*!-
1741 \fn QPointF QMatrix4x4::map(const QPointF& point) const-
1742-
1743 Maps \a point by multiplying this matrix by \a point.-
1744-
1745 \sa mapRect()-
1746*/-
1747-
1748#ifndef QT_NO_VECTOR3D-
1749-
1750/*!-
1751 \fn QVector3D QMatrix4x4::map(const QVector3D& point) const-
1752-
1753 Maps \a point by multiplying this matrix by \a point.-
1754-
1755 \sa mapRect(), mapVector()-
1756*/-
1757-
1758/*!-
1759 \fn QVector3D QMatrix4x4::mapVector(const QVector3D& vector) const-
1760-
1761 Maps \a vector by multiplying the top 3x3 portion of this matrix-
1762 by \a vector. The translation and projection components of-
1763 this matrix are ignored.-
1764-
1765 \sa map()-
1766*/-
1767-
1768#endif-
1769-
1770#ifndef QT_NO_VECTOR4D-
1771-
1772/*!-
1773 \fn QVector4D QMatrix4x4::map(const QVector4D& point) const;-
1774-
1775 Maps \a point by multiplying this matrix by \a point.-
1776-
1777 \sa mapRect()-
1778*/-
1779-
1780#endif-
1781-
1782/*!-
1783 Maps \a rect by multiplying this matrix by the corners-
1784 of \a rect and then forming a new rectangle from the results.-
1785 The returned rectangle will be an ordinary 2D rectangle-
1786 with sides parallel to the horizontal and vertical axes.-
1787-
1788 \sa map()-
1789*/-
1790QRect QMatrix4x4::mapRect(const QRect& rect) const-
1791{-
1792 if (flagBits < Scale) {
flagBits < ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1793 // Translation-
1794 return QRect(qRound(rect.x() + m[3][0]),
never executed: return QRect(qRound(rect.x() + m[3][0]), qRound(rect.y() + m[3][1]), rect.width(), rect.height());
0
1795 qRound(rect.y() + m[3][1]),
never executed: return QRect(qRound(rect.x() + m[3][0]), qRound(rect.y() + m[3][1]), rect.width(), rect.height());
0
1796 rect.width(), rect.height());
never executed: return QRect(qRound(rect.x() + m[3][0]), qRound(rect.y() + m[3][1]), rect.width(), rect.height());
0
1797 } else if (flagBits < Rotation2D) {
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
1798 // Translation | Scale-
1799 float x = rect.x() * m[0][0] + m[3][0];-
1800 float y = rect.y() * m[1][1] + m[3][1];-
1801 float w = rect.width() * m[0][0];-
1802 float h = rect.height() * m[1][1];-
1803 if (w < 0) {
w < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1804 w = -w;-
1805 x -= w;-
1806 }
never executed: end of block
0
1807 if (h < 0) {
h < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1808 h = -h;-
1809 y -= h;-
1810 }
never executed: end of block
0
1811 return QRect(qRound(x), qRound(y), qRound(w), qRound(h));
never executed: return QRect(qRound(x), qRound(y), qRound(w), qRound(h));
0
1812 }-
1813-
1814 QPoint tl = map(rect.topLeft());-
1815 QPoint tr = map(QPoint(rect.x() + rect.width(), rect.y()));-
1816 QPoint bl = map(QPoint(rect.x(), rect.y() + rect.height()));-
1817 QPoint br = map(QPoint(rect.x() + rect.width(),-
1818 rect.y() + rect.height()));-
1819-
1820 int xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));-
1821 int xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));-
1822 int ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));-
1823 int ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));-
1824-
1825 return QRect(xmin, ymin, xmax - xmin, ymax - ymin);
never executed: return QRect(xmin, ymin, xmax - xmin, ymax - ymin);
0
1826}-
1827-
1828/*!-
1829 Maps \a rect by multiplying this matrix by the corners-
1830 of \a rect and then forming a new rectangle from the results.-
1831 The returned rectangle will be an ordinary 2D rectangle-
1832 with sides parallel to the horizontal and vertical axes.-
1833-
1834 \sa map()-
1835*/-
1836QRectF QMatrix4x4::mapRect(const QRectF& rect) const-
1837{-
1838 if (flagBits < Scale) {
flagBits < ScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1839 // Translation-
1840 return rect.translated(m[3][0], m[3][1]);
never executed: return rect.translated(m[3][0], m[3][1]);
0
1841 } else if (flagBits < Rotation2D) {
flagBits < Rotation2DDescription
TRUEnever evaluated
FALSEnever evaluated
0
1842 // Translation | Scale-
1843 float x = rect.x() * m[0][0] + m[3][0];-
1844 float y = rect.y() * m[1][1] + m[3][1];-
1845 float w = rect.width() * m[0][0];-
1846 float h = rect.height() * m[1][1];-
1847 if (w < 0) {
w < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1848 w = -w;-
1849 x -= w;-
1850 }
never executed: end of block
0
1851 if (h < 0) {
h < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1852 h = -h;-
1853 y -= h;-
1854 }
never executed: end of block
0
1855 return QRectF(x, y, w, h);
never executed: return QRectF(x, y, w, h);
0
1856 }-
1857-
1858 QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());-
1859 QPointF bl = map(rect.bottomLeft()); QPointF br = map(rect.bottomRight());-
1860-
1861 float xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));-
1862 float xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));-
1863 float ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));-
1864 float ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));-
1865-
1866 return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
never executed: return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
0
1867}-
1868-
1869/*!-
1870 \fn float *QMatrix4x4::data()-
1871-
1872 Returns a pointer to the raw data of this matrix.-
1873-
1874 \sa constData(), optimize()-
1875*/-
1876-
1877/*!-
1878 \fn const float *QMatrix4x4::data() const-
1879-
1880 Returns a constant pointer to the raw data of this matrix.-
1881 This raw data is stored in column-major format.-
1882-
1883 \sa constData()-
1884*/-
1885-
1886/*!-
1887 \fn const float *QMatrix4x4::constData() const-
1888-
1889 Returns a constant pointer to the raw data of this matrix.-
1890 This raw data is stored in column-major format.-
1891-
1892 \sa data()-
1893*/-
1894-
1895// Helper routine for inverting orthonormal matrices that consist-
1896// of just rotations and translations.-
1897QMatrix4x4 QMatrix4x4::orthonormalInverse() const-
1898{-
1899 QMatrix4x4 result(1); // The '1' says not to load identity-
1900-
1901 result.m[0][0] = m[0][0];-
1902 result.m[1][0] = m[0][1];-
1903 result.m[2][0] = m[0][2];-
1904-
1905 result.m[0][1] = m[1][0];-
1906 result.m[1][1] = m[1][1];-
1907 result.m[2][1] = m[1][2];-
1908-
1909 result.m[0][2] = m[2][0];-
1910 result.m[1][2] = m[2][1];-
1911 result.m[2][2] = m[2][2];-
1912-
1913 result.m[0][3] = 0.0f;-
1914 result.m[1][3] = 0.0f;-
1915 result.m[2][3] = 0.0f;-
1916-
1917 result.m[3][0] = -(result.m[0][0] * m[3][0] + result.m[1][0] * m[3][1] + result.m[2][0] * m[3][2]);-
1918 result.m[3][1] = -(result.m[0][1] * m[3][0] + result.m[1][1] * m[3][1] + result.m[2][1] * m[3][2]);-
1919 result.m[3][2] = -(result.m[0][2] * m[3][0] + result.m[1][2] * m[3][1] + result.m[2][2] * m[3][2]);-
1920 result.m[3][3] = 1.0f;-
1921-
1922 result.flagBits = flagBits;-
1923-
1924 return result;
never executed: return result;
0
1925}-
1926-
1927/*!-
1928 Optimize the usage of this matrix from its current elements.-
1929-
1930 Some operations such as translate(), scale(), and rotate() can be-
1931 performed more efficiently if the matrix being modified is already-
1932 known to be the identity, a previous translate(), a previous-
1933 scale(), etc.-
1934-
1935 Normally the QMatrix4x4 class keeps track of this special type internally-
1936 as operations are performed. However, if the matrix is modified-
1937 directly with operator()() or data(), then QMatrix4x4 will lose track of-
1938 the special type and will revert to the safest but least efficient-
1939 operations thereafter.-
1940-
1941 By calling optimize() after directly modifying the matrix,-
1942 the programmer can force QMatrix4x4 to recover the special type if-
1943 the elements appear to conform to one of the known optimized types.-
1944-
1945 \sa operator()(), data(), translate()-
1946*/-
1947void QMatrix4x4::optimize()-
1948{-
1949 // If the last row is not (0, 0, 0, 1), the matrix is not a special type.-
1950 flagBits = General;-
1951 if (m[0][3] != 0 || m[1][3] != 0 || m[2][3] != 0 || m[3][3] != 1)
m[0][3] != 0Description
TRUEnever evaluated
FALSEnever evaluated
m[1][3] != 0Description
TRUEnever evaluated
FALSEnever evaluated
m[2][3] != 0Description
TRUEnever evaluated
FALSEnever evaluated
m[3][3] != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1952 return;
never executed: return;
0
1953-
1954 flagBits &= ~Perspective;-
1955-
1956 // If the last column is (0, 0, 0, 1), then there is no translation.-
1957 if (m[3][0] == 0 && m[3][1] == 0 && m[3][2] == 0)
m[3][0] == 0Description
TRUEnever evaluated
FALSEnever evaluated
m[3][1] == 0Description
TRUEnever evaluated
FALSEnever evaluated
m[3][2] == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1958 flagBits &= ~Translation;
never executed: flagBits &= ~Translation;
0
1959-
1960 // If the two first elements of row 3 and column 3 are 0, then any rotation must be about Z.-
1961 if (!m[0][2] && !m[1][2] && !m[2][0] && !m[2][1]) {
!m[0][2]Description
TRUEnever evaluated
FALSEnever evaluated
!m[1][2]Description
TRUEnever evaluated
FALSEnever evaluated
!m[2][0]Description
TRUEnever evaluated
FALSEnever evaluated
!m[2][1]Description
TRUEnever evaluated
FALSEnever evaluated
0
1962 flagBits &= ~Rotation;-
1963 // If the six non-diagonal elements in the top left 3x3 matrix are 0, there is no rotation.-
1964 if (!m[0][1] && !m[1][0]) {
!m[0][1]Description
TRUEnever evaluated
FALSEnever evaluated
!m[1][0]Description
TRUEnever evaluated
FALSEnever evaluated
0
1965 flagBits &= ~Rotation2D;-
1966 // Check for identity.-
1967 if (m[0][0] == 1 && m[1][1] == 1 && m[2][2] == 1)
m[0][0] == 1Description
TRUEnever evaluated
FALSEnever evaluated
m[1][1] == 1Description
TRUEnever evaluated
FALSEnever evaluated
m[2][2] == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1968 flagBits &= ~Scale;
never executed: flagBits &= ~Scale;
0
1969 } else {
never executed: end of block
0
1970 // If the columns are orthonormal and form a right-handed system, then there is no scale.-
1971 double mm[4][4];-
1972 copyToDoubles(m, mm);-
1973 double det = matrixDet2(mm, 0, 1, 0, 1);-
1974 double lenX = mm[0][0] * mm[0][0] + mm[0][1] * mm[0][1];-
1975 double lenY = mm[1][0] * mm[1][0] + mm[1][1] * mm[1][1];-
1976 double lenZ = mm[2][2];-
1977 if (qFuzzyCompare(det, 1.0) && qFuzzyCompare(lenX, 1.0)
qFuzzyCompare(det, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
qFuzzyCompare(lenX, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1978 && qFuzzyCompare(lenY, 1.0) && qFuzzyCompare(lenZ, 1.0))
qFuzzyCompare(lenY, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
qFuzzyCompare(lenZ, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1979 {-
1980 flagBits &= ~Scale;-
1981 }
never executed: end of block
0
1982 }
never executed: end of block
0
1983 } else {-
1984 // If the columns are orthonormal and form a right-handed system, then there is no scale.-
1985 double mm[4][4];-
1986 copyToDoubles(m, mm);-
1987 double det = matrixDet3(mm, 0, 1, 2, 0, 1, 2);-
1988 double lenX = mm[0][0] * mm[0][0] + mm[0][1] * mm[0][1] + mm[0][2] * mm[0][2];-
1989 double lenY = mm[1][0] * mm[1][0] + mm[1][1] * mm[1][1] + mm[1][2] * mm[1][2];-
1990 double lenZ = mm[2][0] * mm[2][0] + mm[2][1] * mm[2][1] + mm[2][2] * mm[2][2];-
1991 if (qFuzzyCompare(det, 1.0) && qFuzzyCompare(lenX, 1.0)
qFuzzyCompare(det, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
qFuzzyCompare(lenX, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1992 && qFuzzyCompare(lenY, 1.0) && qFuzzyCompare(lenZ, 1.0))
qFuzzyCompare(lenY, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
qFuzzyCompare(lenZ, 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1993 {-
1994 flagBits &= ~Scale;-
1995 }
never executed: end of block
0
1996 }
never executed: end of block
0
1997}-
1998-
1999/*!-
2000 Returns the matrix as a QVariant.-
2001*/-
2002QMatrix4x4::operator QVariant() const-
2003{-
2004 return QVariant(QVariant::Matrix4x4, this);
never executed: return QVariant(QVariant::Matrix4x4, this);
0
2005}-
2006-
2007#ifndef QT_NO_DEBUG_STREAM-
2008-
2009QDebug operator<<(QDebug dbg, const QMatrix4x4 &m)-
2010{-
2011 QDebugStateSaver saver(dbg);-
2012 // Create a string that represents the matrix type.-
2013 QByteArray bits;-
2014 if (m.flagBits == QMatrix4x4::Identity) {
m.flagBits == ...x4x4::IdentityDescription
TRUEnever evaluated
FALSEnever evaluated
0
2015 bits = "Identity";-
2016 } else if (m.flagBits == QMatrix4x4::General) {
never executed: end of block
m.flagBits == ...ix4x4::GeneralDescription
TRUEnever evaluated
FALSEnever evaluated
0
2017 bits = "General";-
2018 } else {
never executed: end of block
0
2019 if ((m.flagBits & QMatrix4x4::Translation) != 0)
(m.flagBits & ...nslation) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2020 bits += "Translation,";
never executed: bits += "Translation,";
0
2021 if ((m.flagBits & QMatrix4x4::Scale) != 0)
(m.flagBits & ...4::Scale) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2022 bits += "Scale,";
never executed: bits += "Scale,";
0
2023 if ((m.flagBits & QMatrix4x4::Rotation2D) != 0)
(m.flagBits & ...tation2D) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2024 bits += "Rotation2D,";
never executed: bits += "Rotation2D,";
0
2025 if ((m.flagBits & QMatrix4x4::Rotation) != 0)
(m.flagBits & ...Rotation) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2026 bits += "Rotation,";
never executed: bits += "Rotation,";
0
2027 if ((m.flagBits & QMatrix4x4::Perspective) != 0)
(m.flagBits & ...spective) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2028 bits += "Perspective,";
never executed: bits += "Perspective,";
0
2029 if (bits.size() > 0)
bits.size() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2030 bits = bits.left(bits.size() - 1);
never executed: bits = bits.left(bits.size() - 1);
0
2031 }
never executed: end of block
0
2032-
2033 // Output in row-major order because it is more human-readable.-
2034 dbg.nospace() << "QMatrix4x4(type:" << bits.constData() << endl-
2035 << qSetFieldWidth(10)-
2036 << m(0, 0) << m(0, 1) << m(0, 2) << m(0, 3) << endl-
2037 << m(1, 0) << m(1, 1) << m(1, 2) << m(1, 3) << endl-
2038 << m(2, 0) << m(2, 1) << m(2, 2) << m(2, 3) << endl-
2039 << m(3, 0) << m(3, 1) << m(3, 2) << m(3, 3) << endl-
2040 << qSetFieldWidth(0) << ')';-
2041 return dbg;
never executed: return dbg;
0
2042}-
2043-
2044#endif-
2045-
2046#ifndef QT_NO_DATASTREAM-
2047-
2048/*!-
2049 \fn QDataStream &operator<<(QDataStream &stream, const QMatrix4x4 &matrix)-
2050 \relates QMatrix4x4-
2051-
2052 Writes the given \a matrix to the given \a stream and returns a-
2053 reference to the stream.-
2054-
2055 \sa {Serializing Qt Data Types}-
2056*/-
2057-
2058QDataStream &operator<<(QDataStream &stream, const QMatrix4x4 &matrix)-
2059{-
2060 for (int row = 0; row < 4; ++row)
row < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
2061 for (int col = 0; col < 4; ++col)
col < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
2062 stream << matrix(row, col);
never executed: stream << matrix(row, col);
0
2063 return stream;
never executed: return stream;
0
2064}-
2065-
2066/*!-
2067 \fn QDataStream &operator>>(QDataStream &stream, QMatrix4x4 &matrix)-
2068 \relates QMatrix4x4-
2069-
2070 Reads a 4x4 matrix from the given \a stream into the given \a matrix-
2071 and returns a reference to the stream.-
2072-
2073 \sa {Serializing Qt Data Types}-
2074*/-
2075-
2076QDataStream &operator>>(QDataStream &stream, QMatrix4x4 &matrix)-
2077{-
2078 float x;-
2079 for (int row = 0; row < 4; ++row) {
row < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
2080 for (int col = 0; col < 4; ++col) {
col < 4Description
TRUEnever evaluated
FALSEnever evaluated
0
2081 stream >> x;-
2082 matrix(row, col) = x;-
2083 }
never executed: end of block
0
2084 }
never executed: end of block
0
2085 matrix.optimize();-
2086 return stream;
never executed: return stream;
0
2087}-
2088-
2089#endif // QT_NO_DATASTREAM-
2090-
2091#endif // QT_NO_MATRIX4X4-
2092-
2093QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9