Coverage Report

Created: 2026-05-31 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/math3d/qmatrix4x4.h
Line
Count
Source
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#ifndef QMATRIX4X4_H
6
#define QMATRIX4X4_H
7
8
#include <QtGui/qtguiglobal.h>
9
#include <QtGui/qvector3d.h>
10
#include <QtGui/qvector4d.h>
11
#include <QtGui/qgenericmatrix.h>
12
#include <QtCore/qrect.h>
13
14
class tst_QMatrixNxN;
15
16
QT_BEGIN_NAMESPACE
17
18
#ifndef QT_NO_QUATERNION
19
class QQuaternion;
20
#endif
21
22
#ifndef QT_NO_MATRIX4X4
23
24
class QTransform;
25
class QVariant;
26
27
class Q_GUI_EXPORT QMatrix4x4
28
{
29
public:
30
0
    inline QMatrix4x4() { setToIdentity(); }
31
0
    explicit QMatrix4x4(Qt::Initialization) : flagBits(General) {}
32
    explicit QMatrix4x4(const float *values);
33
    inline QMatrix4x4(float m11, float m12, float m13, float m14,
34
                      float m21, float m22, float m23, float m24,
35
                      float m31, float m32, float m33, float m34,
36
                      float m41, float m42, float m43, float m44);
37
38
    template <int N, int M>
39
    explicit QMatrix4x4(const QGenericMatrix<N, M, float>& matrix);
40
41
    QMatrix4x4(const float *values, int cols, int rows);
42
    QMatrix4x4(const QTransform& transform);
43
44
    inline const float& operator()(int row, int column) const;
45
    inline float& operator()(int row, int column);
46
47
#ifndef QT_NO_VECTOR4D
48
    inline QVector4D column(int index) const;
49
    inline void setColumn(int index, const QVector4D& value);
50
51
    inline QVector4D row(int index) const;
52
    inline void setRow(int index, const QVector4D& value);
53
#endif
54
55
    inline bool isAffine() const;
56
57
    inline bool isIdentity() const;
58
    inline void setToIdentity();
59
60
    inline void fill(float value);
61
62
    double determinant() const;
63
    QMatrix4x4 inverted(bool *invertible = nullptr) const;
64
    QMatrix4x4 transposed() const;
65
    QMatrix3x3 normalMatrix() const;
66
67
    inline QMatrix4x4& operator+=(const QMatrix4x4& other);
68
    inline QMatrix4x4& operator-=(const QMatrix4x4& other);
69
    inline QMatrix4x4& operator*=(const QMatrix4x4& other);
70
    inline QMatrix4x4& operator*=(float factor);
71
    QMatrix4x4& operator/=(float divisor);
72
    inline bool operator==(const QMatrix4x4& other) const;
73
    inline bool operator!=(const QMatrix4x4& other) const;
74
75
    friend QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2);
76
    friend QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2);
77
    friend QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2);
78
#ifndef QT_NO_VECTOR3D
79
#if QT_DEPRECATED_SINCE(6, 1)
80
    friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector);
81
    friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix);
82
#endif
83
#endif
84
#ifndef QT_NO_VECTOR4D
85
    friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix);
86
    friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector);
87
#endif
88
    friend QPoint operator*(const QPoint& point, const QMatrix4x4& matrix);
89
    friend QPointF operator*(const QPointF& point, const QMatrix4x4& matrix);
90
    friend QMatrix4x4 operator-(const QMatrix4x4& matrix);
91
#if QT_DEPRECATED_SINCE(6, 1)
92
    friend QPoint operator*(const QMatrix4x4& matrix, const QPoint& point);
93
    friend QPointF operator*(const QMatrix4x4& matrix, const QPointF& point);
94
#endif
95
    friend QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix);
96
    friend QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor);
97
    friend Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor);
98
99
    friend Q_GUI_EXPORT bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2) noexcept;
100
101
#ifndef QT_NO_VECTOR3D
102
    void scale(const QVector3D& vector);
103
    void translate(const QVector3D& vector);
104
    void rotate(float angle, const QVector3D& vector);
105
#endif
106
    void scale(float x, float y);
107
    void scale(float x, float y, float z);
108
    void scale(float factor);
109
    void translate(float x, float y);
110
    void translate(float x, float y, float z);
111
    void rotate(float angle, float x, float y, float z = 0.0f);
112
#ifndef QT_NO_QUATERNION
113
    void rotate(const QQuaternion& quaternion);
114
#endif
115
116
    void ortho(const QRect& rect);
117
    void ortho(const QRectF& rect);
118
    void ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane);
119
    void frustum(float left, float right, float bottom, float top, float nearPlane, float farPlane);
120
    void perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane);
121
#ifndef QT_NO_VECTOR3D
122
    void lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up);
123
#endif
124
    void viewport(const QRectF &rect);
125
    void viewport(float left, float bottom, float width, float height, float nearPlane = 0.0f, float farPlane = 1.0f);
126
    void flipCoordinates();
127
128
    void copyDataTo(float *values) const;
129
130
    QTransform toTransform() const;
131
    QTransform toTransform(float distanceToPlane) const;
132
133
    inline QPoint map(const QPoint& point) const;
134
    inline QPointF map(const QPointF& point) const;
135
#ifndef QT_NO_VECTOR3D
136
    inline QVector3D map(const QVector3D& point) const;
137
    inline QVector3D mapVector(const QVector3D& vector) const;
138
#endif
139
#ifndef QT_NO_VECTOR4D
140
    inline QVector4D map(const QVector4D& point) const;
141
#endif
142
    QRect mapRect(const QRect& rect) const;
143
    QRectF mapRect(const QRectF& rect) const;
144
145
    template <int N, int M>
146
    QGenericMatrix<N, M, float> toGenericMatrix() const;
147
148
    inline float *data();
149
0
    inline const float *data() const { return *m; }
150
0
    inline const float *constData() const { return *m; }
151
152
    void optimize();
153
154
    operator QVariant() const;
155
156
#ifndef QT_NO_DEBUG_STREAM
157
    friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
158
#endif
159
160
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
161
    void projectedRotate(float angle, float x, float y, float z, float distanceToPlane);
162
    // ### Qt7: Remove
163
    void projectedRotate(float angle, float x, float y, float z);
164
#else
165
    void projectedRotate(float angle, float x, float y, float z, float distanceToPlane = 1024.0);
166
#endif
167
168
    // When matrices are multiplied, the flag bits are or-ed together.
