Coverage Report

Created: 2026-08-11 07:29

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