summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2020-01-23 11:52:51 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2020-02-28 18:08:45 +0100
commit5ebb03c47604e0597502fbe1069de636987f33fc (patch)
tree7b138570063de3eff29925f79f01b9386740d690
parent543e87c65a8c8a9215c7fa1647792da77c2f6925 (diff)
Remove flagBits from QMatrix4x4
Change-Id: I14a22f3272b4793abd1e1b448351c94d3e07e946 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r--src/gui/math3d/qmatrix4x4.cpp564
-rw-r--r--src/gui/math3d/qmatrix4x4.h271
-rw-r--r--tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp7
3 files changed, 185 insertions, 657 deletions
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp
index 2adb94573b..2297342be7 100644
--- a/src/gui/math3d/qmatrix4x4.cpp
+++ b/src/gui/math3d/qmatrix4x4.cpp
@@ -105,7 +105,6 @@ QMatrix4x4::QMatrix4x4(const float *values)
for (int row = 0; row < 4; ++row)
for (int col = 0; col < 4; ++col)
m[col][row] = values[row * 4 + col];
- flagBits = General;
}
/*!
@@ -183,7 +182,6 @@ QMatrix4x4::QMatrix4x4(const float *values, int cols, int rows)
m[col][row] = 0.0f;
}
}
- flagBits = General;
}
/*!
@@ -215,7 +213,6 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform)
m[3][1] = transform.dy();
m[3][2] = 0.0f;
m[3][3] = transform.m33();
- flagBits = General;
}
/*!
@@ -349,15 +346,11 @@ static inline void copyToDoubles(const float m[4][4], double mm[4][4])
*/
double QMatrix4x4::determinant() const
{
- if ((flagBits & ~(Translation | Rotation2D | Rotation)) == Identity)
+ if (isIdentity())
return 1.0;
double mm[4][4];
copyToDoubles(m, mm);
- if (flagBits < Rotation2D)
- return mm[0][0] * mm[1][1] * mm[2][2]; // Translation | Scale
- if (flagBits < Perspective)
- return matrixDet3(mm, 0, 1, 2, 0, 1, 2);
return matrixDet4(mm);
}
@@ -376,77 +369,10 @@ double QMatrix4x4::determinant() const
QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const
{
// Handle some of the easy cases first.
- if (flagBits == Identity) {
+ if (isIdentity()) {
if (invertible)
*invertible = true;
return QMatrix4x4();
- } else if (flagBits == Translation) {
- QMatrix4x4 inv;
- inv.m[3][0] = -m[3][0];
- inv.m[3][1] = -m[3][1];
- inv.m[3][2] = -m[3][2];
- inv.flagBits = Translation;
- if (invertible)
- *invertible = true;
- return inv;
- } else if (flagBits < Rotation2D) {
- // Translation | Scale
- if (m[0][0] == 0 || m[1][1] == 0 || m[2][2] == 0) {
- if (invertible)
- *invertible = false;
- return QMatrix4x4();
- }
- QMatrix4x4 inv;
- inv.m[0][0] = 1.0f / m[0][0];
- inv.m[1][1] = 1.0f / m[1][1];
- inv.m[2][2] = 1.0f / m[2][2];
- inv.m[3][0] = -m[3][0] * inv.m[0][0];
- inv.m[3][1] = -m[3][1] * inv.m[1][1];
- inv.m[3][2] = -m[3][2] * inv.m[2][2];
- inv.flagBits = flagBits;
-
- if (invertible)
- *invertible = true;
- return inv;
- } else if ((flagBits & ~(Translation | Rotation2D | Rotation)) == Identity) {
- if (invertible)
- *invertible = true;
- return orthonormalInverse();
- } else if (flagBits < Perspective) {
- QMatrix4x4 inv(1); // The "1" says to not load the identity.
-
- double mm[4][4];
- copyToDoubles(m, mm);
-
- double det = matrixDet3(mm, 0, 1, 2, 0, 1, 2);
- if (det == 0.0f) {
- if (invertible)
- *invertible = false;
- return QMatrix4x4();
- }
- det = 1.0f / det;
-
- inv.m[0][0] = matrixDet2(mm, 1, 2, 1, 2) * det;
- inv.m[0][1] = -matrixDet2(mm, 0, 2, 1, 2) * det;
- inv.m[0][2] = matrixDet2(mm, 0, 1, 1, 2) * det;
- inv.m[0][3] = 0;
- inv.m[1][0] = -matrixDet2(mm, 1, 2, 0, 2) * det;
- inv.m[1][1] = matrixDet2(mm, 0, 2, 0, 2) * det;
- inv.m[1][2] = -matrixDet2(mm, 0, 1, 0, 2) * det;
- inv.m[1][3] = 0;
- inv.m[2][0] = matrixDet2(mm, 1, 2, 0, 1) * det;
- inv.m[2][1] = -matrixDet2(mm, 0, 2, 0, 1) * det;
- inv.m[2][2] = matrixDet2(mm, 0, 1, 0, 1) * det;
- inv.m[2][3] = 0;
- 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];
- 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];
- 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];
- inv.m[3][3] = 1;
- inv.flagBits = flagBits;
-
- if (invertible)
- *invertible = true;
- return inv;
}
QMatrix4x4 inv(1); // The "1" says to not load the identity.
@@ -478,7 +404,6 @@ QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const
inv.m[3][1] = matrixDet3(mm, 0, 2, 3, 0, 1, 2) * det;
inv.m[3][2] = -matrixDet3(mm, 0, 1, 3, 0, 1, 2) * det;
inv.m[3][3] = matrixDet3(mm, 0, 1, 2, 0, 1, 2) * det;
- inv.flagBits = flagBits;
if (invertible)
*invertible = true;
@@ -497,32 +422,6 @@ QMatrix3x3 QMatrix4x4::normalMatrix() const
{
QMatrix3x3 inv;
- // Handle the simple cases first.
- if (flagBits < Scale) {
- // Translation
- return inv;
- } else if (flagBits < Rotation2D) {
- // Translation | Scale
- if (m[0][0] == 0.0f || m[1][1] == 0.0f || m[2][2] == 0.0f)
- return inv;
- inv.data()[0] = 1.0f / m[0][0];
- inv.data()[4] = 1.0f / m[1][1];
- inv.data()[8] = 1.0f / m[2][2];
- return inv;
- } else if ((flagBits & ~(Translation | Rotation2D | Rotation)) == Identity) {
- float *invm = inv.data();
- invm[0 + 0 * 3] = m[0][0];
- invm[1 + 0 * 3] = m[0][1];
- invm[2 + 0 * 3] = m[0][2];
- invm[0 + 1 * 3] = m[1][0];
- invm[1 + 1 * 3] = m[1][1];
- invm[2 + 1 * 3] = m[1][2];
- invm[0 + 2 * 3] = m[2][0];
- invm[1 + 2 * 3] = m[2][1];
- invm[2 + 2 * 3] = m[2][2];
- return inv;
- }
-
double mm[4][4];
copyToDoubles(m, mm);
double det = matrixDet3(mm, 0, 1, 2, 0, 1, 2);
@@ -557,8 +456,6 @@ QMatrix4x4 QMatrix4x4::transposed() const
result.m[col][row] = m[row][col];
}
}
- // When a translation is transposed, it becomes a perspective transformation.
- result.flagBits = (flagBits & Translation ? General : flagBits);
return result;
}
@@ -610,7 +507,6 @@ QMatrix4x4& QMatrix4x4::operator/=(float divisor)
m[3][1] /= divisor;
m[3][2] /= divisor;
m[3][3] /= divisor;
- flagBits = General;
return *this;
}
@@ -767,7 +663,6 @@ QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor)
m.m[3][1] = matrix.m[3][1] / divisor;
m.m[3][2] = matrix.m[3][2] / divisor;
m.m[3][3] = matrix.m[3][3] / divisor;
- m.flagBits = QMatrix4x4::General;
return m;
}
@@ -789,38 +684,21 @@ QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor)
*/
void QMatrix4x4::scale(const QVector3D& vector)
{
- float vx = vector.x();
- float vy = vector.y();
- float vz = vector.z();
- if (flagBits < Scale) {
- m[0][0] = vx;
- m[1][1] = vy;
- m[2][2] = vz;
- } else if (flagBits < Rotation2D) {
- m[0][0] *= vx;
- m[1][1] *= vy;
- m[2][2] *= vz;
- } else if (flagBits < Rotation) {
- m[0][0] *= vx;
- m[0][1] *= vx;
- m[1][0] *= vy;
- m[1][1] *= vy;
- m[2][2] *= vz;
- } else {
- m[0][0] *= vx;
- m[0][1] *= vx;
- m[0][2] *= vx;
- m[0][3] *= vx;
- m[1][0] *= vy;
- m[1][1] *= vy;
- m[1][2] *= vy;
- m[1][3] *= vy;
- m[2][0] *= vz;
- m[2][1] *= vz;
- m[2][2] *= vz;
- m[2][3] *= vz;
- }
- flagBits |= Scale;
+ const float vx = vector.x();
+ const float vy = vector.y();
+ const float vz = vector.z();
+ m[0][0] *= vx;
+ m[0][1] *= vx;
+ m[0][2] *= vx;
+ m[0][3] *= vx;
+ m[1][0] *= vy;
+ m[1][1] *= vy;
+ m[1][2] *= vy;
+ m[1][3] *= vy;
+ m[2][0] *= vz;
+ m[2][1] *= vz;
+ m[2][2] *= vz;
+ m[2][3] *= vz;
}
#endif
@@ -835,28 +713,14 @@ void QMatrix4x4::scale(const QVector3D& vector)
*/
void QMatrix4x4::scale(float x, float y)
{
- if (flagBits < Scale) {
- m[0][0] = x;
- m[1][1] = y;
- } else if (flagBits < Rotation2D) {
- m[0][0] *= x;
- m[1][1] *= y;
- } else if (flagBits < Rotation) {
- m[0][0] *= x;
- m[0][1] *= x;
- m[1][0] *= y;
- m[1][1] *= y;
- } else {
- m[0][0] *= x;
- m[0][1] *= x;
- m[0][2] *= x;
- m[0][3] *= x;
- m[1][0] *= y;
- m[1][1] *= y;
- m[1][2] *= y;
- m[1][3] *= y;
- }
- flagBits |= Scale;
+ m[0][0] *= x;
+ m[0][1] *= x;
+ m[0][2] *= x;
+ m[0][3] *= x;
+ m[1][0] *= y;
+ m[1][1] *= y;
+ m[1][2] *= y;
+ m[1][3] *= y;
}
/*!
@@ -869,35 +733,18 @@ void QMatrix4x4::scale(float x, float y)
*/
void QMatrix4x4::scale(float x, float y, float z)
{
- if (flagBits < Scale) {
- m[0][0] = x;
- m[1][1] = y;
- m[2][2] = z;
- } else if (flagBits < Rotation2D) {
- m[0][0] *= x;
- m[1][1] *= y;
- m[2][2] *= z;
- } else if (flagBits < Rotation) {
- m[0][0] *= x;
- m[0][1] *= x;
- m[1][0] *= y;
- m[1][1] *= y;
- m[2][2] *= z;
- } else {
- m[0][0] *= x;
- m[0][1] *= x;
- m[0][2] *= x;
- m[0][3] *= x;
- m[1][0] *= y;
- m[1][1] *= y;
- m[1][2] *= y;
- m[1][3] *= y;
- m[2][0] *= z;
- m[2][1] *= z;
- m[2][2] *= z;
- m[2][3] *= z;
- }
- flagBits |= Scale;
+ m[0][0] *= x;
+ m[0][1] *= x;
+ m[0][2] *= x;
+ m[0][3] *= x;
+ m[1][0] *= y;
+ m[1][1] *= y;
+ m[1][2] *= y;
+ m[1][3] *= y;
+ m[2][0] *= z;
+ m[2][1] *= z;
+ m[2][2] *= z;
+ m[2][3] *= z;
}
/*!
@@ -910,35 +757,18 @@ void QMatrix4x4::scale(float x, float y, float z)
*/
void QMatrix4x4::scale(float factor)
{
- if (flagBits < Scale) {
- m[0][0] = factor;
- m[1][1] = factor;
- m[2][2] = factor;
- } else if (flagBits < Rotation2D) {
- m[0][0] *= factor;
- m[1][1] *= factor;
- m[2][2] *= factor;
- } else if (flagBits < Rotation) {
- m[0][0] *= factor;
- m[0][1] *= factor;
- m[1][0] *= factor;
- m[1][1] *= factor;
- m[2][2] *= factor;
- } else {
- m[0][0] *= factor;
- m[0][1] *= factor;
- m[0][2] *= factor;
- m[0][3] *= factor;
- m[1][0] *= factor;
- m[1][1] *= factor;
- m[1][2] *= factor;
- m[1][3] *= factor;
- m[2][0] *= factor;
- m[2][1] *= factor;
- m[2][2] *= factor;
- m[2][3] *= factor;
- }
- flagBits |= Scale;
+ m[0][0] *= factor;
+ m[0][1] *= factor;
+ m[0][2] *= factor;
+ m[0][3] *= factor;
+ m[1][0] *= factor;
+ m[1][1] *= factor;
+ m[1][2] *= factor;
+ m[1][3] *= factor;
+ m[2][0] *= factor;
+ m[2][1] *= factor;
+ m[2][2] *= factor;
+ m[2][3] *= factor;
}
#ifndef QT_NO_VECTOR3D
@@ -951,36 +781,13 @@ void QMatrix4x4::scale(float factor)
void QMatrix4x4::translate(const QVector3D& vector)
{
- float vx = vector.x();
- float vy = vector.y();
- float vz = vector.z();
- if (flagBits == Identity) {
- m[3][0] = vx;
- m[3][1] = vy;
- m[3][2] = vz;
- } else if (flagBits == Translation) {
- m[3][0] += vx;
- m[3][1] += vy;
- m[3][2] += vz;
- } else if (flagBits == Scale) {
- m[3][0] = m[0][0] * vx;
- m[3][1] = m[1][1] * vy;
- m[3][2] = m[2][2] * vz;
- } else if (flagBits == (Translation | Scale)) {
- m[3][0] += m[0][0] * vx;
- m[3][1] += m[1][1] * vy;
- m[3][2] += m[2][2] * vz;
- } else if (flagBits < Rotation) {
- m[3][0] += m[0][0] * vx + m[1][0] * vy;
- m[3][1] += m[0][1] * vx + m[1][1] * vy;
- m[3][2] += m[2][2] * vz;
- } else {
- m[3][0] += m[0][0] * vx + m[1][0] * vy + m[2][0] * vz;
- m[3][1] += m[0][1] * vx + m[1][1] * vy + m[2][1] * vz;
- m[3][2] += m[0][2] * vx + m[1][2] * vy + m[2][2] * vz;
- m[3][3] += m[0][3] * vx + m[1][3] * vy + m[2][3] * vz;
- }
- flagBits |= Translation;
+ const float vx = vector.x();
+ const float vy = vector.y();
+ const float vz = vector.z();
+ m[3][0] += m[0][0] * vx + m[1][0] * vy + m[2][0] * vz;
+ m[3][1] += m[0][1] * vx + m[1][1] * vy + m[2][1] * vz;
+ m[3][2] += m[0][2] * vx + m[1][2] * vy + m[2][2] * vz;
+ m[3][3] += m[0][3] * vx + m[1][3] * vy + m[2][3] * vz;
}
#endif
@@ -994,28 +801,10 @@ void QMatrix4x4::translate(const QVector3D& vector)
*/
void QMatrix4x4::translate(float x, float y)
{
- if (flagBits == Identity) {
- m[3][0] = x;
- m[3][1] = y;
- } else if (flagBits == Translation) {
- m[3][0] += x;
- m[3][1] += y;
- } else if (flagBits == Scale) {
- m[3][0] = m[0][0] * x;
- m[3][1] = m[1][1] * y;
- } else if (flagBits == (Translation | Scale)) {
- m[3][0] += m[0][0] * x;
- m[3][1] += m[1][1] * y;
- } else if (flagBits < Rotation) {
- m[3][0] += m[0][0] * x + m[1][0] * y;
- m[3][1] += m[0][1] * x + m[1][1] * y;
- } else {
- m[3][0] += m[0][0] * x + m[1][0] * y;
- m[3][1] += m[0][1] * x + m[1][1] * y;
- m[3][2] += m[0][2] * x + m[1][2] * y;
- m[3][3] += m[0][3] * x + m[1][3] * y;
- }
- flagBits |= Translation;
+ m[3][0] += m[0][0] * x + m[1][0] * y;
+ m[3][1] += m[0][1] * x + m[1][1] * y;
+ m[3][2] += m[0][2] * x + m[1][2] * y;
+ m[3][3] += m[0][3] * x + m[1][3] * y;
}
/*!
@@ -1028,33 +817,10 @@ void QMatrix4x4::translate(float x, float y)
*/
void QMatrix4x4::translate(float x, float y, float z)
{
- if (flagBits == Identity) {
- m[3][0] = x;
- m[3][1] = y;
- m[3][2] = z;
- } else if (flagBits == Translation) {
- m[3][0] += x;
- m[3][1] += y;
- m[3][2] += z;
- } else if (flagBits == Scale) {
- m[3][0] = m[0][0] * x;
- m[3][1] = m[1][1] * y;
- m[3][2] = m[2][2] * z;
- } else if (flagBits == (Translation | Scale)) {
- m[3][0] += m[0][0] * x;
- m[3][1] += m[1][1] * y;
- m[3][2] += m[2][2] * z;
- } else if (flagBits < Rotation) {
- m[3][0] += m[0][0] * x + m[1][0] * y;
- m[3][1] += m[0][1] * x + m[1][1] * y;
- m[3][2] += m[2][2] * z;
- } else {
- m[3][0] += m[0][0] * x + m[1][0] * y + m[2][0] * z;
- m[3][1] += m[0][1] * x + m[1][1] * y + m[2][1] * z;
- m[3][2] += m[0][2] * x + m[1][2] * y + m[2][2] * z;
- m[3][3] += m[0][3] * x + m[1][3] * y + m[2][3] * z;
- }
- flagBits |= Translation;
+ m[3][0] += m[0][0] * x + m[1][0] * y + m[2][0] * z;
+ m[3][1] += m[0][1] * x + m[1][1] * y + m[2][1] * z;
+ m[3][2] += m[0][2] * x + m[1][2] * y + m[2][2] * z;
+ m[3][3] += m[0][3] * x + m[1][3] * y + m[2][3] * z;
}
#ifndef QT_NO_VECTOR3D
@@ -1115,7 +881,6 @@ void QMatrix4x4::rotate(float angle, float x, float y, float z)
m[0][3] = (tmp = m[0][3]) * c + m[1][3] * s;
m[1][3] = m[1][3] * c - tmp * s;
- flagBits |= Rotation2D;
return;
}
} else if (z == 0.0f) {
@@ -1132,7 +897,6 @@ void QMatrix4x4::rotate(float angle, float x, float y, float z)
m[2][3] = (tmp = m[2][3]) * c + m[0][3] * s;
m[0][3] = m[0][3] * c - tmp * s;
- flagBits |= Rotation;
return;
}
} else if (y == 0.0f && z == 0.0f) {
@@ -1149,7 +913,6 @@ void QMatrix4x4::rotate(float angle, float x, float y, float z)
m[1][3] = (tmp = m[1][3]) * c + m[2][3] * s;
m[2][3] = m[2][3] * c - tmp * s;
- flagBits |= Rotation;
return;
}
@@ -1180,7 +943,6 @@ void QMatrix4x4::rotate(float angle, float x, float y, float z)
rot.m[1][3] = 0.0f;
rot.m[2][3] = 0.0f;
rot.m[3][3] = 1.0f;
- rot.flagBits = Rotation;
*this *= rot;
}
@@ -1204,7 +966,7 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
s = 0.0f;
c = -1.0f;
} else {
- float a = qDegreesToRadians(angle);
+ const float a = qDegreesToRadians(angle);
c = std::cos(a);
s = std::sin(a);
}
@@ -1224,7 +986,6 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
m[0][3] = (tmp = m[0][3]) * c + m[1][3] * s;
m[1][3] = m[1][3] * c - tmp * s;
- flagBits |= Rotation2D;
return;
}
} else if (z == 0.0f) {
@@ -1235,7 +996,6 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
m[0][1] = m[0][1] * c + m[3][1] * s * inv_dist_to_plane;
m[0][2] = m[0][2] * c + m[3][2] * s * inv_dist_to_plane;
m[0][3] = m[0][3] * c + m[3][3] * s * inv_dist_to_plane;
- flagBits = General;
return;
}
} else if (y == 0.0f && z == 0.0f) {
@@ -1246,7 +1006,6 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
m[1][1] = m[1][1] * c - m[3][1] * s * inv_dist_to_plane;
m[1][2] = m[1][2] * c - m[3][2] * s * inv_dist_to_plane;
m[1][3] = m[1][3] * c - m[3][3] * s * inv_dist_to_plane;
- flagBits = General;
return;
}
double len = double(x) * double(x) +
@@ -1258,7 +1017,7 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
y = float(double(y) / len);
z = float(double(z) / len);
}
- float ic = 1.0f - c;
+ const float ic = 1.0f - c;
QMatrix4x4 rot(1); // The "1" says to not load the identity.
rot.m[0][0] = x * x * ic + c;
rot.m[1][0] = x * y * ic - z * s;
@@ -1276,7 +1035,6 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
rot.m[1][3] = (y * z * ic + x * s) * -inv_dist_to_plane;
rot.m[2][3] = 0.0f;
rot.m[3][3] = 1.0f;
- rot.flagBits = General;
*this *= rot;
}
@@ -1325,7 +1083,6 @@ void QMatrix4x4::rotate(const QQuaternion& quaternion)
m.m[1][3] = 0.0f;
m.m[2][3] = 0.0f;
m.m[3][3] = 1.0f;
- m.flagBits = Rotation;
*this *= m;
}
@@ -1378,9 +1135,9 @@ void QMatrix4x4::ortho(float left, float right, float bottom, float top, float n
return;
// Construct the projection.
- float width = right - left;
- float invheight = top - bottom;
- float clip = farPlane - nearPlane;
+ const float width = right - left;
+ const float invheight = top - bottom;
+ const float clip = farPlane - nearPlane;
QMatrix4x4 m(1);
m.m[0][0] = 2.0f / width;
m.m[1][0] = 0.0f;
@@ -1398,7 +1155,6 @@ void QMatrix4x4::ortho(float left, float right, float bottom, float top, float n
m.m[1][3] = 0.0f;
m.m[2][3] = 0.0f;
m.m[3][3] = 1.0f;
- m.flagBits = Translation | Scale;
// Apply the projection.
*this *= m;
@@ -1420,9 +1176,9 @@ void QMatrix4x4::frustum(float left, float right, float bottom, float top, float
// Construct the projection.
QMatrix4x4 m(1);
- float width = right - left;
- float invheight = top - bottom;
- float clip = farPlane - nearPlane;
+ const float width = right - left;
+ const float invheight = top - bottom;
+ const float clip = farPlane - nearPlane;
m.m[0][0] = 2.0f * nearPlane / width;
m.m[1][0] = 0.0f;
m.m[2][0] = (left + right) / width;
@@ -1439,7 +1195,6 @@ void QMatrix4x4::frustum(float left, float right, float bottom, float top, float
m.m[1][3] = 0.0f;
m.m[2][3] = -1.0f;
m.m[3][3] = 0.0f;
- m.flagBits = General;
// Apply the projection.
*this *= m;
@@ -1463,12 +1218,12 @@ void QMatrix4x4::perspective(float verticalAngle, float aspectRatio, float nearP
// Construct the projection.
QMatrix4x4 m(1);
- float radians = qDegreesToRadians(verticalAngle / 2.0f);
- float sine = std::sin(radians);
+ const float radians = qDegreesToRadians(verticalAngle / 2.0f);
+ const float sine = std::sin(radians);
if (sine == 0.0f)
return;
- float cotan = std::cos(radians) / sine;
- float clip = farPlane - nearPlane;
+ const float cotan = std::cos(radians) / sine;
+ const float clip = farPlane - nearPlane;
m.m[0][0] = cotan / aspectRatio;
m.m[1][0] = 0.0f;
m.m[2][0] = 0.0f;
@@ -1485,7 +1240,6 @@ void QMatrix4x4::perspective(float verticalAngle, float aspectRatio, float nearP
m.m[1][3] = 0.0f;
m.m[2][3] = -1.0f;
m.m[3][3] = 0.0f;
- m.flagBits = General;
// Apply the projection.
*this *= m;
@@ -1529,7 +1283,6 @@ void QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, const QVe
m.m[1][3] = 0.0f;
m.m[2][3] = 0.0f;
m.m[3][3] = 1.0f;
- m.flagBits = Rotation;
*this *= m;
translate(-eye);
@@ -1578,7 +1331,6 @@ void QMatrix4x4::viewport(float left, float bottom, float width, float height, f
m.m[1][3] = 0.0f;
m.m[2][3] = 0.0f;
m.m[3][3] = 1.0f;
- m.flagBits = General;
*this *= m;
}
@@ -1598,21 +1350,14 @@ void QMatrix4x4::flipCoordinates()
// Multiplying the y and z coordinates with -1 does NOT flip between right-handed and
// left-handed coordinate systems, it just rotates 180 degrees around the x axis, so
// I'm deprecating this function.
- if (flagBits < Rotation2D) {
- // Translation | Scale
- m[1][1] = -m[1][1];
- m[2][2] = -m[2][2];
- } else {
- m[1][0] = -m[1][0];
- m[1][1] = -m[1][1];
- m[1][2] = -m[1][2];
- m[1][3] = -m[1][3];
- m[2][0] = -m[2][0];
- m[2][1] = -m[2][1];
- m[2][2] = -m[2][2];
- m[2][3] = -m[2][3];
- }
- flagBits |= Scale;
+ m[1][0] = -m[1][0];
+ m[1][1] = -m[1][1];
+ m[1][2] = -m[1][2];
+ m[1][3] = -m[1][3];
+ m[2][0] = -m[2][0];
+ m[2][1] = -m[2][1];
+ m[2][2] = -m[2][2];
+ m[2][3] = -m[2][3];
}
/*!
@@ -1676,7 +1421,7 @@ QTransform QMatrix4x4::toTransform(float distanceToPlane) const
// | 0 0 d 1 |
// where d = -1 / distanceToPlane. After projection, row 3 and
// column 3 are dropped to form the final QTransform.
- float d = 1.0f / distanceToPlane;
+ const float d = 1.0f / distanceToPlane;
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);
@@ -1748,38 +1493,16 @@ QTransform QMatrix4x4::toTransform(float distanceToPlane) const
*/
QRect QMatrix4x4::mapRect(const QRect& rect) const
{
- if (flagBits < Scale) {
- // Translation
- return QRect(qRound(rect.x() + m[3][0]),
- qRound(rect.y() + m[3][1]),
- rect.width(), rect.height());
- } else if (flagBits < Rotation2D) {
- // Translation | Scale
- float x = rect.x() * m[0][0] + m[3][0];
- float y = rect.y() * m[1][1] + m[3][1];
- float w = rect.width() * m[0][0];
- float h = rect.height() * m[1][1];
- if (w < 0) {
- w = -w;
- x -= w;
- }
- if (h < 0) {
- h = -h;
- y -= h;
- }
- return QRect(qRound(x), qRound(y), qRound(w), qRound(h));
- }
-
- QPoint tl = map(rect.topLeft());
- QPoint tr = map(QPoint(rect.x() + rect.width(), rect.y()));
- QPoint bl = map(QPoint(rect.x(), rect.y() + rect.height()));
- QPoint br = map(QPoint(rect.x() + rect.width(),
- rect.y() + rect.height()));
+ const QPoint tl = map(rect.topLeft());
+ const QPoint tr = map(QPoint(rect.x() + rect.width(), rect.y()));
+ const QPoint bl = map(QPoint(rect.x(), rect.y() + rect.height()));
+ const QPoint br = map(QPoint(rect.x() + rect.width(),
+ rect.y() + rect.height()));
- int xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
- int xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
- int ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
- int ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
+ const int xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
+ const int xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
+ const int ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
+ const int ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
return QRect(xmin, ymin, xmax - xmin, ymax - ymin);
}
@@ -1794,33 +1517,13 @@ QRect QMatrix4x4::mapRect(const QRect& rect) const
*/
QRectF QMatrix4x4::mapRect(const QRectF& rect) const
{
- if (flagBits < Scale) {
- // Translation
- return rect.translated(m[3][0], m[3][1]);
- } else if (flagBits < Rotation2D) {
- // Translation | Scale
- float x = rect.x() * m[0][0] + m[3][0];
- float y = rect.y() * m[1][1] + m[3][1];
- float w = rect.width() * m[0][0];
- float h = rect.height() * m[1][1];
- if (w < 0) {
- w = -w;
- x -= w;
- }
- if (h < 0) {
- h = -h;
- y -= h;
- }
- return QRectF(x, y, w, h);
- }
-
- QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());
- QPointF bl = map(rect.bottomLeft()); QPointF br = map(rect.bottomRight());
+ const QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());
+ const QPointF bl = map(rect.bottomLeft()); QPointF br = map(rect.bottomRight());
- float xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
- float xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
- float ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
- float ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
+ const float xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
+ const float xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
+ const float ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
+ const float ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
}
@@ -1878,8 +1581,6 @@ QMatrix4x4 QMatrix4x4::orthonormalInverse() const
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]);
result.m[3][3] = 1.0f;
- result.flagBits = flagBits;
-
return result;
}
@@ -1905,54 +1606,6 @@ QMatrix4x4 QMatrix4x4::orthonormalInverse() const
*/
void QMatrix4x4::optimize()
{
- // If the last row is not (0, 0, 0, 1), the matrix is not a special type.
- flagBits = General;
- if (m[0][3] != 0 || m[1][3] != 0 || m[2][3] != 0 || m[3][3] != 1)
- return;
-
- flagBits &= ~Perspective;
-
- // If the last column is (0, 0, 0, 1), then there is no translation.
- if (m[3][0] == 0 && m[3][1] == 0 && m[3][2] == 0)
- flagBits &= ~Translation;
-
- // If the two first elements of row 3 and column 3 are 0, then any rotation must be about Z.
- if (!m[0][2] && !m[1][2] && !m[2][0] && !m[2][1]) {
- flagBits &= ~Rotation;
- // If the six non-diagonal elements in the top left 3x3 matrix are 0, there is no rotation.
- if (!m[0][1] && !m[1][0]) {
- flagBits &= ~Rotation2D;
- // Check for identity.
- if (m[0][0] == 1 && m[1][1] == 1 && m[2][2] == 1)
- flagBits &= ~Scale;
- } else {
- // If the columns are orthonormal and form a right-handed system, then there is no scale.
- double mm[4][4];
- copyToDoubles(m, mm);
- double det = matrixDet2(mm, 0, 1, 0, 1);
- double lenX = mm[0][0] * mm[0][0] + mm[0][1] * mm[0][1];
- double lenY = mm[1][0] * mm[1][0] + mm[1][1] * mm[1][1];
- double lenZ = mm[2][2];
- if (qFuzzyCompare(det, 1.0) && qFuzzyCompare(lenX, 1.0)
- && qFuzzyCompare(lenY, 1.0) && qFuzzyCompare(lenZ, 1.0))
- {
- flagBits &= ~Scale;
- }
- }
- } else {
- // If the columns are orthonormal and form a right-handed system, then there is no scale.
- double mm[4][4];
- copyToDoubles(m, mm);
- double det = matrixDet3(mm, 0, 1, 2, 0, 1, 2);
- double lenX = mm[0][0] * mm[0][0] + mm[0][1] * mm[0][1] + mm[0][2] * mm[0][2];
- double lenY = mm[1][0] * mm[1][0] + mm[1][1] * mm[1][1] + mm[1][2] * mm[1][2];
- double lenZ = mm[2][0] * mm[2][0] + mm[2][1] * mm[2][1] + mm[2][2] * mm[2][2];
- if (qFuzzyCompare(det, 1.0) && qFuzzyCompare(lenX, 1.0)
- && qFuzzyCompare(lenY, 1.0) && qFuzzyCompare(lenZ, 1.0))
- {
- flagBits &= ~Scale;
- }
- }
}
/*!
@@ -1970,23 +1623,10 @@ QDebug operator<<(QDebug dbg, const QMatrix4x4 &m)
QDebugStateSaver saver(dbg);
// Create a string that represents the matrix type.
QByteArray bits;
- if (m.flagBits == QMatrix4x4::Identity) {
+ if (m.isIdentity()) {
bits = "Identity";
- } else if (m.flagBits == QMatrix4x4::General) {
- bits = "General";
} else {
- if ((m.flagBits & QMatrix4x4::Translation) != 0)
- bits += "Translation,";
- if ((m.flagBits & QMatrix4x4::Scale) != 0)
- bits += "Scale,";
- if ((m.flagBits & QMatrix4x4::Rotation2D) != 0)
- bits += "Rotation2D,";
- if ((m.flagBits & QMatrix4x4::Rotation) != 0)
- bits += "Rotation,";
- if ((m.flagBits & QMatrix4x4::Perspective) != 0)
- bits += "Perspective,";
- if (bits.size() > 0)
- bits = bits.left(bits.size() - 1);
+ bits = "General";
}
// Output in row-major order because it is more human-readable.
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
index 95f4db92ec..198a47c51b 100644
--- a/src/gui/math3d/qmatrix4x4.h
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -59,7 +59,7 @@ class Q_GUI_EXPORT QMatrix4x4
{
public:
inline QMatrix4x4() { setToIdentity(); }
- explicit QMatrix4x4(Qt::Initialization) : flagBits(General) {}
+ explicit QMatrix4x4(Qt::Initialization) {}
explicit QMatrix4x4(const float *values);
inline QMatrix4x4(float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
@@ -186,19 +186,9 @@ public:
void projectedRotate(float angle, float x, float y, float z);
private:
- float m[4][4]; // Column-major order to match OpenGL.
- int flagBits; // Flag bits from the enum below.
-
- // When matrices are multiplied, the flag bits are or-ed together.
- enum {
- Identity = 0x0000, // Identity matrix
- Translation = 0x0001, // Contains a translation
- Scale = 0x0002, // Contains a scale
- Rotation2D = 0x0004, // Contains a rotation about the Z axis
- Rotation = 0x0008, // Contains an arbitrary rotation
- Perspective = 0x0010, // Last row is different from (0, 0, 0, 1)
- General = 0x001f // General matrix, unknown contents
- };
+
+ // No other members are allowed in order to ensure a size of 16 * sizeof(float)
+ float m[4][4]; // Column-major order to match OpenGL.
// Construct without initializing identity matrix.
explicit QMatrix4x4(int) { }
@@ -222,7 +212,6 @@ inline QMatrix4x4::QMatrix4x4
m[1][0] = m12; m[1][1] = m22; m[1][2] = m32; m[1][3] = m42;
m[2][0] = m13; m[2][1] = m23; m[2][2] = m33; m[2][3] = m43;
m[3][0] = m14; m[3][1] = m24; m[3][2] = m34; m[3][3] = m44;
- flagBits = General;
}
template <int N, int M>
@@ -240,7 +229,6 @@ Q_INLINE_TEMPLATE QMatrix4x4::QMatrix4x4
m[matrixCol][matrixRow] = 0.0f;
}
}
- flagBits = General;
}
template <int N, int M>
@@ -270,7 +258,6 @@ inline const float& QMatrix4x4::operator()(int aRow, int aColumn) const
inline float& QMatrix4x4::operator()(int aRow, int aColumn)
{
Q_ASSERT(aRow >= 0 && aRow < 4 && aColumn >= 0 && aColumn < 4);
- flagBits = General;
return m[aColumn][aRow];
}
@@ -288,7 +275,6 @@ inline void QMatrix4x4::setColumn(int index, const QVector4D& value)
m[index][1] = value.y();
m[index][2] = value.z();
m[index][3] = value.w();
- flagBits = General;
}
inline QVector4D QMatrix4x4::row(int index) const
@@ -304,7 +290,6 @@ inline void QMatrix4x4::setRow(int index, const QVector4D& value)
m[1][index] = value.y();
m[2][index] = value.z();
m[3][index] = value.w();
- flagBits = General;
}
#endif
@@ -317,8 +302,6 @@ inline bool QMatrix4x4::isAffine() const
inline bool QMatrix4x4::isIdentity() const
{
- if (flagBits == Identity)
- return true;
if (m[0][0] != 1.0f || m[0][1] != 0.0f || m[0][2] != 0.0f)
return false;
if (m[0][3] != 0.0f || m[1][0] != 0.0f || m[1][1] != 1.0f)
@@ -350,7 +333,6 @@ inline void QMatrix4x4::setToIdentity()
m[3][1] = 0.0f;
m[3][2] = 0.0f;
m[3][3] = 1.0f;
- flagBits = Identity;
}
inline void QMatrix4x4::fill(float value)
@@ -371,7 +353,6 @@ inline void QMatrix4x4::fill(float value)
m[3][1] = value;
m[3][2] = value;
m[3][3] = value;
- flagBits = General;
}
inline QMatrix4x4& QMatrix4x4::operator+=(const QMatrix4x4& other)
@@ -392,7 +373,6 @@ inline QMatrix4x4& QMatrix4x4::operator+=(const QMatrix4x4& other)
m[3][1] += other.m[3][1];
m[3][2] += other.m[3][2];
m[3][3] += other.m[3][3];
- flagBits = General;
return *this;
}
@@ -414,25 +394,12 @@ inline QMatrix4x4& QMatrix4x4::operator-=(const QMatrix4x4& other)
m[3][1] -= other.m[3][1];
m[3][2] -= other.m[3][2];
m[3][3] -= other.m[3][3];
- flagBits = General;
return *this;
}
inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& o)
{
const QMatrix4x4 other = o; // prevent aliasing when &o == this ### Qt 6: take o by value
- flagBits |= other.flagBits;
-
- if (flagBits < Rotation2D) {
- m[3][0] += m[0][0] * other.m[3][0];
- m[3][1] += m[1][1] * other.m[3][1];
- m[3][2] += m[2][2] * other.m[3][2];
-
- m[0][0] *= other.m[0][0];
- m[1][1] *= other.m[1][1];
- m[2][2] *= other.m[2][2];
- return *this;
- }
float m0, m1, m2;
m0 = m[0][0] * other.m[0][0]
@@ -535,7 +502,6 @@ inline QMatrix4x4& QMatrix4x4::operator*=(float factor)
m[3][1] *= factor;
m[3][2] *= factor;
m[3][3] *= factor;
- flagBits = General;
return *this;
}
@@ -598,7 +564,6 @@ inline QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2)
m.m[3][1] = m1.m[3][1] + m2.m[3][1];
m.m[3][2] = m1.m[3][2] + m2.m[3][2];
m.m[3][3] = m1.m[3][3] + m2.m[3][3];
- m.flagBits = QMatrix4x4::General;
return m;
}
@@ -621,26 +586,11 @@ inline QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2)
m.m[3][1] = m1.m[3][1] - m2.m[3][1];
m.m[3][2] = m1.m[3][2] - m2.m[3][2];
m.m[3][3] = m1.m[3][3] - m2.m[3][3];
- m.flagBits = QMatrix4x4::General;
return m;
}
inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
{
- int flagBits = m1.flagBits | m2.flagBits;
- if (flagBits < QMatrix4x4::Rotation2D) {
- QMatrix4x4 m = m1;
- m.m[3][0] += m.m[0][0] * m2.m[3][0];
- m.m[3][1] += m.m[1][1] * m2.m[3][1];
- m.m[3][2] += m.m[2][2] * m2.m[3][2];
-
- m.m[0][0] *= m2.m[0][0];
- m.m[1][1] *= m2.m[1][1];
- m.m[2][2] *= m2.m[2][2];
- m.flagBits = flagBits;
- return m;
- }
-
QMatrix4x4 m(1);
m.m[0][0] = m1.m[0][0] * m2.m[0][0]
+ m1.m[1][0] * m2.m[0][1]
@@ -709,7 +659,6 @@ inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
+ m1.m[1][3] * m2.m[3][1]
+ m1.m[2][3] * m2.m[3][2]
+ m1.m[3][3] * m2.m[3][3];
- m.flagBits = flagBits;
return m;
}
@@ -717,20 +666,19 @@ inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
{
- float x, y, z, w;
- x = vector.x() * matrix.m[0][0] +
+ const float x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[0][1] +
vector.z() * matrix.m[0][2] +
matrix.m[0][3];
- y = vector.x() * matrix.m[1][0] +
+ const float y = vector.x() * matrix.m[1][0] +
vector.y() * matrix.m[1][1] +
vector.z() * matrix.m[1][2] +
matrix.m[1][3];
- z = vector.x() * matrix.m[2][0] +
+ const float z = vector.x() * matrix.m[2][0] +
vector.y() * matrix.m[2][1] +
vector.z() * matrix.m[2][2] +
matrix.m[2][3];
- w = vector.x() * matrix.m[3][0] +
+ const float w = vector.x() * matrix.m[3][0] +
vector.y() * matrix.m[3][1] +
vector.z() * matrix.m[3][2] +
matrix.m[3][3];
@@ -742,41 +690,29 @@ inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
{
- float x, y, z, w;
- if (matrix.flagBits == QMatrix4x4::Identity) {
+ if (matrix.isIdentity())
return vector;
- } else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
- // Translation | Scale
- return QVector3D(vector.x() * matrix.m[0][0] + matrix.m[3][0],
- vector.y() * matrix.m[1][1] + matrix.m[3][1],
- vector.z() * matrix.m[2][2] + matrix.m[3][2]);
- } else if (matrix.flagBits < QMatrix4x4::Rotation) {
- // Translation | Scale | Rotation2D
- return QVector3D(vector.x() * matrix.m[0][0] + vector.y() * matrix.m[1][0] + matrix.m[3][0],
- vector.x() * matrix.m[0][1] + vector.y() * matrix.m[1][1] + matrix.m[3][1],
- vector.z() * matrix.m[2][2] + matrix.m[3][2]);
- } else {
- x = vector.x() * matrix.m[0][0] +
- vector.y() * matrix.m[1][0] +
- vector.z() * matrix.m[2][0] +
- matrix.m[3][0];
- y = vector.x() * matrix.m[0][1] +
- vector.y() * matrix.m[1][1] +
- vector.z() * matrix.m[2][1] +
- matrix.m[3][1];
- z = vector.x() * matrix.m[0][2] +
- vector.y() * matrix.m[1][2] +
- vector.z() * matrix.m[2][2] +
- matrix.m[3][2];
- w = vector.x() * matrix.m[0][3] +
- vector.y() * matrix.m[1][3] +
- vector.z() * matrix.m[2][3] +
- matrix.m[3][3];
- if (w == 1.0f)
- return QVector3D(x, y, z);
- else
- return QVector3D(x / w, y / w, z / w);
- }
+
+ const float x = vector.x() * matrix.m[0][0] +
+ vector.y() * matrix.m[1][0] +
+ vector.z() * matrix.m[2][0] +
+ matrix.m[3][0];
+ const float y = vector.x() * matrix.m[0][1] +
+ vector.y() * matrix.m[1][1] +
+ vector.z() * matrix.m[2][1] +
+ matrix.m[3][1];
+ const float z = vector.x() * matrix.m[0][2] +
+ vector.y() * matrix.m[1][2] +
+ vector.z() * matrix.m[2][2] +
+ matrix.m[3][2];
+ const float w = vector.x() * matrix.m[0][3] +
+ vector.y() * matrix.m[1][3] +
+ vector.z() * matrix.m[2][3] +
+ matrix.m[3][3];
+ if (w == 1.0f)
+ return QVector3D(x, y, z);
+ else
+ return QVector3D(x / w, y / w, z / w);
}
#endif
@@ -785,20 +721,19 @@ inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)
{
- float x, y, z, w;
- x = vector.x() * matrix.m[0][0] +
+ const float x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[0][1] +
vector.z() * matrix.m[0][2] +
vector.w() * matrix.m[0][3];
- y = vector.x() * matrix.m[1][0] +
+ const float y = vector.x() * matrix.m[1][0] +
vector.y() * matrix.m[1][1] +
vector.z() * matrix.m[1][2] +
vector.w() * matrix.m[1][3];
- z = vector.x() * matrix.m[2][0] +
+ const float z = vector.x() * matrix.m[2][0] +
vector.y() * matrix.m[2][1] +
vector.z() * matrix.m[2][2] +
vector.w() * matrix.m[2][3];
- w = vector.x() * matrix.m[3][0] +
+ const float w = vector.x() * matrix.m[3][0] +
vector.y() * matrix.m[3][1] +
vector.z() * matrix.m[3][2] +
vector.w() * matrix.m[3][3];
@@ -807,20 +742,19 @@ inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)
inline QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector)
{
- float x, y, z, w;
- x = vector.x() * matrix.m[0][0] +
+ const float x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[1][0] +
vector.z() * matrix.m[2][0] +
vector.w() * matrix.m[3][0];
- y = vector.x() * matrix.m[0][1] +
+ const float y = vector.x() * matrix.m[0][1] +
vector.y() * matrix.m[1][1] +
vector.z() * matrix.m[2][1] +
vector.w() * matrix.m[3][1];
- z = vector.x() * matrix.m[0][2] +
+ const float z = vector.x() * matrix.m[0][2] +
vector.y() * matrix.m[1][2] +
vector.z() * matrix.m[2][2] +
vector.w() * matrix.m[3][2];
- w = vector.x() * matrix.m[0][3] +
+ const float w = vector.x() * matrix.m[0][3] +
vector.y() * matrix.m[1][3] +
vector.z() * matrix.m[2][3] +
vector.w() * matrix.m[3][3];
@@ -831,17 +765,15 @@ inline QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector)
inline QPoint operator*(const QPoint& point, const QMatrix4x4& matrix)
{
- float xin, yin;
- float x, y, w;
- xin = point.x();
- yin = point.y();
- x = xin * matrix.m[0][0] +
+ const float xin = point.x();
+ const float yin = point.y();
+ const float x = xin * matrix.m[0][0] +
yin * matrix.m[0][1] +
matrix.m[0][3];
- y = xin * matrix.m[1][0] +
+ const float y = xin * matrix.m[1][0] +
yin * matrix.m[1][1] +
matrix.m[1][3];
- w = xin * matrix.m[3][0] +
+ const float w = xin * matrix.m[3][0] +
yin * matrix.m[3][1] +
matrix.m[3][3];
if (w == 1.0f)
@@ -852,17 +784,15 @@ inline QPoint operator*(const QPoint& point, const QMatrix4x4& matrix)
inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)
{
- float xin, yin;
- float x, y, w;
- xin = float(point.x());
- yin = float(point.y());
- x = xin * matrix.m[0][0] +
+ const float xin = float(point.x());
+ const float yin = float(point.y());
+ const float x = xin * matrix.m[0][0] +
yin * matrix.m[0][1] +
matrix.m[0][3];
- y = xin * matrix.m[1][0] +
+ const float y = xin * matrix.m[1][0] +
yin * matrix.m[1][1] +
matrix.m[1][3];
- w = xin * matrix.m[3][0] +
+ const float w = xin * matrix.m[3][0] +
yin * matrix.m[3][1] +
matrix.m[3][3];
if (w == 1.0f) {
@@ -874,69 +804,46 @@ inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)
inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
{
- float xin, yin;
- float x, y, w;
- xin = point.x();
- yin = point.y();
- if (matrix.flagBits == QMatrix4x4::Identity) {
+ if (matrix.isIdentity())
return point;
- } else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
- // Translation | Scale
- return QPoint(qRound(xin * matrix.m[0][0] + matrix.m[3][0]),
- qRound(yin * matrix.m[1][1] + matrix.m[3][1]));
- } else if (matrix.flagBits < QMatrix4x4::Perspective) {
- return QPoint(qRound(xin * matrix.m[0][0] + yin * matrix.m[1][0] + matrix.m[3][0]),
- qRound(xin * matrix.m[0][1] + yin * matrix.m[1][1] + matrix.m[3][1]));
- } else {
- x = xin * matrix.m[0][0] +
- yin * matrix.m[1][0] +
- matrix.m[3][0];
- y = xin * matrix.m[0][1] +
- yin * matrix.m[1][1] +
- matrix.m[3][1];
- w = xin * matrix.m[0][3] +
- yin * matrix.m[1][3] +
- matrix.m[3][3];
- if (w == 1.0f)
- return QPoint(qRound(x), qRound(y));
- else
- return QPoint(qRound(x / w), qRound(y / w));
- }
+
+ const float xin = point.x();
+ const float yin = point.y();
+ const float x = xin * matrix.m[0][0] +
+ yin * matrix.m[1][0] +
+ matrix.m[3][0];
+ const float y = xin * matrix.m[0][1] +
+ yin * matrix.m[1][1] +
+ matrix.m[3][1];
+ const float w = xin * matrix.m[0][3] +
+ yin * matrix.m[1][3] +
+ matrix.m[3][3];
+ if (w == 1.0f)
+ return QPoint(qRound(x), qRound(y));
+
+ return QPoint(qRound(x / w), qRound(y / w));
}
inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
{
- qreal xin, yin;
- qreal x, y, w;
- xin = point.x();
- yin = point.y();
- if (matrix.flagBits == QMatrix4x4::Identity) {
+ if (matrix.isIdentity())
return point;
- } else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
- // Translation | Scale
- return QPointF(xin * qreal(matrix.m[0][0]) + qreal(matrix.m[3][0]),
- yin * qreal(matrix.m[1][1]) + qreal(matrix.m[3][1]));
- } else if (matrix.flagBits < QMatrix4x4::Perspective) {
- return QPointF(xin * qreal(matrix.m[0][0]) + yin * qreal(matrix.m[1][0]) +
- qreal(matrix.m[3][0]),
- xin * qreal(matrix.m[0][1]) + yin * qreal(matrix.m[1][1]) +
- qreal(matrix.m[3][1]));
- } else {
- x = xin * qreal(matrix.m[0][0]) +
+
+ const qreal xin = point.x();
+ const qreal yin = point.y();
+ const qreal x = xin * qreal(matrix.m[0][0]) +
yin * qreal(matrix.m[1][0]) +
qreal(matrix.m[3][0]);
- y = xin * qreal(matrix.m[0][1]) +
+ const qreal y = xin * qreal(matrix.m[0][1]) +
yin * qreal(matrix.m[1][1]) +
qreal(matrix.m[3][1]);
- w = xin * qreal(matrix.m[0][3]) +
+ const qreal w = xin * qreal(matrix.m[0][3]) +
yin * qreal(matrix.m[1][3]) +
qreal(matrix.m[3][3]);
- if (w == 1.0) {
- return QPointF(qreal(x), qreal(y));
- } else {
- return QPointF(qreal(x / w), qreal(y / w));
- }
- }
+ if (w == 1.0)
+ return QPointF(qreal(x), qreal(y));
+
+ return QPointF(qreal(x / w), qreal(y / w));
}
inline QMatrix4x4 operator-(const QMatrix4x4& matrix)
@@ -958,7 +865,6 @@ inline QMatrix4x4 operator-(const QMatrix4x4& matrix)
m.m[3][1] = -matrix.m[3][1];
m.m[3][2] = -matrix.m[3][2];
m.m[3][3] = -matrix.m[3][3];
- m.flagBits = QMatrix4x4::General;
return m;
}
@@ -981,7 +887,6 @@ inline QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix)
m.m[3][1] = matrix.m[3][1] * factor;
m.m[3][2] = matrix.m[3][2] * factor;
m.m[3][3] = matrix.m[3][3] * factor;
- m.flagBits = QMatrix4x4::General;
return m;
}
@@ -1004,7 +909,6 @@ inline QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor)
m.m[3][1] = matrix.m[3][1] * factor;
m.m[3][2] = matrix.m[3][2] * factor;
m.m[3][3] = matrix.m[3][3] * factor;
- m.flagBits = QMatrix4x4::General;
return m;
}
@@ -1047,25 +951,9 @@ inline QVector3D QMatrix4x4::map(const QVector3D& point) const
inline QVector3D QMatrix4x4::mapVector(const QVector3D& vector) const
{
- if (flagBits < Scale) {
- // Translation
- return vector;
- } else if (flagBits < Rotation2D) {
- // Translation | Scale
- return QVector3D(vector.x() * m[0][0],
- vector.y() * m[1][1],
- vector.z() * m[2][2]);
- } else {
- return QVector3D(vector.x() * m[0][0] +
- vector.y() * m[1][0] +
- vector.z() * m[2][0],
- vector.x() * m[0][1] +
- vector.y() * m[1][1] +
- vector.z() * m[2][1],
- vector.x() * m[0][2] +
- vector.y() * m[1][2] +
- vector.z() * m[2][2]);
- }
+ return QVector3D(vector.x() * m[0][0] + vector.y() * m[1][0] + vector.z() * m[2][0],
+ vector.x() * m[0][1] + vector.y() * m[1][1] + vector.z() * m[2][1],
+ vector.x() * m[0][2] + vector.y() * m[1][2] + vector.z() * m[2][2]);
}
#endif
@@ -1083,7 +971,6 @@ inline float *QMatrix4x4::data()
{
// We have to assume that the caller will modify the matrix elements,
// so we flip it over to "General" mode.
- flagBits = General;
return *m;
}
diff --git a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
index 26e22e5883..c39fd7f7bc 100644
--- a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
+++ b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
@@ -139,8 +139,8 @@ private slots:
void convertGeneric();
- void optimize_data();
- void optimize();
+// void optimize_data();
+// void optimize();
void columnsAndRows();
@@ -2881,6 +2881,7 @@ void tst_QMatrixNxN::convertGeneric()
#endif
}
+/*
// Copy of "flagBits" in qmatrix4x4.h.
enum {
Identity = 0x0000, // Identity matrix
@@ -3014,7 +3015,7 @@ void tst_QMatrixNxN::optimize()
QCOMPARE(reinterpret_cast<Matrix4x4 *>(&m)->flagBits, flagBits);
}
-
+*/
void tst_QMatrixNxN::columnsAndRows()
{
QMatrix4x4 m1(uniqueValues4);