169
    // Note that the ordering of the bit values matters. (ident < t < s < r2d < r < p)
170
    enum Flag {
171
        Identity        = 0x0000, // Identity matrix
172
        Translation     = 0x0001, // Contains a translation
173
        Scale           = 0x0002, // Contains a scale
174
        Rotation2D      = 0x0004, // Contains a rotation about the Z axis
175
        Rotation        = 0x0008, // Contains an arbitrary rotation
176
        Perspective     = 0x0010, // Last row is different from (0, 0, 0, 1)
177
        General         = 0x001f  // General matrix, unknown contents
178
    };
179
    Q_DECLARE_FLAGS(Flags, Flag)
180
181
0
    Flags flags() const { return flagBits; }
182
183
private:
184
    float m[4][4];          // Column-major order to match OpenGL.
185
    Flags flagBits;
186
187
    QMatrix4x4 orthonormalInverse() const;
188
    void toGenericMatrix_impl(float *dst, int n, int m) const;
189
190
    friend class ::tst_QMatrixNxN; // for access to flagBits
191
};
192
193
0
Q_DECLARE_OPERATORS_FOR_FLAGS(QMatrix4x4::Flags)
Unexecuted instantiation: operator|(QMatrix4x4::Flag, QMatrix4x4::Flag)
Unexecuted instantiation: operator|(QMatrix4x4::Flag, QFlags<QMatrix4x4::Flag>)
Unexecuted instantiation: operator&(QMatrix4x4::Flag, QMatrix4x4::Flag)
Unexecuted instantiation: operator&(QMatrix4x4::Flag, QFlags<QMatrix4x4::Flag>)
Unexecuted instantiation: operator^(QMatrix4x4::Flag, QMatrix4x4::Flag)
Unexecuted instantiation: operator^(QMatrix4x4::Flag, QFlags<QMatrix4x4::Flag>)
Unexecuted instantiation: operator|(QMatrix4x4::Flag, int)
194
0
195
0
QT_WARNING_PUSH
196
0
QT_WARNING_DISABLE_FLOAT_COMPARE
197
0
198
0
Q_DECLARE_TYPEINFO(QMatrix4x4, Q_PRIMITIVE_TYPE);
199
0
200
0
inline QMatrix4x4::QMatrix4x4
201
0
        (float m11, float m12, float m13, float m14,
202
0
         float m21, float m22, float m23, float m24,
203
0
         float m31, float m32, float m33, float m34,
204
0
         float m41, float m42, float m43, float m44)
205
0
{
206
0
    m[0][0] = m11; m[0][1] = m21; m[0][2] = m31; m[0][3] = m41;
207
0
    m[1][0] = m12; m[1][1] = m22; m[1][2] = m32; m[1][3] = m42;
208
0
    m[2][0] = m13; m[2][1] = m23; m[2][2] = m33; m[2][3] = m43;
209
0
    m[3][0] = m14; m[3][1] = m24; m[3][2] = m34; m[3][3] = m44;
210
0
    flagBits = General;
211
0
}
212
0
213
0
template <int N, int M>
214
0
Q_INLINE_TEMPLATE QMatrix4x4::QMatrix4x4
215
0
    (const QGenericMatrix<N, M, float>& matrix)
216
0
{
217
0
    const float *values = matrix.constData();
218
0
    for (int matrixCol = 0; matrixCol < 4; ++matrixCol) {
219
0
        for (int matrixRow = 0; matrixRow < 4; ++matrixRow) {
220
0
            if (matrixCol < N && matrixRow < M)
221
0
                m[matrixCol][matrixRow] = values[matrixCol * M + matrixRow];
222
0
            else if (matrixCol == matrixRow)
223
0
                m[matrixCol][matrixRow] = 1.0f;
224
0
            else
225
0
                m[matrixCol][matrixRow] = 0.0f;
226
0
        }
227
0
    }
228
0
    flagBits = General;
229
0
}
230
0
231
0
template <int N, int M>
232
0
QGenericMatrix<N, M, float> QMatrix4x4::toGenericMatrix() const
233
0
{
234
0
    Q_DECL_UNINITIALIZED
235
0
    QGenericMatrix<N, M, float> result(Qt::Uninitialized);
236
0
    toGenericMatrix_impl(result.data(), N, M);
237
0
    return result;
238
0
}
239
0
240
0
inline const float& QMatrix4x4::operator()(int aRow, int aColumn) const
241
0
{
242
0
    Q_ASSERT(aRow >= 0 && aRow < 4 && aColumn >= 0 && aColumn < 4);
243
0
    return m[aColumn][aRow];
244
0
}
245
246
inline float& QMatrix4x4::operator()(int aRow, int aColumn)
247
0
{
248
0
    Q_ASSERT(aRow >= 0 && aRow < 4 && aColumn >= 0 && aColumn < 4);
249
0
    flagBits = General;
250
0
    return m[aColumn][aRow];
251
0
}
252
253
#ifndef QT_NO_VECTOR4D
254
inline QVector4D QMatrix4x4::column(int index) const
255
0
{
256
0
    Q_ASSERT(index >= 0 && index < 4);
257
0
    return QVector4D(m[index][0], m[index][1], m[index][2], m[index][3]);
258
0
}
259
260
inline void QMatrix4x4::setColumn(int index, const QVector4D& value)
261
0
{
262
0
    Q_ASSERT(index >= 0 && index < 4);
263
0
    m[index][0] = value.x();
264
0
    m[index][1] = value.y();
265
0
    m[index][2] = value.z();
266
0
    m[index][3] = value.w();
267
0
    flagBits = General;
268
0
}
269
270
inline QVector4D QMatrix4x4::row(int index) const
271
0
{
272
0
    Q_ASSERT(index >= 0 && index < 4);
273
0
    return QVector4D(m[0][index], m[1][index], m[2][index], m[3][index]);
274
0
}
275
276
inline void QMatrix4x4::setRow(int index, const QVector4D& value)
277
0
{
278
0
    Q_ASSERT(index >= 0 && index < 4);
279
0
    m[0][index] = value.x();
280
0
    m[1][index] = value.y();
281
0
    m[2][index] = value.z();
282
0
    m[3][index] = value.w();
283
0
    flagBits = General;
284
0
}
285
#endif
286
287
Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor);
288
289
inline bool QMatrix4x4::isAffine() const
290
0
{
291
0
    return m[0][3] == 0.0f && m[1][3] == 0.0f && m[2][3] == 0.0f && m[3][3] == 1.0f;
292
0
}
293
294
inline bool QMatrix4x4::isIdentity() const
295
0
{
296
0
    if (flagBits == Identity)
297
0
        return true;
298
0
    if (m[0][0] != 1.0f || m[0][1] != 0.0f || m[0][2] != 0.0f)
299
0
        return false;
300
0
    if (m[0][3] != 0.0f || m[1][0] != 0.0f || m[1][1] != 1.0f)
301
0
        return false;
302
0
    if (m[1][2] != 0.0f || m[1][3] != 0.0f || m[2][0] != 0.0f)
303
0
        return false;
304
0
    if (m[2][1] != 0.0f || m[2][2] != 1.0f || m[2][3] != 0.0f)
305
0
        return false;
306
0
    if (m[3][0] != 0.0f || m[3][1] != 0.0f || m[3][2] != 0.0f)
307
0
        return false;
308
0
    return (m[3][3] == 1.0f);
309
0
}
310
311
inline void QMatrix4x4::setToIdentity()
312
0
{
313
0
    m[0][0] = 1.0f;
314
0
    m[0][1] = 0.0f;
315
0
    m[0][2] = 0.0f;
316
0
    m[0][3] = 0.0f;
317
0
    m[1][0] = 0.0f;
318
0
    m[1][1] = 1.0f;
319
0
    m[1][2] = 0.0f;
320
0
    m[1][3] = 0.0f;
321
0
    m[2][0] = 0.0f;
322
0
    m[2][1] = 0.0f;
323
0
    m[2][2] = 1.0f;
324
0
    m[2][3] = 0.0f;
325
0
    m[3][0] = 0.0f;
326
0
    m[3][1] = 0.0f;
327
0
    m[3][2] = 0.0f;
328
0
    m[3][3] = 1.0f;
329
0
    flagBits = Identity;
330
0
}
331
332
inline void QMatrix4x4::fill(float value)
333
0
{
334
0
    m[0][0] = value;
335
0
    m[0][1] = value;
336
0
    m[0][2] = value;
337
0
    m[0][3] = value;
338
0
    m[1][0] = value;
339
0
    m[1][1] = value;
340
0
    m[1][2] = value;
341
0
    m[1][3] = value;
342
0
    m[2][0] = value;
343
0
    m[2][1] = value;
344
0
    m[2][2] = value;
345
0
    m[2][3] = value;
346
0
    m[3][0] = value;
347
0
    m[3][1] = value;
348
0
    m[3][2] = value;
349
0
    m[3][3] = value;
350
0
    flagBits = General;
351
0
}
352
353
inline QMatrix4x4& QMatrix4x4::operator+=(const QMatrix4x4& other)
354
0
{
355
0
    m[0][0] += other.m[0][0];
356
0
    m[0][1] += other.m[0][1];
357
0
    m[0][2] += other.m[0][2];
358
0
    m[0][3] += other.m[0][3];
359
0
    m[1][0] += other.m[1][0];
360
0
    m[1][1] += other.m[1][1];
361
0
    m[1][2] += other.m[1][2];
362
0
    m[1][3] += other.m[1][3];
363
0
    m[2][0] += other.m[2][0];
364
0
    m[2][1] += other.m[2][1];
365
0
    m[2][2] += other.m[2][2];
366
0
    m[2][3] += other.m[2][3];
367
0
    m[3][0] += other.m[3][0];
368
0
    m[3][1] += other.m[3][1];
369
0
    m[3][2] += other.m[3][2];
370
0
    m[3][3] += other.m[3][3];
371
0
    flagBits = General;
372
0
    return *this;
373
0
}
374
375
inline QMatrix4x4& QMatrix4x4::operator-=(const QMatrix4x4& other)
376
0
{
377
0
    m[0][0] -= other.m[0][0];
378
0
    m[0][1] -= other.m[0][1];
379
0
    m[0][2] -= other.m[0][2];
380
0
    m[0][3] -= other.m[0][3];
381
0
    m[1][0] -= other.m[1][0];
382
0
    m[1][1] -= other.m[1][1];
383
0
    m[1][2] -= other.m[1][2];
384
0
    m[1][3] -= other.m[1][3];
385
0
    m[2][0] -= other.m[2][0];
386
0
    m[2][1] -= other.m[2][1];
387
0
    m[2][2] -= other.m[2][2];
388
0
    m[2][3] -= other.m[2][3];
389
0
    m[3][0] -= other.m[3][0];
390
0
    m[3][1] -= other.m[3][1];
391
0
    m[3][2] -= other.m[3][2];
392
0
    m[3][3] -= other.m[3][3];
393
0
    flagBits = General;
394
0
    return *this;
395
0
}
396
397
inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& o)
398
0
{
399
0
    const QMatrix4x4 other = o; // prevent aliasing when &o == this ### Qt 6: take o by value
400
0
    flagBits |= other.flagBits;
401
402
0
    if (flagBits.toInt() < Rotation2D) {
403
0
        m[3][0] += m[0][0] * other.m[3][0];
404
0
        m[3][1] += m[1][1] * other.m[3][1];
405
0
        m[3][2] += m[2][2] * other.m[3][2];
406
407
0
        m[0][0] *= other.m[0][0];
408
0
        m[1][1] *= other.m[1][1];
409
0
        m[2][2] *= other.m[2][2];
410
0
        return *this;
411
0
    }
412
413
0
    float m0, m1, m2;
414
0
    m0 = m[0][0] * other.m[0][0]
415
0
            + m[1][0] * other.m[0][1]
416
0
            + m[2][0] * other.m[0][2]
417
0
            + m[3][0] * other.m[0][3];
418
0
    m1 = m[0][0] * other.m[1][0]
419
0
            + m[1][0] * other.m[1][1]
420
0
            + m[2][0] * other.m[1][2]
421
0
            + m[3][0] * other.m[1][3];
422
0
    m2 = m[0][0] * other.m[2][0]
423
0
            + m[1][0] * other.m[2][1]
424
0
            + m[2][0] * other.m[2][2]
425
0
            + m[3][0] * other.m[2][3];
426
0
    m[3][0] = m[0][0] * other.m[3][0]
427
0
            + m[1][0] * other.m[3][1]
428
0
            + m[2][0] * other.m[3][2]
429
0
            + m[3][0] * other.m[3][3];
430
0
    m[0][0] = m0;
431
0
    m[1][0] = m1;
432
0
    m[2][0] = m2;
433
434
0
    m0 = m[0][1] * other.m[0][0]
435
0
            + m[1][1] * other.m[0][1]
436
0
            + m[2][1] * other.m[0][2]
437
0
            + m[3][1] * other.m[0][3];
438
0
    m1 = m[0][1] * other.m[1][0]
439
0
            + m[1][1] * other.m[1][1]
440
0
            + m[2][1] * other.m[1][2]
441
0
            + m[3][1] * other.m[1][3];
442
0
    m2 = m[0][1] * other.m[2][0]
443
0
            + m[1][1] * other.m[2][1]
444
0
            + m[2][1] * other.m[2][2]
445
0
            + m[3][1] * other.m[2][3];
446
0
    m[3][1] = m[0][1] * other.m[3][0]
447
0
            + m[1][1] * other.m[3][1]
448
0
            + m[2][1] * other.m[3][2]
449
0
            + m[3][1] * other.m[3][3];
450
0
    m[0][1] = m0;
451
0
    m[1][1] = m1;
452
0
    m[2][1] = m2;
453
454
0
    m0 = m[0][2] * other.m[0][0]
455
0
            + m[1][2] * other.m[0][1]
456
0
            + m[2][2] * other.m[0][2]
457
0
            + m[3][2] * other.m[0][3];
458
0
    m1 = m[0][2] * other.m[1][0]
459
0
            + m[1][2] * other.m[1][1]
460
0
            + m[2][2] * other.m[1][2]
461
0
            + m[3][2] * other.m[1][3];
462
0
    m2 = m[0][2] * other.m[2][0]
463
0
            + m[1][2] * other.m[2][1]
464
0
            + m[2][2] * other.m[2][2]
465
0
            + m[3][2] * other.m[2][3];
466
0
    m[3][2] = m[0][2] * other.m[3][0]
467
0
            + m[1][2] * other.m[3][1]
468
0
            + m[2][2] * other.m[3][2]
469
0
            + m[3][2] * other.m[3][3];
470
0
    m[0][2] = m0;
471
0
    m[1][2] = m1;
472
0
    m[2][2] = m2;
473
474
0
    m0 = m[0][3] * other.m[0][0]
475
0
            + m[1][3] * other.m[0][1]
476
0
            + m[2][3] * other.m[0][2]
477
0
            + m[3][3] * other.m[0][3];
478
0
    m1 = m[0][3] * other.m[1][0]
479
0
            + m[1][3] * other.m[1][1]
480
0
            + m[2][3] * other.m[1][2]
481
0
            + m[3][3] * other.m[1][3];
482
0
    m2 = m[0][3] * other.m[2][0]
483
0
            + m[1][3] * other.m[2][1]
484
0
            + m[2][3] * other.m[2][2]
485
0
            + m[3][3] * other.m[2][3];
486
0
    m[3][3] = m[0][3] * other.m[3][0]
487
0
            + m[1][3] * other.m[3][1]
488
0
            + m[2][3] * other.m[3][2]
489
0
            + m[3][3] * other.m[3][3];
490
0
    m[0][3] = m0;
491
0
    m[1][3] = m1;
492
0
    m[2][3] = m2;
493
0
    return *this;
494
0
}
495
496
inline QMatrix4x4& QMatrix4x4::operator*=(float factor)
497
0
{
498
0
    m[0][0] *= factor;
499
0
    m[0][1] *= factor;
500
0
    m[0][2] *= factor;
501
0
    m[0][3] *= factor;
502
0
    m[1][0] *= factor;
503
0
    m[1][1] *= factor;
504
0
    m[1][2] *= factor;
505
0
    m[1][3] *= factor;
506
0
    m[2][0] *= factor;
507
0
    m[2][1] *= factor;
508
0
    m[2][2] *= factor;
509
0
    m[2][3] *= factor;
510
0
    m[3][0] *= factor;
511
0
    m[3][1] *= factor;
512
0
    m[3][2] *= factor;
513
0
    m[3][3] *= factor;
514
0
    flagBits = General;
515
0
    return *this;
516
0
}
517
518
inline bool QMatrix4x4::operator==(const QMatrix4x4& other) const
519
0
{
520
0
    return m[0][0] == other.m[0][0] &&
521
0
           m[0][1] == other.m[0][1] &&
522
0
           m[0][2] == other.m[0][2] &&
523
0
           m[0][3] == other.m[0][3] &&
524
0
           m[1][0] == other.m[1][0] &&
525
0
           m[1][1] == other.m[1][1] &&
526
0
           m[1][2] == other.m[1][2] &&
527
0
           m[1][3] == other.m[1][3] &&
528
0
           m[2][0] == other.m[2][0] &&
529
0
           m[2][1] == other.m[2][1] &&
530
0
           m[2][2] == other.m[2][2] &&
531
0
           m[2][3] == other.m[2][3] &&
532
0
           m[3][0] == other.m[3][0] &&
533
0
           m[3][1] == other.m[3][1] &&
534
0
           m[3][2] == other.m[3][2] &&
535
0
           m[3][3] == other.m[3][3];
536
0
}
537
538
inline bool QMatrix4x4::operator!=(const QMatrix4x4& other) const
539
0
{
540
0
    return m[0][0] != other.m[0][0] ||
541
0
           m[0][1] != other.m[0][1] ||
542
0
           m[0][2] != other.m[0][2] ||
543
0
           m[0][3] != other.m[0][3] ||
544
0
           m[1][0] != other.m[1][0] ||
545
0
           m[1][1] != other.m[1][1] ||
546
0
           m[1][2] != other.m[1][2] ||
547
0
           m[1][3] != other.m[1][3] ||
548
0
           m[2][0] != other.m[2][0] ||
549
0
           m[2][1] != other.m[2][1] ||
550
0
           m[2][2] != other.m[2][2] ||
551
0
           m[2][3] != other.m[2][3] ||
552
0
           m[3][0] != other.m[3][0] ||
553
0
           m[3][1] != other.m[3][1] ||
554
0
           m[3][2] != other.m[3][2] ||
555
0
           m[3][3] != other.m[3][3];
556
0
}
557
558
inline QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2)
559
0
{
560
0
    Q_DECL_UNINITIALIZED
561
0
    QMatrix4x4 m(Qt::Uninitialized);
562
0
    m.m[0][0] = m1.m[0][0] + m2.m[0][0];
563
0
    m.m[0][1] = m1.m[0][1] + m2.m[0][1];
564
0
    m.m[0][2] = m1.m[0][2] + m2.m[0][2];
565
0
    m.m[0][3] = m1.m[0][3] + m2.m[0][3];
566
0
    m.m[1][0] = m1.m[1][0] + m2.m[1][0];
567
0
    m.m[1][1] = m1.m[1][1] + m2.m[1][1];
568
0
    m.m[1][2] = m1.m[1][2] + m2.m[1][2];
569
0
    m.m[1][3] = m1.m[1][3] + m2.m[1][3];
570
0
    m.m[2][0] = m1.m[2][0] + m2.m[2][0];
571
0
    m.m[2][1] = m1.m[2][1] + m2.m[2][1];
572
0
    m.m[2][2] = m1.m[2][2] + m2.m[2][2];
573
0
    m.m[2][3] = m1.m[2][3] + m2.m[2][3];
574
0
    m.m[3][0] = m1.m[3][0] + m2.m[3][0];
575
0
    m.m[3][1] = m1.m[3][1] + m2.m[3][1];
576
0
    m.m[3][2] = m1.m[3][2] + m2.m[3][2];
577
0
    m.m[3][3] = m1.m[3][3] + m2.m[3][3];
578
0
    return m;
579
0
}
580
581
inline QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2)
582
0
{
583
0
    Q_DECL_UNINITIALIZED
584
0
    QMatrix4x4 m(Qt::Uninitialized);
585
0
    m.m[0][0] = m1.m[0][0] - m2.m[0][0];
586
0
    m.m[0][1] = m1.m[0][1] - m2.m[0][1];
587
0
    m.m[0][2] = m1.m[0][2] - m2.m[0][2];
588
0
    m.m[0][3] = m1.m[0][3] - m2.m[0][3];
589
0
    m.m[1][0] = m1.m[1][0] - m2.m[1][0];
590
0
    m.m[1][1] = m1.m[1][1] - m2.m[1][1];
591
0
    m.m[1][2] = m1.m[1][2] - m2.m[1][2];
592
0
    m.m[1][3] = m1.m[1][3] - m2.m[1][3];
593
0
    m.m[2][0] = m1.m[2][0] - m2.m[2][0];
594
0
    m.m[2][1] = m1.m[2][1] - m2.m[2][1];
595
0
    m.m[2][2] = m1.m[2][2] - m2.m[2][2];
596
0
    m.m[2][3] = m1.m[2][3] - m2.m[2][3];
597
0
    m.m[3][0] = m1.m[3][0] - m2.m[3][0];
598
0
    m.m[3][1] = m1.m[3][1] - m2.m[3][1];
599
0
    m.m[3][2] = m1.m[3][2] - m2.m[3][2];
600
0
    m.m[3][3] = m1.m[3][3] - m2.m[3][3];
601
0
    return m;
602
0
}
603
604
inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
605
0
{
606
0
    Q_DECL_UNINITIALIZED
607
0
    QMatrix4x4 m(Qt::Uninitialized);
608
0
    QMatrix4x4::Flags flagBits = m1.flagBits | m2.flagBits;
609
0
    if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
610
        // Scale | Translation
611
0
        m.m[0][0] = m1.m[0][0] * m2.m[0][0];
612
0
        m.m[0][1] = 0.0f;
613
0
        m.m[0][2] = 0.0f;
614
0
        m.m[0][3] = 0.0f;
615
616
0
        m.m[1][0] = 0.0f;
617
0
        m.m[1][1] = m1.m[1][1] * m2.m[1][1];
618
0
        m.m[1][2] = 0.0f;
619
0
        m.m[1][3] = 0.0f;
620
621
0
        m.m[2][0] = 0.0f;
622
0
        m.m[2][1] = 0.0f;
623
0
        m.m[2][2] = m1.m[2][2] * m2.m[2][2];
624
0
        m.m[2][3] = 0.0f;
625
626
0
        m.m[3][0] = m1.m[3][0] + m1.m[0][0] * m2.m[3][0];
627
0
        m.m[3][1] = m1.m[3][1] + m1.m[1][1] * m2.m[3][1];
628
0
        m.m[3][2] = m1.m[3][2] + m1.m[2][2] * m2.m[3][2];
629
0
        m.m[3][3] = 1.0f;
630
0
        m.flagBits = flagBits;
631
0
        return m;
632
0
    }
633
634
0
    m.m[0][0] = m1.m[0][0] * m2.m[0][0]
635
0
              + m1.m[1][0] * m2.m[0][1]
636
0
              + m1.m[2][0] * m2.m[0][2]
637
0
              + m1.m[3][0] * m2.m[0][3];
638
0
    m.m[0][1] = m1.m[0][1] * m2.m[0][0]
639
0
              + m1.m[1][1] * m2.m[0][1]
640
0
              + m1.m[2][1] * m2.m[0][2]
641
0
              + m1.m[3][1] * m2.m[0][3];
642
0
    m.m[0][2] = m1.m[0][2] * m2.m[0][0]
643
0
              + m1.m[1][2] * m2.m[0][1]
644
0
              + m1.m[2][2] * m2.m[0][2]
645
0
              + m1.m[3][2] * m2.m[0][3];
646
0
    m.m[0][3] = m1.m[0][3] * m2.m[0][0]
647
0
              + m1.m[1][3] * m2.m[0][1]
648
0
              + m1.m[2][3] * m2.m[0][2]
649
0
              + m1.m[3][3] * m2.m[0][3];
650
651
0
    m.m[1][0] = m1.m[0][0] * m2.m[1][0]
652
0
              + m1.m[1][0] * m2.m[1][1]
653
0
              + m1.m[2][0] * m2.m[1][2]
654
0
              + m1.m[3][0] * m2.m[1][3];
655
0
    m.m[1][1] = m1.m[0][1] * m2.m[1][0]
656
0
              + m1.m[1][1] * m2.m[1][1]
657
0
              + m1.m[2][1] * m2.m[1][2]
658
0
              + m1.m[3][1] * m2.m[1][3];
659
0
    m.m[1][2] = m1.m[0][2] * m2.m[1][0]
660
0
              + m1.m[1][2] * m2.m[1][1]
661
0
              + m1.m[2][2] * m2.m[1][2]
662
0
              + m1.m[3][2] * m2.m[1][3];
663
0
    m.m[1][3] = m1.m[0][3] * m2.m[1][0]
664
0
              + m1.m[1][3] * m2.m[1][1]
665
0
              + m1.m[2][3] * m2.m[1][2]
666
0
              + m1.m[3][3] * m2.m[1][3];
667
668
0
    m.m[2][0] = m1.m[0][0] * m2.m[2][0]
669
0
              + m1.m[1][0] * m2.m[2][1]
670
0
              + m1.m[2][0] * m2.m[2][2]
671
0
              + m1.m[3][0] * m2.m[2][3];
672
0
    m.m[2][1] = m1.m[0][1] * m2.m[2][0]
673
0
              + m1.m[1][1] * m2.m[2][1]
674
0
              + m1.m[2][1] * m2.m[2][2]
675
0
              + m1.m[3][1] * m2.m[2][3];
676
0
    m.m[2][2] = m1.m[0][2] * m2.m[2][0]
677
0
              + m1.m[1][2] * m2.m[2][1]
678
0
              + m1.m[2][2] * m2.m[2][2]
679
0
              + m1.m[3][2] * m2.m[2][3];
680
0
    m.m[2][3] = m1.m[0][3] * m2.m[2][0]
681
0
              + m1.m[1][3] * m2.m[2][1]
682
0
              + m1.m[2][3] * m2.m[2][2]
683
0
              + m1.m[3][3] * m2.m[2][3];
684
685
0
    m.m[3][0] = m1.m[0][0] * m2.m[3][0]
686
0
              + m1.m[1][0] * m2.m[3][1]
687
0
              + m1.m[2][0] * m2.m[3][2]
688
0
              + m1.m[3][0] * m2.m[3][3];
689
0
    m.m[3][1] = m1.m[0][1] * m2.m[3][0]
690
0
              + m1.m[1][1] * m2.m[3][1]
691
0
              + m1.m[2][1] * m2.m[3][2]
692
0
              + m1.m[3][1] * m2.m[3][3];
693
0
    m.m[3][2] = m1.m[0][2] * m2.m[3][0]
694
0
              + m1.m[1][2] * m2.m[3][1]
695
0
              + m1.m[2][2] * m2.m[3][2]
696
0
              + m1.m[3][2] * m2.m[3][3];
697
0
    m.m[3][3] = m1.m[0][3] * m2.m[3][0]
698
0
              + m1.m[1][3] * m2.m[3][1]
699
0
              + m1.m[2][3] * m2.m[3][2]
700
0
              + m1.m[3][3] * m2.m[3][3];
701
0
    m.flagBits = flagBits;
702
0
    return m;
703
0
}
704
705
#ifndef QT_NO_VECTOR3D
706
707
#if QT_DEPRECATED_SINCE(6, 1)
708
709
QT_DEPRECATED_VERSION_X_6_1("Extend the QVector3D to a QVector4D with 1.0 as the w coordinate before multiplying")
710
inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
711
0
{
712
0
    float x, y, z, w;
713
0
    x = vector.x() * matrix.m[0][0] +
714
0
        vector.y() * matrix.m[0][1] +
715
0
        vector.z() * matrix.m[0][2] +
716
0
        matrix.m[0][3];
717
0
    y = vector.x() * matrix.m[1][0] +
718
0
        vector.y() * matrix.m[1][1] +
719
0
        vector.z() * matrix.m[1][2] +
720
0
        matrix.m[1][3];
721
0
    z = vector.x() * matrix.m[2][0] +
722
0
        vector.y() * matrix.m[2][1] +
723
0
        vector.z() * matrix.m[2][2] +
724
0
        matrix.m[2][3];
725
0
    w = vector.x() * matrix.m[3][0] +
726
0
        vector.y() * matrix.m[3][1] +
727
0
        vector.z() * matrix.m[3][2] +
728
0
        matrix.m[3][3];
729
0
    if (w == 1.0f)
730
0
        return QVector3D(x, y, z);
731
0
    else
732
0
        return QVector3D(x / w, y / w, z / w);
733
0
}
734
735
QT_DEPRECATED_VERSION_X_6_1("Use matrix.map(vector) instead")
736
inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
737
0
{
738
0
    return matrix.map(vector);
739
0
}
740
741
#endif
742
743
#endif
744
745
#ifndef QT_NO_VECTOR4D
746
747
inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)
748
0
{
749
0
    float x, y, z, w;
750
0
    x = vector.x() * matrix.m[0][0] +
751
0
        vector.y() * matrix.m[0][1] +
752
0
        vector.z() * matrix.m[0][2] +
753
0
        vector.w() * matrix.m[0][3];
754
0
    y = vector.x() * matrix.m[1][0] +
755
0
        vector.y() * matrix.m[1][1] +
756
0
        vector.z() * matrix.m[1][2] +
757
0
        vector.w() * matrix.m[1][3];
758
0
    z = vector.x() * matrix.m[2][0] +
759
0
        vector.y() * matrix.m[2][1] +
760
0
        vector.z() * matrix.m[2][2] +
761
0
        vector.w() * matrix.m[2][3];
762
0
    w = vector.x() * matrix.m[3][0] +
763
0
        vector.y() * matrix.m[3][1] +
764
0
        vector.z() * matrix.m[3][2] +
765
0
        vector.w() * matrix.m[3][3];
766
0
    return QVector4D(x, y, z, w);
767
0
}
768
769
inline QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector)
770
0
{
771
0
    float x, y, z, w;
772
0
    x = vector.x() * matrix.m[0][0] +
773
0
        vector.y() * matrix.m[1][0] +
774
0
        vector.z() * matrix.m[2][0] +
775
0
        vector.w() * matrix.m[3][0];
776
0
    y = vector.x() * matrix.m[0][1] +
777
0
        vector.y() * matrix.m[1][1] +
778
0
        vector.z() * matrix.m[2][1] +
779
0
        vector.w() * matrix.m[3][1];
780
0
    z = vector.x() * matrix.m[0][2] +
781
0
        vector.y() * matrix.m[1][2] +
782
0
        vector.z() * matrix.m[2][2] +
783
0
        vector.w() * matrix.m[3][2];
784
0
    w = vector.x() * matrix.m[0][3] +
785
0
        vector.y() * matrix.m[1][3] +
786
0
        vector.z() * matrix.m[2][3] +
787
0
        vector.w() * matrix.m[3][3];
788
0
    return QVector4D(x, y, z, w);
789
0
}
790
791
#endif
792
793
inline QPoint operator*(const QPoint& point, const QMatrix4x4& matrix)
794
0
{
795
0
    float xin, yin;
796
0
    float x, y, w;
797
0
    xin = point.x();
798
0
    yin = point.y();
799
0
    x = xin * matrix.m[0][0] +
800
0
        yin * matrix.m[0][1] +
801
0
        matrix.m[0][3];
802
0
    y = xin * matrix.m[1][0] +
803
0
        yin * matrix.m[1][1] +
804
0
        matrix.m[1][3];
805
0
    w = xin * matrix.m[3][0] +
806
0
        yin * matrix.m[3][1] +
807
0
        matrix.m[3][3];
808
0
    if (w == 1.0f)
809
0
        return QPoint(qRound(x), qRound(y));
810
0
    else
811
0
        return QPoint(qRound(x / w), qRound(y / w));
812
0
}
813
814
inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)
815
0
{
816
0
    float xin, yin;
817
0
    float x, y, w;
818
0
    xin = float(point.x());
819
0
    yin = float(point.y());
820
0
    x = xin * matrix.m[0][0] +
821
0
        yin * matrix.m[0][1] +
822
0
        matrix.m[0][3];
823
0
    y = xin * matrix.m[1][0] +
824
0
        yin * matrix.m[1][1] +
825
0
        matrix.m[1][3];
826
0
    w = xin * matrix.m[3][0] +
827
0
        yin * matrix.m[3][1] +
828
0
        matrix.m[3][3];
829
0
    if (w == 1.0f) {
830
0
        return QPointF(qreal(x), qreal(y));
831
0
    } else {
832
0
        return QPointF(qreal(x / w), qreal(y / w));
833
0
    }
834
0
}
835
836
#if QT_DEPRECATED_SINCE(6, 1)
837
838
QT_DEPRECATED_VERSION_X_6_1("Use matrix.map(point) instead")
839
inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
840
0
{
841
0
    return matrix.map(point);
842
0
}
843
844
QT_DEPRECATED_VERSION_X_6_1("Use matrix.map(point) instead")
845
inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
846
0
{
847
0
    return matrix.map(point);
848
0
}
849
850
#endif
851
852
inline QMatrix4x4 operator-(const QMatrix4x4& matrix)
853
0
{
854
0
    Q_DECL_UNINITIALIZED
855
0
    QMatrix4x4 m(Qt::Uninitialized);
856
0
    m.m[0][0] = -matrix.m[0][0];
857
0
    m.m[0][1] = -matrix.m[0][1];
858
0
    m.m[0][2] = -matrix.m[0][2];
859
0
    m.m[0][3] = -matrix.m[0][3];
860
0
    m.m[1][0] = -matrix.m[1][0];
861
0
    m.m[1][1] = -matrix.m[1][1];
862
0
    m.m[1][2] = -matrix.m[1][2];
863
0
    m.m[1][3] = -matrix.m[1][3];
864
0
    m.m[2][0] = -matrix.m[2][0];
865
0
    m.m[2][1] = -matrix.m[2][1];
866
0
    m.m[2][2] = -matrix.m[2][2];
867
0
    m.m[2][3] = -matrix.m[2][3];
868
0
    m.m[3][0] = -matrix.m[3][0];
869
0
    m.m[3][1] = -matrix.m[3][1];
870
0
    m.m[3][2] = -matrix.m[3][2];
871
0
    m.m[3][3] = -matrix.m[3][3];
872
0
    return m;
873
0
}
874
875
inline QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix)
876
0
{
877
0
    Q_DECL_UNINITIALIZED
878
0
    QMatrix4x4 m(Qt::Uninitialized);
879
0
    m.m[0][0] = matrix.m[0][0] * factor;
880
0
    m.m[0][1] = matrix.m[0][1] * factor;
881
0
    m.m[0][2] = matrix.m[0][2] * factor;
882
0
    m.m[0][3] = matrix.m[0][3] * factor;
883
0
    m.m[1][0] = matrix.m[1][0] * factor;
884
0
    m.m[1][1] = matrix.m[1][1] * factor;
885
0
    m.m[1][2] = matrix.m[1][2] * factor;
886
0
    m.m[1][3] = matrix.m[1][3] * factor;
887
0
    m.m[2][0] = matrix.m[2][0] * factor;
888
0
    m.m[2][1] = matrix.m[2][1] * factor;
889
0
    m.m[2][2] = matrix.m[2][2] * factor;
890
0
    m.m[2][3] = matrix.m[2][3] * factor;
891
0
    m.m[3][0] = matrix.m[3][0] * factor;
892
0
    m.m[3][1] = matrix.m[3][1] * factor;
893
0
    m.m[3][2] = matrix.m[3][2] * factor;
894
0
    m.m[3][3] = matrix.m[3][3] * factor;
895
0
    return m;
896
0
}
897
898
inline QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor)
899
0
{
900
0
    Q_DECL_UNINITIALIZED
901
0
    QMatrix4x4 m(Qt::Uninitialized);
902
0
    m.m[0][0] = matrix.m[0][0] * factor;
903
0
    m.m[0][1] = matrix.m[0][1] * factor;
904
0
    m.m[0][2] = matrix.m[0][2] * factor;
905
0
    m.m[0][3] = matrix.m[0][3] * factor;
906
0
    m.m[1][0] = matrix.m[1][0] * factor;
907
0
    m.m[1][1] = matrix.m[1][1] * factor;
908
0
    m.m[1][2] = matrix.m[1][2] * factor;
909
0
    m.m[1][3] = matrix.m[1][3] * factor;
910
0
    m.m[2][0] = matrix.m[2][0] * factor;
911
0
    m.m[2][1] = matrix.m[2][1] * factor;
912
0
    m.m[2][2] = matrix.m[2][2] * factor;
913
0
    m.m[2][3] = matrix.m[2][3] * factor;
914
0
    m.m[3][0] = matrix.m[3][0] * factor;
915
0
    m.m[3][1] = matrix.m[3][1] * factor;
916
0
    m.m[3][2] = matrix.m[3][2] * factor;
917
0
    m.m[3][3] = matrix.m[3][3] * factor;
918
0
    return m;
919
0
}
920
921
inline QPoint QMatrix4x4::map(const QPoint& point) const
922
0
{
923
0
    float xin, yin;
924
0
    float x, y, w;
925
0
    xin = point.x();
926
0
    yin = point.y();
927
0
    if (flagBits == QMatrix4x4::Identity) {
928
0
        return point;
929
0
    } else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
930
        // Translation | Scale
931
0
        return QPoint(qRound(xin * m[0][0] + m[3][0]),
932
0
                      qRound(yin * m[1][1] + m[3][1]));
933
0
    } else if (flagBits.toInt() < QMatrix4x4::Perspective) {
934
0
        return QPoint(qRound(xin * m[0][0] + yin * m[1][0] + m[3][0]),
935
0
                      qRound(xin * m[0][1] + yin * m[1][1] + m[3][1]));
936
0
    } else {
937
0
        x = xin * m[0][0] +
938
0
            yin * m[1][0] +
939
0
            m[3][0];
940
0
        y = xin * m[0][1] +
941
0
            yin * m[1][1] +
942
0
            m[3][1];
943
0
        w = xin * m[0][3] +
944
0
            yin * m[1][3] +
945
0
            m[3][3];
946
0
        if (w == 1.0f)
947
0
            return QPoint(qRound(x), qRound(y));
948
0
        else
949
0
            return QPoint(qRound(x / w), qRound(y / w));
950
0
    }
951
0
}
952
953
inline QPointF QMatrix4x4::map(const QPointF& point) const
954
0
{
955
0
    qreal xin, yin;
956
0
    qreal x, y, w;
957
0
    xin = point.x();
958
0
    yin = point.y();
959
0
    if (flagBits == QMatrix4x4::Identity) {
960
0
        return point;
961
0
    } else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
962
        // Translation | Scale
963
0
        return QPointF(xin * qreal(m[0][0]) + qreal(m[3][0]),
964
0
                       yin * qreal(m[1][1]) + qreal(m[3][1]));
965
0
    } else if (flagBits.toInt() < QMatrix4x4::Perspective) {
966
0
        return QPointF(xin * qreal(m[0][0]) + yin * qreal(m[1][0]) +
967
0
                       qreal(m[3][0]),
968
0
                       xin * qreal(m[0][1]) + yin * qreal(m[1][1]) +
969
0
                       qreal(m[3][1]));
970
0
    } else {
971
0
        x = xin * qreal(m[0][0]) +
972
0
            yin * qreal(m[1][0]) +
973
0
            qreal(m[3][0]);
974
0
        y = xin * qreal(m[0][1]) +
975
0
            yin * qreal(m[1][1]) +
976
0
            qreal(m[3][1]);
977
0
        w = xin * qreal(m[0][3]) +
978
0
            yin * qreal(m[1][3]) +
979
0
            qreal(m[3][3]);
980
0
        if (w == 1.0) {
981
0
            return QPointF(qreal(x), qreal(y));
982
0
        } else {
983
0
            return QPointF(qreal(x / w), qreal(y / w));
984
0
        }
985
0
    }
986
0
}
987
988
#ifndef QT_NO_VECTOR3D
989
990
inline QVector3D QMatrix4x4::map(const QVector3D& point) const
991
0
{
992
0
    float x, y, z, w;
993
0
    if (flagBits == QMatrix4x4::Identity) {
994
0
        return point;
995
0
    } else if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
996
0
        // Translation | Scale
997
0
        return QVector3D(point.x() * m[0][0] + m[3][0],
998
0
                         point.y() * m[1][1] + m[3][1],
999
0
                         point.z() * m[2][2] + m[3][2]);
1000
0
    } else if (flagBits.toInt() < QMatrix4x4::Rotation) {
1001
0
        // Translation | Scale | Rotation2D
1002
0
        return QVector3D(point.x() * m[0][0] + point.y() * m[1][0] + m[3][0],
1003
0
                         point.x() * m[0][1] + point.y() * m[1][1] + m[3][1],
1004
0
                         point.z() * m[2][2] + m[3][2]);
1005
0
    } else {
1006
0
        x = point.x() * m[0][0] +
1007
0
            point.y() * m[1][0] +
1008
0
            point.z() * m[2][0] +
1009
0
            m[3][0];
1010
0
        y = point.x() * m[0][1] +
1011
0
            point.y() * m[1][1] +
1012
0
            point.z() * m[2][1] +
1013
0
            m[3][1];
1014
0
        z = point.x() * m[0][2] +
1015
0
            point.y() * m[1][2] +
1016
0
            point.z() * m[2][2] +
1017
0
            m[3][2];
1018
0
        w = point.x() * m[0][3] +
1019
0
            point.y() * m[1][3] +
1020
0
            point.z() * m[2][3] +
1021
0
            m[3][3];
1022
0
        if (w == 1.0f)
1023
0
            return QVector3D(x, y, z);
1024
0
        else
1025
0
            return QVector3D(x / w, y / w, z / w);
1026
0
    }
1027
0
}
1028
1029
inline QVector3D QMatrix4x4::mapVector(const QVector3D& vector) const
1030
0
{
1031
0
    if (flagBits.toInt() < Scale) {
1032
0
        // Translation
1033
0
        return vector;
1034
0
    } else if (flagBits.toInt() < Rotation2D) {
1035
0
        // Translation | Scale
1036
0
        return QVector3D(vector.x() * m[0][0],
1037
0
                         vector.y() * m[1][1],
1038
0
                         vector.z() * m[2][2]);
1039
0
    } else {
1040
0
        return QVector3D(vector.x() * m[0][0] +
1041
0
                         vector.y() * m[1][0] +
1042
0
                         vector.z() * m[2][0],
1043
0
                         vector.x() * m[0][1] +
1044
0
                         vector.y() * m[1][1] +
1045
0
                         vector.z() * m[2][1],
1046
0
                         vector.x() * m[0][2] +
1047
0
                         vector.y() * m[1][2] +
1048
0
                         vector.z() * m[2][2]);
1049
0
    }
1050
0
}
1051
1052
#endif
1053
1054
#ifndef QT_NO_VECTOR4D
1055
1056
inline QVector4D QMatrix4x4::map(const QVector4D& point) const
1057
0
{
1058
0
    return *this * point;
1059
0
}
1060
1061
#endif
1062
1063
inline float *QMatrix4x4::data()
1064
0
{
1065
    // We have to assume that the caller will modify the matrix elements,
1066
    // so we flip it over to "General" mode.
1067
0
    flagBits = General;
1068
0
    return *m;
1069
0
}
1070
1071
inline void QMatrix4x4::viewport(const QRectF &rect)
1072
0
{
1073
0
    viewport(float(rect.x()), float(rect.y()), float(rect.width()), float(rect.height()));
1074
0
}
1075
1076
QT_WARNING_POP
1077
1078
#ifndef QT_NO_DEBUG_STREAM
1079
Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
1080
#endif
1081
1082
#ifndef QT_NO_DATASTREAM
1083
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QMatrix4x4 &);
1084
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QMatrix4x4 &);
1085
#endif
1086
1087
#endif
1088
1089
QT_END_NAMESPACE
1090
1091
#endif