summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/math3d/qgenericmatrix.cpp16
-rw-r--r--src/gui/math3d/qgenericmatrix.h16
-rw-r--r--src/gui/math3d/qmatrix4x4.cpp357
-rw-r--r--src/gui/math3d/qmatrix4x4.h149
-rw-r--r--src/gui/math3d/qquaternion.cpp88
-rw-r--r--src/gui/math3d/qquaternion.h96
-rw-r--r--src/gui/math3d/qvector2d.cpp64
-rw-r--r--src/gui/math3d/qvector2d.h64
-rw-r--r--src/gui/math3d/qvector3d.cpp88
-rw-r--r--src/gui/math3d/qvector3d.h80
-rw-r--r--src/gui/math3d/qvector4d.cpp95
-rw-r--r--src/gui/math3d/qvector4d.h84
-rw-r--r--src/gui/opengl/qopenglshaderprogram.cpp53
13 files changed, 624 insertions, 626 deletions
diff --git a/src/gui/math3d/qgenericmatrix.cpp b/src/gui/math3d/qgenericmatrix.cpp
index a05a47fa54..e0ae71d3fc 100644
--- a/src/gui/math3d/qgenericmatrix.cpp
+++ b/src/gui/math3d/qgenericmatrix.cpp
@@ -273,7 +273,7 @@ QT_BEGIN_NAMESPACE
\relates QGenericMatrix
The QMatrix2x2 type defines a convenient instantiation of the
- QGenericMatrix template for 2 columns, 2 rows, and qreal as
+ QGenericMatrix template for 2 columns, 2 rows, and float as
the element type.
*/
@@ -282,7 +282,7 @@ QT_BEGIN_NAMESPACE
\relates QGenericMatrix
The QMatrix2x3 type defines a convenient instantiation of the
- QGenericMatrix template for 2 columns, 3 rows, and qreal as
+ QGenericMatrix template for 2 columns, 3 rows, and float as
the element type.
*/
@@ -291,7 +291,7 @@ QT_BEGIN_NAMESPACE
\relates QGenericMatrix
The QMatrix2x4 type defines a convenient instantiation of the
- QGenericMatrix template for 2 columns, 4 rows, and qreal as
+ QGenericMatrix template for 2 columns, 4 rows, and float as
the element type.
*/
@@ -300,7 +300,7 @@ QT_BEGIN_NAMESPACE
\relates QGenericMatrix
The QMatrix3x2 type defines a convenient instantiation of the
- QGenericMatrix template for 3 columns, 2 rows, and qreal as
+ QGenericMatrix template for 3 columns, 2 rows, and float as
the element type.
*/
@@ -309,7 +309,7 @@ QT_BEGIN_NAMESPACE
\relates QGenericMatrix
The QMatrix3x3 type defines a convenient instantiation of the
- QGenericMatrix template for 3 columns, 3 rows, and qreal as
+ QGenericMatrix template for 3 columns, 3 rows, and float as
the element type.
*/
@@ -318,7 +318,7 @@ QT_BEGIN_NAMESPACE
\relates QGenericMatrix
The QMatrix3x4 type defines a convenient instantiation of the
- QGenericMatrix template for 3 columns, 4 rows, and qreal as
+ QGenericMatrix template for 3 columns, 4 rows, and float as
the element type.
*/
@@ -327,7 +327,7 @@ QT_BEGIN_NAMESPACE
\relates QGenericMatrix
The QMatrix4x2 type defines a convenient instantiation of the
- QGenericMatrix template for 4 columns, 2 rows, and qreal as
+ QGenericMatrix template for 4 columns, 2 rows, and float as
the element type.
*/
@@ -336,7 +336,7 @@ QT_BEGIN_NAMESPACE
\relates QGenericMatrix
The QMatrix4x3 type defines a convenient instantiation of the
- QGenericMatrix template for 4 columns, 3 rows, and qreal as
+ QGenericMatrix template for 4 columns, 3 rows, and float as
the element type.
*/
diff --git a/src/gui/math3d/qgenericmatrix.h b/src/gui/math3d/qgenericmatrix.h
index b987ab2334..cd98f09ece 100644
--- a/src/gui/math3d/qgenericmatrix.h
+++ b/src/gui/math3d/qgenericmatrix.h
@@ -336,14 +336,14 @@ Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T>::copyDataTo(T *values) const
}
// Define aliases for the useful variants of QGenericMatrix.
-typedef QGenericMatrix<2, 2, qreal> QMatrix2x2;
-typedef QGenericMatrix<2, 3, qreal> QMatrix2x3;
-typedef QGenericMatrix<2, 4, qreal> QMatrix2x4;
-typedef QGenericMatrix<3, 2, qreal> QMatrix3x2;
-typedef QGenericMatrix<3, 3, qreal> QMatrix3x3;
-typedef QGenericMatrix<3, 4, qreal> QMatrix3x4;
-typedef QGenericMatrix<4, 2, qreal> QMatrix4x2;
-typedef QGenericMatrix<4, 3, qreal> QMatrix4x3;
+typedef QGenericMatrix<2, 2, float> QMatrix2x2;
+typedef QGenericMatrix<2, 3, float> QMatrix2x3;
+typedef QGenericMatrix<2, 4, float> QMatrix2x4;
+typedef QGenericMatrix<3, 2, float> QMatrix3x2;
+typedef QGenericMatrix<3, 3, float> QMatrix3x3;
+typedef QGenericMatrix<3, 4, float> QMatrix3x4;
+typedef QGenericMatrix<4, 2, float> QMatrix4x2;
+typedef QGenericMatrix<4, 3, float> QMatrix4x3;
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp
index 76135f0eff..899939c2c3 100644
--- a/src/gui/math3d/qmatrix4x4.cpp
+++ b/src/gui/math3d/qmatrix4x4.cpp
@@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE
\sa QVector3D, QGenericMatrix
*/
-static const qreal inv_dist_to_plane = 1. / 1024.;
+static const float inv_dist_to_plane = 1.0f / 1024.0f;
/*!
\fn QMatrix4x4::QMatrix4x4()
@@ -93,7 +93,7 @@ static const qreal inv_dist_to_plane = 1. / 1024.;
\sa copyDataTo(), optimize()
*/
-QMatrix4x4::QMatrix4x4(const qreal *values)
+QMatrix4x4::QMatrix4x4(const float *values)
{
for (int row = 0; row < 4; ++row)
for (int col = 0; col < 4; ++col)
@@ -101,8 +101,17 @@ QMatrix4x4::QMatrix4x4(const qreal *values)
flagBits = General;
}
+// ###TODO This is temporary to get through the CI's revdep qtdeclarative tests. Remove it!
+QMatrix4x4::QMatrix4x4(const double *values)
+{
+ for (int row = 0; row < 4; ++row)
+ for (int col = 0; col < 4; ++col)
+ m[col][row] = float(values[row * 4 + col]);
+ flagBits = General;
+}
+
/*!
- \fn QMatrix4x4::QMatrix4x4(qreal m11, qreal m12, qreal m13, qreal m14, qreal m21, qreal m22, qreal m23, qreal m24, qreal m31, qreal m32, qreal m33, qreal m34, qreal m41, qreal m42, qreal m43, qreal m44)
+ \fn QMatrix4x4::QMatrix4x4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)
Constructs a matrix from the 16 elements \a m11, \a m12, \a m13, \a m14,
\a m21, \a m22, \a m23, \a m24, \a m31, \a m32, \a m33, \a m34,
@@ -118,7 +127,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values)
*/
/*!
- \fn QMatrix4x4::QMatrix4x4(const QGenericMatrix<N, M, qreal>& matrix)
+ \fn QMatrix4x4::QMatrix4x4(const QGenericMatrix<N, M, float>& matrix)
Constructs a 4x4 matrix from the left-most 4 columns and top-most
4 rows of \a matrix. If \a matrix has less than 4 columns or rows,
@@ -129,7 +138,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values)
*/
/*!
- \fn QGenericMatrix<N, M, qreal> QMatrix4x4::toGenericMatrix() const
+ \fn QGenericMatrix<N, M, float> QMatrix4x4::toGenericMatrix() const
Constructs a NxM generic matrix from the left-most N columns and
top-most M rows of this 4x4 matrix. If N or M is greater than 4,
@@ -138,7 +147,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values)
*/
/*!
- \fn QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix<N, M, qreal>& matrix)
+ \fn QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix<N, M, float>& matrix)
\relates QMatrix4x4
\obsolete
@@ -151,7 +160,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values)
*/
/*!
- \fn QGenericMatrix<N, M, qreal> qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix)
+ \fn QGenericMatrix<N, M, float> qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix)
\relates QMatrix4x4
\obsolete
@@ -166,7 +175,7 @@ QMatrix4x4::QMatrix4x4(const qreal *values)
/*!
\internal
*/
-QMatrix4x4::QMatrix4x4(const qreal *values, int cols, int rows)
+QMatrix4x4::QMatrix4x4(const float *values, int cols, int rows)
{
for (int col = 0; col < 4; ++col) {
for (int row = 0; row < 4; ++row) {
@@ -246,7 +255,7 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform)
}
/*!
- \fn const qreal& QMatrix4x4::operator()(int row, int column) const
+ \fn const float& QMatrix4x4::operator()(int row, int column) const
Returns a constant reference to the element at position
(\a row, \a column) in this matrix.
@@ -255,7 +264,7 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform)
*/
/*!
- \fn qreal& QMatrix4x4::operator()(int row, int column)
+ \fn float& QMatrix4x4::operator()(int row, int column)
Returns a reference to the element at position (\a row, \a column)
in this matrix so that the element can be assigned to.
@@ -312,12 +321,12 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform)
*/
/*!
- \fn void QMatrix4x4::fill(qreal value)
+ \fn void QMatrix4x4::fill(float value)
Fills all elements of this matrx with \a value.
*/
-static inline qreal matrixDet2(const qreal m[4][4], int col0, int col1, int row0, int row1)
+static inline double matrixDet2(const double m[4][4], int col0, int col1, int row0, int row1)
{
return m[col0][row0] * m[col1][row1] - m[col0][row1] * m[col1][row0];
}
@@ -332,8 +341,8 @@ static inline qreal matrixDet2(const qreal m[4][4], int col0, int col1, int row0
// | A B C |
// M = | D E F | det(M) = A * (EI - HF) - B * (DI - GF) + C * (DH - GE)
// | G H I |
-static inline qreal matrixDet3
- (const qreal m[4][4], int col0, int col1, int col2,
+static inline double matrixDet3
+ (const double m[4][4], int col0, int col1, int col2,
int row0, int row1, int row2)
{
return m[col0][row0] * matrixDet2(m, col1, col2, row1, row2)
@@ -342,9 +351,9 @@ static inline qreal matrixDet3
}
// Calculate the determinant of a 4x4 matrix.
-static inline qreal matrixDet4(const qreal m[4][4])
+static inline double matrixDet4(const double m[4][4])
{
- qreal det;
+ double det;
det = m[0][0] * matrixDet3(m, 1, 2, 3, 1, 2, 3);
det -= m[1][0] * matrixDet3(m, 0, 2, 3, 1, 2, 3);
det += m[2][0] * matrixDet3(m, 0, 1, 3, 1, 2, 3);
@@ -352,18 +361,28 @@ static inline qreal matrixDet4(const qreal m[4][4])
return det;
}
+static inline void copyToDoubles(const float m[4][4], double mm[4][4])
+{
+ for (int i = 0; i < 4; ++i)
+ for (int j = 0; j < 4; ++j)
+ mm[i][j] = double(m[i][j]);
+}
+
/*!
Returns the determinant of this matrix.
*/
-qreal QMatrix4x4::determinant() const
+double QMatrix4x4::determinant() const
{
if ((flagBits & ~(Translation | Rotation2D | Rotation)) == Identity)
- return 1;
+ return 1.0;
+
+ double mm[4][4];
+ copyToDoubles(m, mm);
if (flagBits < Rotation2D)
- return m[0][0] * m[1][1] * m[2][2]; // Translation | Scale
+ return mm[0][0] * mm[1][1] * mm[2][2]; // Translation | Scale
if (flagBits < Perspective)
- return matrixDet3(m, 0, 1, 2, 0, 1, 2);
- return matrixDet4(m);
+ return matrixDet3(mm, 0, 1, 2, 0, 1, 2);
+ return matrixDet4(mm);
}
/*!
@@ -420,7 +439,10 @@ QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const
} else if (flagBits < Perspective) {
QMatrix4x4 inv(1); // The "1" says to not load the identity.
- qreal det = matrixDet3(m, 0, 1, 2, 0, 1, 2);
+ 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;
@@ -428,17 +450,17 @@ QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const
}
det = 1.0f / det;
- inv.m[0][0] = matrixDet2(m, 1, 2, 1, 2) * det;
- inv.m[0][1] = -matrixDet2(m, 0, 2, 1, 2) * det;
- inv.m[0][2] = matrixDet2(m, 0, 1, 1, 2) * 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(m, 1, 2, 0, 2) * det;
- inv.m[1][1] = matrixDet2(m, 0, 2, 0, 2) * det;
- inv.m[1][2] = -matrixDet2(m, 0, 1, 0, 2) * det;
+ 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(m, 1, 2, 0, 1) * det;
- inv.m[2][1] = -matrixDet2(m, 0, 2, 0, 1) * det;
- inv.m[2][2] = matrixDet2(m, 0, 1, 0, 1) * det;
+ 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];
@@ -453,7 +475,10 @@ QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const
QMatrix4x4 inv(1); // The "1" says to not load the identity.
- qreal det = matrixDet4(m);
+ double mm[4][4];
+ copyToDoubles(m, mm);
+
+ double det = matrixDet4(mm);
if (det == 0.0f) {
if (invertible)
*invertible = false;
@@ -461,22 +486,22 @@ QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const
}
det = 1.0f / det;
- inv.m[0][0] = matrixDet3(m, 1, 2, 3, 1, 2, 3) * det;
- inv.m[0][1] = -matrixDet3(m, 0, 2, 3, 1, 2, 3) * det;
- inv.m[0][2] = matrixDet3(m, 0, 1, 3, 1, 2, 3) * det;
- inv.m[0][3] = -matrixDet3(m, 0, 1, 2, 1, 2, 3) * det;
- inv.m[1][0] = -matrixDet3(m, 1, 2, 3, 0, 2, 3) * det;
- inv.m[1][1] = matrixDet3(m, 0, 2, 3, 0, 2, 3) * det;
- inv.m[1][2] = -matrixDet3(m, 0, 1, 3, 0, 2, 3) * det;
- inv.m[1][3] = matrixDet3(m, 0, 1, 2, 0, 2, 3) * det;
- inv.m[2][0] = matrixDet3(m, 1, 2, 3, 0, 1, 3) * det;
- inv.m[2][1] = -matrixDet3(m, 0, 2, 3, 0, 1, 3) * det;
- inv.m[2][2] = matrixDet3(m, 0, 1, 3, 0, 1, 3) * det;
- inv.m[2][3] = -matrixDet3(m, 0, 1, 2, 0, 1, 3) * det;
- inv.m[3][0] = -matrixDet3(m, 1, 2, 3, 0, 1, 2) * det;
- inv.m[3][1] = matrixDet3(m, 0, 2, 3, 0, 1, 2) * det;
- inv.m[3][2] = -matrixDet3(m, 0, 1, 3, 0, 1, 2) * det;
- inv.m[3][3] = matrixDet3(m, 0, 1, 2, 0, 1, 2) * det;
+ inv.m[0][0] = matrixDet3(mm, 1, 2, 3, 1, 2, 3) * det;
+ inv.m[0][1] = -matrixDet3(mm, 0, 2, 3, 1, 2, 3) * det;
+ inv.m[0][2] = matrixDet3(mm, 0, 1, 3, 1, 2, 3) * det;
+ inv.m[0][3] = -matrixDet3(mm, 0, 1, 2, 1, 2, 3) * det;
+ inv.m[1][0] = -matrixDet3(mm, 1, 2, 3, 0, 2, 3) * det;
+ inv.m[1][1] = matrixDet3(mm, 0, 2, 3, 0, 2, 3) * det;
+ inv.m[1][2] = -matrixDet3(mm, 0, 1, 3, 0, 2, 3) * det;
+ inv.m[1][3] = matrixDet3(mm, 0, 1, 2, 0, 2, 3) * det;
+ inv.m[2][0] = matrixDet3(mm, 1, 2, 3, 0, 1, 3) * det;
+ inv.m[2][1] = -matrixDet3(mm, 0, 2, 3, 0, 1, 3) * det;
+ inv.m[2][2] = matrixDet3(mm, 0, 1, 3, 0, 1, 3) * det;
+ inv.m[2][3] = -matrixDet3(mm, 0, 1, 2, 0, 1, 3) * det;
+ inv.m[3][0] = -matrixDet3(mm, 1, 2, 3, 0, 1, 2) * det;
+ 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)
@@ -509,7 +534,7 @@ QMatrix3x3 QMatrix4x4::normalMatrix() const
inv.data()[8] = 1.0f / m[2][2];
return inv;
} else if ((flagBits & ~(Translation | Rotation2D | Rotation)) == Identity) {
- qreal *invm = inv.data();
+ 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];
@@ -522,23 +547,25 @@ QMatrix3x3 QMatrix4x4::normalMatrix() const
return inv;
}
- qreal det = matrixDet3(m, 0, 1, 2, 0, 1, 2);
+ double mm[4][4];
+ copyToDoubles(m, mm);
+ double det = matrixDet3(mm, 0, 1, 2, 0, 1, 2);
if (det == 0.0f)
return inv;
det = 1.0f / det;
- qreal *invm = inv.data();
+ float *invm = inv.data();
// Invert and transpose in a single step.
- invm[0 + 0 * 3] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]) * det;
- invm[1 + 0 * 3] = -(m[1][0] * m[2][2] - m[1][2] * m[2][0]) * det;
- invm[2 + 0 * 3] = (m[1][0] * m[2][1] - m[1][1] * m[2][0]) * det;
- invm[0 + 1 * 3] = -(m[0][1] * m[2][2] - m[2][1] * m[0][2]) * det;
- invm[1 + 1 * 3] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * det;
- invm[2 + 1 * 3] = -(m[0][0] * m[2][1] - m[0][1] * m[2][0]) * det;
- invm[0 + 2 * 3] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * det;
- invm[1 + 2 * 3] = -(m[0][0] * m[1][2] - m[0][2] * m[1][0]) * det;
- invm[2 + 2 * 3] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]) * det;
+ invm[0 + 0 * 3] = (mm[1][1] * mm[2][2] - mm[2][1] * mm[1][2]) * det;
+ invm[1 + 0 * 3] = -(mm[1][0] * mm[2][2] - mm[1][2] * mm[2][0]) * det;
+ invm[2 + 0 * 3] = (mm[1][0] * mm[2][1] - mm[1][1] * mm[2][0]) * det;
+ invm[0 + 1 * 3] = -(mm[0][1] * mm[2][2] - mm[2][1] * mm[0][2]) * det;
+ invm[1 + 1 * 3] = (mm[0][0] * mm[2][2] - mm[0][2] * mm[2][0]) * det;
+ invm[2 + 1 * 3] = -(mm[0][0] * mm[2][1] - mm[0][1] * mm[2][0]) * det;
+ invm[0 + 2 * 3] = (mm[0][1] * mm[1][2] - mm[0][2] * mm[1][1]) * det;
+ invm[1 + 2 * 3] = -(mm[0][0] * mm[1][2] - mm[0][2] * mm[1][0]) * det;
+ invm[2 + 2 * 3] = (mm[0][0] * mm[1][1] - mm[1][0] * mm[0][1]) * det;
return inv;
}
@@ -578,7 +605,7 @@ QMatrix4x4 QMatrix4x4::transposed() const
*/
/*!
- \fn QMatrix4x4& QMatrix4x4::operator*=(qreal factor)
+ \fn QMatrix4x4& QMatrix4x4::operator*=(float factor)
\overload
Multiplies all elements of this matrix by \a factor.
@@ -589,7 +616,7 @@ QMatrix4x4 QMatrix4x4::transposed() const
Divides all elements of this matrix by \a divisor.
*/
-QMatrix4x4& QMatrix4x4::operator/=(qreal divisor)
+QMatrix4x4& QMatrix4x4::operator/=(float divisor)
{
m[0][0] /= divisor;
m[0][1] /= divisor;
@@ -727,14 +754,14 @@ QMatrix4x4& QMatrix4x4::operator/=(qreal divisor)
*/
/*!
- \fn QMatrix4x4 operator*(qreal factor, const QMatrix4x4& matrix)
+ \fn QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix)
\relates QMatrix4x4
Returns the result of multiplying all elements of \a matrix by \a factor.
*/
/*!
- \fn QMatrix4x4 operator*(const QMatrix4x4& matrix, qreal factor)
+ \fn QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor)
\relates QMatrix4x4
Returns the result of multiplying all elements of \a matrix by \a factor.
@@ -745,7 +772,7 @@ QMatrix4x4& QMatrix4x4::operator/=(qreal divisor)
Returns the result of dividing all elements of \a matrix by \a divisor.
*/
-QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor)
+QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor)
{
QMatrix4x4 m(1); // The "1" says to not load the identity.
m.m[0][0] = matrix.m[0][0] / divisor;
@@ -786,9 +813,9 @@ QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor)
*/
void QMatrix4x4::scale(const QVector3D& vector)
{
- qreal vx = vector.x();
- qreal vy = vector.y();
- qreal vz = vector.z();
+ float vx = vector.x();
+ float vy = vector.y();
+ float vz = vector.z();
if (flagBits < Scale) {
m[0][0] = vx;
m[1][1] = vy;
@@ -830,7 +857,7 @@ void QMatrix4x4::scale(const QVector3D& vector)
\sa translate(), rotate()
*/
-void QMatrix4x4::scale(qreal x, qreal y)
+void QMatrix4x4::scale(float x, float y)
{
if (flagBits < Scale) {
m[0][0] = x;
@@ -864,7 +891,7 @@ void QMatrix4x4::scale(qreal x, qreal y)
\sa translate(), rotate()
*/
-void QMatrix4x4::scale(qreal x, qreal y, qreal z)
+void QMatrix4x4::scale(float x, float y, float z)
{
if (flagBits < Scale) {
m[0][0] = x;
@@ -905,7 +932,7 @@ void QMatrix4x4::scale(qreal x, qreal y, qreal z)
\sa translate(), rotate()
*/
-void QMatrix4x4::scale(qreal factor)
+void QMatrix4x4::scale(float factor)
{
if (flagBits < Scale) {
m[0][0] = factor;
@@ -948,9 +975,9 @@ void QMatrix4x4::scale(qreal factor)
void QMatrix4x4::translate(const QVector3D& vector)
{
- qreal vx = vector.x();
- qreal vy = vector.y();
- qreal vz = vector.z();
+ float vx = vector.x();
+ float vy = vector.y();
+ float vz = vector.z();
if (flagBits == Identity) {
m[3][0] = vx;
m[3][1] = vy;
@@ -989,7 +1016,7 @@ void QMatrix4x4::translate(const QVector3D& vector)
\sa scale(), rotate()
*/
-void QMatrix4x4::translate(qreal x, qreal y)
+void QMatrix4x4::translate(float x, float y)
{
if (flagBits == Identity) {
m[3][0] = x;
@@ -1023,7 +1050,7 @@ void QMatrix4x4::translate(qreal x, qreal y)
\sa scale(), rotate()
*/
-void QMatrix4x4::translate(qreal x, qreal y, qreal z)
+void QMatrix4x4::translate(float x, float y, float z)
{
if (flagBits == Identity) {
m[3][0] = x;
@@ -1062,7 +1089,7 @@ void QMatrix4x4::translate(qreal x, qreal y, qreal z)
\sa scale(), translate()
*/
-void QMatrix4x4::rotate(qreal angle, const QVector3D& vector)
+void QMatrix4x4::rotate(float angle, const QVector3D& vector)
{
rotate(angle, vector.x(), vector.y(), vector.z());
}
@@ -1077,11 +1104,11 @@ void QMatrix4x4::rotate(qreal angle, const QVector3D& vector)
\sa scale(), translate()
*/
-void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z)
+void QMatrix4x4::rotate(float angle, float x, float y, float z)
{
if (angle == 0.0f)
return;
- qreal c, s;
+ float c, s;
if (angle == 90.0f || angle == -270.0f) {
s = 1.0f;
c = 0.0f;
@@ -1092,9 +1119,9 @@ void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z)
s = 0.0f;
c = -1.0f;
} else {
- qreal a = angle * M_PI / 180.0f;
- c = qCos(a);
- s = qSin(a);
+ float a = angle * M_PI / 180.0f;
+ c = cosf(a);
+ s = sinf(a);
}
if (x == 0.0f) {
if (y == 0.0f) {
@@ -1102,7 +1129,7 @@ void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z)
// Rotate around the Z axis.
if (z < 0)
s = -s;
- qreal tmp;
+ float tmp;
m[0][0] = (tmp = m[0][0]) * c + m[1][0] * s;
m[1][0] = m[1][0] * c - tmp * s;
m[0][1] = (tmp = m[0][1]) * c + m[1][1] * s;
@@ -1119,7 +1146,7 @@ void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z)
// Rotate around the Y axis.
if (y < 0)
s = -s;
- qreal tmp;
+ float tmp;
m[2][0] = (tmp = m[2][0]) * c + m[0][0] * s;
m[0][0] = m[0][0] * c - tmp * s;
m[2][1] = (tmp = m[2][1]) * c + m[0][1] * s;
@@ -1136,7 +1163,7 @@ void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z)
// Rotate around the X axis.
if (x < 0)
s = -s;
- qreal tmp;
+ float tmp;
m[1][0] = (tmp = m[1][0]) * c + m[2][0] * s;
m[2][0] = m[2][0] * c - tmp * s;
m[1][1] = (tmp = m[1][1]) * c + m[2][1] * s;
@@ -1150,14 +1177,16 @@ void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z)
return;
}
- qreal len = x * x + y * y + z * z;
- if (!qFuzzyCompare(len, qreal(1)) && !qFuzzyIsNull(len)) {
- len = qSqrt(len);
- x /= len;
- y /= len;
- z /= len;
+ double len = double(x) * double(x) +
+ double(y) * double(y) +
+ double(z) * double(z);
+ if (!qFuzzyCompare(len, 1.0) && !qFuzzyIsNull(len)) {
+ len = sqrt(len);
+ x = float(double(x) / len);
+ y = float(double(y) / len);
+ z = float(double(z) / len);
}
- qreal ic = 1.0f - c;
+ 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;
@@ -1182,13 +1211,13 @@ void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z)
/*!
\internal
*/
-void QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z)
+void QMatrix4x4::projectedRotate(float angle, float x, float y, float z)
{
// Used by QGraphicsRotation::applyTo() to perform a rotation
// and projection back to 2D in a single step.
if (angle == 0.0f)
return;
- qreal c, s;
+ float c, s;
if (angle == 90.0f || angle == -270.0f) {
s = 1.0f;
c = 0.0f;
@@ -1199,9 +1228,9 @@ void QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z)
s = 0.0f;
c = -1.0f;
} else {
- qreal a = angle * M_PI / 180.0f;
- c = qCos(a);
- s = qSin(a);
+ float a = angle * M_PI / 180.0f;
+ c = cosf(a);
+ s = sinf(a);
}
if (x == 0.0f) {
if (y == 0.0f) {
@@ -1209,7 +1238,7 @@ void QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z)
// Rotate around the Z axis.
if (z < 0)
s = -s;
- qreal tmp;
+ float tmp;
m[0][0] = (tmp = m[0][0]) * c + m[1][0] * s;
m[1][0] = m[1][0] * c - tmp * s;
m[0][1] = (tmp = m[0][1]) * c + m[1][1] * s;
@@ -1244,14 +1273,16 @@ void QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z)
flagBits = General;
return;
}
- qreal len = x * x + y * y + z * z;
- if (!qFuzzyIsNull(len - 1.0f) && !qFuzzyIsNull(len)) {
- len = qSqrt(len);
- x /= len;
- y /= len;
- z /= len;
+ double len = double(x) * double(x) +
+ double(y) * double(y) +
+ double(z) * double(z);
+ if (!qFuzzyCompare(len, 1.0) && !qFuzzyIsNull(len)) {
+ len = sqrt(len);
+ x = float(double(x) / len);
+ y = float(double(y) / len);
+ z = float(double(z) / len);
}
- qreal ic = 1.0f - c;
+ 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;
@@ -1287,15 +1318,15 @@ void QMatrix4x4::rotate(const QQuaternion& quaternion)
// Algorithm from:
// http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54
QMatrix4x4 m(1);
- qreal xx = quaternion.x() * quaternion.x();
- qreal xy = quaternion.x() * quaternion.y();
- qreal xz = quaternion.x() * quaternion.z();
- qreal xw = quaternion.x() * quaternion.scalar();
- qreal yy = quaternion.y() * quaternion.y();
- qreal yz = quaternion.y() * quaternion.z();
- qreal yw = quaternion.y() * quaternion.scalar();
- qreal zz = quaternion.z() * quaternion.z();
- qreal zw = quaternion.z() * quaternion.scalar();
+ float xx = quaternion.x() * quaternion.x();
+ float xy = quaternion.x() * quaternion.y();
+ float xz = quaternion.x() * quaternion.z();
+ float xw = quaternion.x() * quaternion.scalar();
+ float yy = quaternion.y() * quaternion.y();
+ float yz = quaternion.y() * quaternion.z();
+ float yw = quaternion.y() * quaternion.scalar();
+ float zz = quaternion.z() * quaternion.z();
+ float zw = quaternion.z() * quaternion.scalar();
m.m[0][0] = 1.0f - 2 * (yy + zz);
m.m[1][0] = 2 * (xy - zw);
m.m[2][0] = 2 * (xz + yw);
@@ -1358,16 +1389,16 @@ void QMatrix4x4::ortho(const QRectF& rect)
\sa frustum(), perspective()
*/
-void QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane)
+void QMatrix4x4::ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane)
{
// Bail out if the projection volume is zero-sized.
if (left == right || bottom == top || nearPlane == farPlane)
return;
// Construct the projection.
- qreal width = right - left;
- qreal invheight = top - bottom;
- qreal clip = farPlane - nearPlane;
+ float width = right - left;
+ float invheight = top - bottom;
+ float clip = farPlane - nearPlane;
QMatrix4x4 m(1);
m.m[0][0] = 2.0f / width;
m.m[1][0] = 0.0f;
@@ -1399,7 +1430,7 @@ void QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, qreal n
\sa ortho(), perspective()
*/
-void QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane)
+void QMatrix4x4::frustum(float left, float right, float bottom, float top, float nearPlane, float farPlane)
{
// Bail out if the projection volume is zero-sized.
if (left == right || bottom == top || nearPlane == farPlane)
@@ -1407,9 +1438,9 @@ void QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top, qreal
// Construct the projection.
QMatrix4x4 m(1);
- qreal width = right - left;
- qreal invheight = top - bottom;
- qreal clip = farPlane - nearPlane;
+ float width = right - left;
+ float invheight = top - bottom;
+ 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;
@@ -1440,7 +1471,7 @@ void QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top, qreal
\sa ortho(), frustum()
*/
-void QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane)
+void QMatrix4x4::perspective(float angle, float aspect, float nearPlane, float farPlane)
{
// Bail out if the projection volume is zero-sized.
if (nearPlane == farPlane || aspect == 0.0f)
@@ -1448,12 +1479,12 @@ void QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, qreal f
// Construct the projection.
QMatrix4x4 m(1);
- qreal radians = (angle / 2.0f) * M_PI / 180.0f;
- qreal sine = qSin(radians);
+ float radians = (angle / 2.0f) * M_PI / 180.0f;
+ float sine = sinf(radians);
if (sine == 0.0f)
return;
- qreal cotan = qCos(radians) / sine;
- qreal clip = farPlane - nearPlane;
+ float cotan = cosf(radians) / sine;
+ float clip = farPlane - nearPlane;
m.m[0][0] = cotan / aspect;
m.m[1][0] = 0.0f;
m.m[2][0] = 0.0f;
@@ -1551,11 +1582,11 @@ void QMatrix4x4::flipCoordinates()
Retrieves the 16 items in this matrix and copies them to \a values
in row-major order.
*/
-void QMatrix4x4::copyDataTo(qreal *values) const
+void QMatrix4x4::copyDataTo(float *values) const
{
for (int row = 0; row < 4; ++row)
for (int col = 0; col < 4; ++col)
- values[row * 4 + col] = qreal(m[col][row]);
+ values[row * 4 + col] = float(m[col][row]);
}
/*!
@@ -1607,7 +1638,7 @@ QTransform QMatrix4x4::toTransform() const
\sa toAffine()
*/
-QTransform QMatrix4x4::toTransform(qreal distanceToPlane) const
+QTransform QMatrix4x4::toTransform(float distanceToPlane) const
{
if (distanceToPlane == 1024.0f) {
// Optimize the common case with constants.
@@ -1622,7 +1653,7 @@ QTransform QMatrix4x4::toTransform(qreal distanceToPlane) const
// | 0 0 d 1 |
// where d = -1 / distanceToPlane. After projection, row 3 and
// column 3 are dropped to form the final QTransform.
- qreal d = 1.0f / distanceToPlane;
+ 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);
@@ -1701,10 +1732,10 @@ QRect QMatrix4x4::mapRect(const QRect& rect) const
rect.width(), rect.height());
} else if (flagBits < Rotation2D) {
// Translation | Scale
- qreal x = rect.x() * m[0][0] + m[3][0];
- qreal y = rect.y() * m[1][1] + m[3][1];
- qreal w = rect.width() * m[0][0];
- qreal h = rect.height() * m[1][1];
+ 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;
@@ -1745,10 +1776,10 @@ QRectF QMatrix4x4::mapRect(const QRectF& rect) const
return rect.translated(m[3][0], m[3][1]);
} else if (flagBits < Rotation2D) {
// Translation | Scale
- qreal x = rect.x() * m[0][0] + m[3][0];
- qreal y = rect.y() * m[1][1] + m[3][1];
- qreal w = rect.width() * m[0][0];
- qreal h = rect.height() * m[1][1];
+ 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;
@@ -1763,16 +1794,16 @@ QRectF QMatrix4x4::mapRect(const QRectF& rect) const
QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());
QPointF bl = map(rect.bottomLeft()); QPointF br = map(rect.bottomRight());
- qreal xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
- qreal xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
- qreal ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
- qreal ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
+ 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()));
return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
}
/*!
- \fn qreal *QMatrix4x4::data()
+ \fn float *QMatrix4x4::data()
Returns a pointer to the raw data of this matrix.
@@ -1780,7 +1811,7 @@ QRectF QMatrix4x4::mapRect(const QRectF& rect) const
*/
/*!
- \fn const qreal *QMatrix4x4::data() const
+ \fn const float *QMatrix4x4::data() const
Returns a constant pointer to the raw data of this matrix.
This raw data is stored in column-major format.
@@ -1789,7 +1820,7 @@ QRectF QMatrix4x4::mapRect(const QRectF& rect) const
*/
/*!
- \fn const qreal *QMatrix4x4::constData() const
+ \fn const float *QMatrix4x4::constData() const
Returns a constant pointer to the raw data of this matrix.
This raw data is stored in column-major format.
@@ -1873,24 +1904,28 @@ void QMatrix4x4::optimize()
flagBits &= ~Scale;
} else {
// If the columns are orthonormal and form a right-handed system, then there is no scale.
- qreal det = matrixDet2(m, 0, 1, 0, 1);
- qreal lenX = m[0][0] * m[0][0] + m[0][1] * m[0][1];
- qreal lenY = m[1][0] * m[1][0] + m[1][1] * m[1][1];
- qreal lenZ = m[2][2];
- if (qFuzzyCompare(det, qreal(1)) && qFuzzyCompare(lenX, qreal(1))
- && qFuzzyCompare(lenY, qreal(1)) && qFuzzyCompare(lenZ, qreal(1)))
+ 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.
- qreal det = matrixDet3(m, 0, 1, 2, 0, 1, 2);
- qreal lenX = m[0][0] * m[0][0] + m[0][1] * m[0][1] + m[0][2] * m[0][2];
- qreal lenY = m[1][0] * m[1][0] + m[1][1] * m[1][1] + m[1][2] * m[1][2];
- qreal lenZ = m[2][0] * m[2][0] + m[2][1] * m[2][1] + m[2][2] * m[2][2];
- if (qFuzzyCompare(det, qreal(1)) && qFuzzyCompare(lenX, qreal(1))
- && qFuzzyCompare(lenY, qreal(1)) && qFuzzyCompare(lenZ, qreal(1)))
+ 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;
}
@@ -1959,7 +1994,7 @@ QDataStream &operator<<(QDataStream &stream, const QMatrix4x4 &matrix)
{
for (int row = 0; row < 4; ++row)
for (int col = 0; col < 4; ++col)
- stream << double(matrix(row, col));
+ stream << matrix(row, col);
return stream;
}
@@ -1975,11 +2010,11 @@ QDataStream &operator<<(QDataStream &stream, const QMatrix4x4 &matrix)
QDataStream &operator>>(QDataStream &stream, QMatrix4x4 &matrix)
{
- double x;
+ float x;
for (int row = 0; row < 4; ++row) {
for (int col = 0; col < 4; ++col) {
stream >> x;
- matrix(row, col) = qreal(x);
+ matrix(row, col) = x;
}
}
matrix.optimize();
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
index 8353adfab1..34230acf0a 100644
--- a/src/gui/math3d/qmatrix4x4.h
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -63,21 +63,24 @@ class Q_GUI_EXPORT QMatrix4x4
{
public:
inline QMatrix4x4() { setToIdentity(); }
- explicit QMatrix4x4(const qreal *values);
- inline QMatrix4x4(qreal m11, qreal m12, qreal m13, qreal m14,
- qreal m21, qreal m22, qreal m23, qreal m24,
- qreal m31, qreal m32, qreal m33, qreal m34,
- qreal m41, qreal m42, qreal m43, qreal m44);
+ explicit QMatrix4x4(const float *values);
+
+ // ###TODO This is temporary to get through the CI's revdep qtdeclarative tests. Remove it!
+ explicit QMatrix4x4(const double *values);
+ inline QMatrix4x4(float m11, float m12, float m13, float m14,
+ float m21, float m22, float m23, float m24,
+ float m31, float m32, float m33, float m34,
+ float m41, float m42, float m43, float m44);
template <int N, int M>
- explicit QMatrix4x4(const QGenericMatrix<N, M, qreal>& matrix);
+ explicit QMatrix4x4(const QGenericMatrix<N, M, float>& matrix);
- QMatrix4x4(const qreal *values, int cols, int rows);
+ QMatrix4x4(const float *values, int cols, int rows);
QMatrix4x4(const QTransform& transform);
QMatrix4x4(const QMatrix& matrix);
- inline const qreal& operator()(int row, int column) const;
- inline qreal& operator()(int row, int column);
+ inline const float& operator()(int row, int column) const;
+ inline float& operator()(int row, int column);
#ifndef QT_NO_VECTOR4D
inline QVector4D column(int index) const;
@@ -90,9 +93,9 @@ public:
inline bool isIdentity() const;
inline void setToIdentity();
- inline void fill(qreal value);
+ inline void fill(float value);
- qreal determinant() const;
+ double determinant() const;
QMatrix4x4 inverted(bool *invertible = 0) const;
QMatrix4x4 transposed() const;
QMatrix3x3 normalMatrix() const;
@@ -100,8 +103,8 @@ public:
inline QMatrix4x4& operator+=(const QMatrix4x4& other);
inline QMatrix4x4& operator-=(const QMatrix4x4& other);
inline QMatrix4x4& operator*=(const QMatrix4x4& other);
- inline QMatrix4x4& operator*=(qreal factor);
- QMatrix4x4& operator/=(qreal divisor);
+ inline QMatrix4x4& operator*=(float factor);
+ QMatrix4x4& operator/=(float divisor);
inline bool operator==(const QMatrix4x4& other) const;
inline bool operator!=(const QMatrix4x4& other) const;
@@ -121,42 +124,42 @@ public:
friend QMatrix4x4 operator-(const QMatrix4x4& matrix);
friend QPoint operator*(const QMatrix4x4& matrix, const QPoint& point);
friend QPointF operator*(const QMatrix4x4& matrix, const QPointF& point);
- friend QMatrix4x4 operator*(qreal factor, const QMatrix4x4& matrix);
- friend QMatrix4x4 operator*(const QMatrix4x4& matrix, qreal factor);
- friend Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor);
+ friend QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix);
+ friend QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor);
+ friend Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor);
friend inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2);
#ifndef QT_NO_VECTOR3D
void scale(const QVector3D& vector);
void translate(const QVector3D& vector);
- void rotate(qreal angle, const QVector3D& vector);
+ void rotate(float angle, const QVector3D& vector);
#endif
- void scale(qreal x, qreal y);
- void scale(qreal x, qreal y, qreal z);
- void scale(qreal factor);
- void translate(qreal x, qreal y);
- void translate(qreal x, qreal y, qreal z);
- void rotate(qreal angle, qreal x, qreal y, qreal z = 0.0f);
+ void scale(float x, float y);
+ void scale(float x, float y, float z);
+ void scale(float factor);
+ void translate(float x, float y);
+ void translate(float x, float y, float z);
+ void rotate(float angle, float x, float y, float z = 0.0f);
#ifndef QT_NO_QUATERNION
void rotate(const QQuaternion& quaternion);
#endif
void ortho(const QRect& rect);
void ortho(const QRectF& rect);
- void ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane);
- void frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane);
- void perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane);
+ void ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane);
+ void frustum(float left, float right, float bottom, float top, float nearPlane, float farPlane);
+ void perspective(float angle, float aspect, float nearPlane, float farPlane);
#ifndef QT_NO_VECTOR3D
void lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up);
#endif
void flipCoordinates();
- void copyDataTo(qreal *values) const;
+ void copyDataTo(float *values) const;
QMatrix toAffine() const;
QTransform toTransform() const;
- QTransform toTransform(qreal distanceToPlane) const;
+ QTransform toTransform(float distanceToPlane) const;
QPoint map(const QPoint& point) const;
QPointF map(const QPointF& point) const;
@@ -171,11 +174,11 @@ public:
QRectF mapRect(const QRectF& rect) const;
template <int N, int M>
- QGenericMatrix<N, M, qreal> toGenericMatrix() const;
+ QGenericMatrix<N, M, float> toGenericMatrix() const;
- inline qreal *data();
- inline const qreal *data() const { return *m; }
- inline const qreal *constData() const { return *m; }
+ inline float *data();
+ inline const float *data() const { return *m; }
+ inline const float *constData() const { return *m; }
void optimize();
@@ -186,7 +189,7 @@ public:
#endif
private:
- qreal m[4][4]; // Column-major order to match OpenGL.
+ 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.
@@ -205,7 +208,7 @@ private:
QMatrix4x4 orthonormalInverse() const;
- void projectedRotate(qreal angle, qreal x, qreal y, qreal z);
+ void projectedRotate(float angle, float x, float y, float z);
friend class QGraphicsRotation;
};
@@ -213,10 +216,10 @@ private:
Q_DECLARE_TYPEINFO(QMatrix4x4, Q_MOVABLE_TYPE);
inline QMatrix4x4::QMatrix4x4
- (qreal m11, qreal m12, qreal m13, qreal m14,
- qreal m21, qreal m22, qreal m23, qreal m24,
- qreal m31, qreal m32, qreal m33, qreal m34,
- qreal m41, qreal m42, qreal m43, qreal m44)
+ (float m11, float m12, float m13, float m14,
+ float m21, float m22, float m23, float m24,
+ float m31, float m32, float m33, float m34,
+ float m41, float m42, float m43, float m44)
{
m[0][0] = m11; m[0][1] = m21; m[0][2] = m31; m[0][3] = m41;
m[1][0] = m12; m[1][1] = m22; m[1][2] = m32; m[1][3] = m42;
@@ -227,9 +230,9 @@ inline QMatrix4x4::QMatrix4x4
template <int N, int M>
Q_INLINE_TEMPLATE QMatrix4x4::QMatrix4x4
- (const QGenericMatrix<N, M, qreal>& matrix)
+ (const QGenericMatrix<N, M, float>& matrix)
{
- const qreal *values = matrix.constData();
+ const float *values = matrix.constData();
for (int matrixCol = 0; matrixCol < 4; ++matrixCol) {
for (int matrixRow = 0; matrixRow < 4; ++matrixRow) {
if (matrixCol < N && matrixRow < M)
@@ -244,10 +247,10 @@ Q_INLINE_TEMPLATE QMatrix4x4::QMatrix4x4
}
template <int N, int M>
-QGenericMatrix<N, M, qreal> QMatrix4x4::toGenericMatrix() const
+QGenericMatrix<N, M, float> QMatrix4x4::toGenericMatrix() const
{
- QGenericMatrix<N, M, qreal> result;
- qreal *values = result.data();
+ QGenericMatrix<N, M, float> result;
+ float *values = result.data();
for (int matrixCol = 0; matrixCol < N; ++matrixCol) {
for (int matrixRow = 0; matrixRow < M; ++matrixRow) {
if (matrixCol < 4 && matrixRow < 4)
@@ -261,13 +264,13 @@ QGenericMatrix<N, M, qreal> QMatrix4x4::toGenericMatrix() const
return result;
}
-inline const qreal& QMatrix4x4::operator()(int aRow, int aColumn) const
+inline const float& QMatrix4x4::operator()(int aRow, int aColumn) const
{
Q_ASSERT(aRow >= 0 && aRow < 4 && aColumn >= 0 && aColumn < 4);
return m[aColumn][aRow];
}
-inline qreal& QMatrix4x4::operator()(int aRow, int aColumn)
+inline float& QMatrix4x4::operator()(int aRow, int aColumn)
{
Q_ASSERT(aRow >= 0 && aRow < 4 && aColumn >= 0 && aColumn < 4);
flagBits = General;
@@ -308,7 +311,7 @@ inline void QMatrix4x4::setRow(int index, const QVector4D& value)
}
#endif
-Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor);
+Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor);
inline bool QMatrix4x4::isIdentity() const
{
@@ -348,7 +351,7 @@ inline void QMatrix4x4::setToIdentity()
flagBits = Identity;
}
-inline void QMatrix4x4::fill(qreal value)
+inline void QMatrix4x4::fill(float value)
{
m[0][0] = value;
m[0][1] = value;
@@ -428,7 +431,7 @@ inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& other)
return *this;
}
- qreal m0, m1, m2;
+ float m0, m1, m2;
m0 = m[0][0] * other.m[0][0]
+ m[1][0] * other.m[0][1]
+ m[2][0] * other.m[0][2]
@@ -511,7 +514,7 @@ inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& other)
return *this;
}
-inline QMatrix4x4& QMatrix4x4::operator*=(qreal factor)
+inline QMatrix4x4& QMatrix4x4::operator*=(float factor)
{
m[0][0] *= factor;
m[0][1] *= factor;
@@ -711,7 +714,7 @@ inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
{
- qreal x, y, z, w;
+ float x, y, z, w;
x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[0][1] +
vector.z() * matrix.m[0][2] +
@@ -736,7 +739,7 @@ inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
{
- qreal x, y, z, w;
+ float x, y, z, w;
if (matrix.flagBits == QMatrix4x4::Identity) {
return vector;
} else if (matrix.flagBits < QMatrix4x4::Rotation2D) {
@@ -779,7 +782,7 @@ inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)
{
- qreal x, y, z, w;
+ float x, y, z, w;
x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[0][1] +
vector.z() * matrix.m[0][2] +
@@ -801,7 +804,7 @@ inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)
inline QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector)
{
- qreal x, y, z, w;
+ float x, y, z, w;
x = vector.x() * matrix.m[0][0] +
vector.y() * matrix.m[1][0] +
vector.z() * matrix.m[2][0] +
@@ -825,8 +828,8 @@ inline QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector)
inline QPoint operator*(const QPoint& point, const QMatrix4x4& matrix)
{
- qreal xin, yin;
- qreal x, y, w;
+ float xin, yin;
+ float x, y, w;
xin = point.x();
yin = point.y();
x = xin * matrix.m[0][0] +
@@ -846,8 +849,8 @@ inline QPoint operator*(const QPoint& point, const QMatrix4x4& matrix)
inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)
{
- qreal xin, yin;
- qreal x, y, w;
+ float xin, yin;
+ float x, y, w;
xin = point.x();
yin = point.y();
x = xin * matrix.m[0][0] +
@@ -860,16 +863,16 @@ inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)
yin * matrix.m[3][1] +
matrix.m[3][3];
if (w == 1.0f) {
- return QPointF(qreal(x), qreal(y));
+ return QPointF(float(x), float(y));
} else {
- return QPointF(qreal(x / w), qreal(y / w));
+ return QPointF(float(x / w), float(y / w));
}
}
inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
{
- qreal xin, yin;
- qreal x, y, w;
+ float xin, yin;
+ float x, y, w;
xin = point.x();
yin = point.y();
if (matrix.flagBits == QMatrix4x4::Identity) {
@@ -900,8 +903,8 @@ inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
{
- qreal xin, yin;
- qreal x, y, w;
+ float xin, yin;
+ float x, y, w;
xin = point.x();
yin = point.y();
if (matrix.flagBits == QMatrix4x4::Identity) {
@@ -924,9 +927,9 @@ inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
yin * matrix.m[1][3] +
matrix.m[3][3];
if (w == 1.0f) {
- return QPointF(qreal(x), qreal(y));
+ return QPointF(float(x), float(y));
} else {
- return QPointF(qreal(x / w), qreal(y / w));
+ return QPointF(float(x / w), float(y / w));
}
}
}
@@ -954,7 +957,7 @@ inline QMatrix4x4 operator-(const QMatrix4x4& matrix)
return m;
}
-inline QMatrix4x4 operator*(qreal factor, const QMatrix4x4& matrix)
+inline QMatrix4x4 operator*(float factor, const QMatrix4x4& matrix)
{
QMatrix4x4 m(1);
m.m[0][0] = matrix.m[0][0] * factor;
@@ -977,7 +980,7 @@ inline QMatrix4x4 operator*(qreal factor, const QMatrix4x4& matrix)
return m;
}
-inline QMatrix4x4 operator*(const QMatrix4x4& matrix, qreal factor)
+inline QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor)
{
QMatrix4x4 m(1);
m.m[0][0] = matrix.m[0][0] * factor;
@@ -1071,7 +1074,7 @@ inline QVector4D QMatrix4x4::map(const QVector4D& point) const
#endif
-inline qreal *QMatrix4x4::data()
+inline float *QMatrix4x4::data()
{
// We have to assume that the caller will modify the matrix elements,
// so we flip it over to "General" mode.
@@ -1090,17 +1093,17 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QMatrix4x4 &);
#if QT_DEPRECATED_SINCE(5, 0)
template <int N, int M>
-QT_DEPRECATED QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix<N, M, qreal>& matrix)
+QT_DEPRECATED QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix<N, M, float>& matrix)
{
return QMatrix4x4(matrix.constData(), N, M);
}
template <int N, int M>
-QT_DEPRECATED QGenericMatrix<N, M, qreal> qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix)
+QT_DEPRECATED QGenericMatrix<N, M, float> qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix)
{
- QGenericMatrix<N, M, qreal> result;
- const qreal *m = matrix.constData();
- qreal *values = result.data();
+ QGenericMatrix<N, M, float> result;
+ const float *m = matrix.constData();
+ float *values = result.data();
for (int col = 0; col < N; ++col) {
for (int row = 0; row < M; ++row) {
if (col < 4 && row < 4)
diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp
index 79cdb36724..b0133881c3 100644
--- a/src/gui/math3d/qquaternion.cpp
+++ b/src/gui/math3d/qquaternion.cpp
@@ -68,7 +68,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QQuaternion::QQuaternion(qreal scalar, qreal xpos, qreal ypos, qreal zpos)
+ \fn QQuaternion::QQuaternion(float scalar, float xpos, float ypos, float zpos)
Constructs a quaternion with the vector (\a xpos, \a ypos, \a zpos)
and \a scalar.
@@ -77,7 +77,7 @@ QT_BEGIN_NAMESPACE
#ifndef QT_NO_VECTOR3D
/*!
- \fn QQuaternion::QQuaternion(qreal scalar, const QVector3D& vector)
+ \fn QQuaternion::QQuaternion(float scalar, const QVector3D& vector)
Constructs a quaternion vector from the specified \a vector and
\a scalar.
@@ -104,7 +104,7 @@ QT_BEGIN_NAMESPACE
#endif
/*!
- \fn void QQuaternion::setVector(qreal x, qreal y, qreal z)
+ \fn void QQuaternion::setVector(float x, float y, float z)
Sets the vector component of this quaternion to (\a x, \a y, \a z).
@@ -143,7 +143,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn qreal QQuaternion::x() const
+ \fn float QQuaternion::x() const
Returns the x coordinate of this quaternion's vector.
@@ -151,7 +151,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn qreal QQuaternion::y() const
+ \fn float QQuaternion::y() const
Returns the y coordinate of this quaternion's vector.
@@ -159,7 +159,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn qreal QQuaternion::z() const
+ \fn float QQuaternion::z() const
Returns the z coordinate of this quaternion's vector.
@@ -167,7 +167,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn qreal QQuaternion::scalar() const
+ \fn float QQuaternion::scalar() const
Returns the scalar component of this quaternion.
@@ -175,7 +175,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QQuaternion::setX(qreal x)
+ \fn void QQuaternion::setX(float x)
Sets the x coordinate of this quaternion's vector to the given
\a x coordinate.
@@ -184,7 +184,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QQuaternion::setY(qreal y)
+ \fn void QQuaternion::setY(float y)
Sets the y coordinate of this quaternion's vector to the given
\a y coordinate.
@@ -193,7 +193,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QQuaternion::setZ(qreal z)
+ \fn void QQuaternion::setZ(float z)
Sets the z coordinate of this quaternion's vector to the given
\a z coordinate.
@@ -202,7 +202,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QQuaternion::setScalar(qreal scalar)
+ \fn void QQuaternion::setScalar(float scalar)
Sets the scalar component of this quaternion to \a scalar.
@@ -214,7 +214,7 @@ QT_BEGIN_NAMESPACE
\sa lengthSquared(), normalized()
*/
-qreal QQuaternion::length() const
+float QQuaternion::length() const
{
return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp);
}
@@ -224,7 +224,7 @@ qreal QQuaternion::length() const
\sa length()
*/
-qreal QQuaternion::lengthSquared() const
+float QQuaternion::lengthSquared() const
{
return xp * xp + yp * yp + zp * zp + wp * wp;
}
@@ -323,7 +323,7 @@ QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
*/
/*!
- \fn QQuaternion &QQuaternion::operator*=(qreal factor)
+ \fn QQuaternion &QQuaternion::operator*=(float factor)
Multiplies this quaternion's components by the given \a factor, and
returns a reference to this quaternion.
@@ -339,7 +339,7 @@ QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
*/
/*!
- \fn QQuaternion &QQuaternion::operator/=(qreal divisor)
+ \fn QQuaternion &QQuaternion::operator/=(float divisor)
Divides this quaternion's components by the given \a divisor, and
returns a reference to this quaternion.
@@ -353,15 +353,15 @@ QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const
Creates a normalized quaternion that corresponds to rotating through
\a angle degrees about the specified 3D \a axis.
*/
-QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle)
+QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, float angle)
{
// Algorithm from:
// http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56
// We normalize the result just in case the values are close
// to zero, as suggested in the above FAQ.
- qreal a = (angle / 2.0f) * M_PI / 180.0f;
- qreal s = qSin(a);
- qreal c = qCos(a);
+ float a = (angle / 2.0f) * M_PI / 180.0f;
+ float s = sinf(a);
+ float c = cosf(a);
QVector3D ax = axis.normalized();
return QQuaternion(c, ax.x() * s, ax.y() * s, ax.z() * s).normalized();
}
@@ -373,17 +373,17 @@ QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle)
\a angle degrees about the 3D axis (\a x, \a y, \a z).
*/
QQuaternion QQuaternion::fromAxisAndAngle
- (qreal x, qreal y, qreal z, qreal angle)
+ (float x, float y, float z, float angle)
{
- qreal length = qSqrt(x * x + y * y + z * z);
+ float length = qSqrt(x * x + y * y + z * z);
if (!qFuzzyIsNull(length - 1.0f) && !qFuzzyIsNull(length)) {
x /= length;
y /= length;
z /= length;
}
- qreal a = (angle / 2.0f) * M_PI / 180.0f;
- qreal s = qSin(a);
- qreal c = qCos(a);
+ float a = (angle / 2.0f) * M_PI / 180.0f;
+ float s = qSin(a);
+ float c = qCos(a);
return QQuaternion(c, x * s, y * s, z * s).normalized();
}
@@ -424,7 +424,7 @@ QQuaternion QQuaternion::fromAxisAndAngle
*/
/*!
- \fn const QQuaternion operator*(qreal factor, const QQuaternion &quaternion)
+ \fn const QQuaternion operator*(float factor, const QQuaternion &quaternion)
\relates QQuaternion
Returns a copy of the given \a quaternion, multiplied by the
@@ -434,7 +434,7 @@ QQuaternion QQuaternion::fromAxisAndAngle
*/
/*!
- \fn const QQuaternion operator*(const QQuaternion &quaternion, qreal factor)
+ \fn const QQuaternion operator*(const QQuaternion &quaternion, float factor)
\relates QQuaternion
Returns a copy of the given \a quaternion, multiplied by the
@@ -466,7 +466,7 @@ QQuaternion QQuaternion::fromAxisAndAngle
*/
/*!
- \fn const QQuaternion operator/(const QQuaternion &quaternion, qreal divisor)
+ \fn const QQuaternion operator/(const QQuaternion &quaternion, float divisor)
\relates QQuaternion
Returns the QQuaternion object formed by dividing all components of
@@ -495,7 +495,7 @@ QQuaternion QQuaternion::fromAxisAndAngle
\sa nlerp()
*/
QQuaternion QQuaternion::slerp
- (const QQuaternion& q1, const QQuaternion& q2, qreal t)
+ (const QQuaternion& q1, const QQuaternion& q2, float t)
{
// Handle the easy cases first.
if (t <= 0.0f)
@@ -505,7 +505,7 @@ QQuaternion QQuaternion::slerp
// Determine the angle between the two quaternions.
QQuaternion q2b;
- qreal dot;
+ float dot;
dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp;
if (dot >= 0.0f) {
q2b = q2;
@@ -516,14 +516,14 @@ QQuaternion QQuaternion::slerp
// Get the scale factors. If they are too small,
// then revert to simple linear interpolation.
- qreal factor1 = 1.0f - t;
- qreal factor2 = t;
+ float factor1 = 1.0f - t;
+ float factor2 = t;
if ((1.0f - dot) > 0.0000001) {
- qreal angle = qreal(qAcos(dot));
- qreal sinOfAngle = qreal(qSin(angle));
+ float angle = float(qAcos(dot));
+ float sinOfAngle = float(qSin(angle));
if (sinOfAngle > 0.0000001) {
- factor1 = qreal(qSin((1.0f - t) * angle)) / sinOfAngle;
- factor2 = qreal(qSin(t * angle)) / sinOfAngle;
+ factor1 = float(qSin((1.0f - t) * angle)) / sinOfAngle;
+ factor2 = float(qSin(t * angle)) / sinOfAngle;
}
}
@@ -547,7 +547,7 @@ QQuaternion QQuaternion::slerp
\sa slerp()
*/
QQuaternion QQuaternion::nlerp
- (const QQuaternion& q1, const QQuaternion& q2, qreal t)
+ (const QQuaternion& q1, const QQuaternion& q2, float t)
{
// Handle the easy cases first.
if (t <= 0.0f)
@@ -557,7 +557,7 @@ QQuaternion QQuaternion::nlerp
// Determine the angle between the two quaternions.
QQuaternion q2b;
- qreal dot;
+ float dot;
dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp;
if (dot >= 0.0f)
q2b = q2;
@@ -602,8 +602,8 @@ QDebug operator<<(QDebug dbg, const QQuaternion &q)
QDataStream &operator<<(QDataStream &stream, const QQuaternion &quaternion)
{
- stream << double(quaternion.scalar()) << double(quaternion.x())
- << double(quaternion.y()) << double(quaternion.z());
+ stream << quaternion.scalar() << quaternion.x()
+ << quaternion.y() << quaternion.z();
return stream;
}
@@ -619,15 +619,15 @@ QDataStream &operator<<(QDataStream &stream, const QQuaternion &quaternion)
QDataStream &operator>>(QDataStream &stream, QQuaternion &quaternion)
{
- double scalar, x, y, z;
+ float scalar, x, y, z;
stream >> scalar;
stream >> x;
stream >> y;
stream >> z;
- quaternion.setScalar(qreal(scalar));
- quaternion.setX(qreal(x));
- quaternion.setY(qreal(y));
- quaternion.setZ(qreal(z));
+ quaternion.setScalar(scalar);
+ quaternion.setX(x);
+ quaternion.setY(y);
+ quaternion.setZ(z);
return stream;
}
diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h
index 0a1552f045..2188a08fc9 100644
--- a/src/gui/math3d/qquaternion.h
+++ b/src/gui/math3d/qquaternion.h
@@ -59,9 +59,9 @@ class Q_GUI_EXPORT QQuaternion
{
public:
QQuaternion();
- QQuaternion(qreal scalar, qreal xpos, qreal ypos, qreal zpos);
+ QQuaternion(float scalar, float xpos, float ypos, float zpos);
#ifndef QT_NO_VECTOR3D
- QQuaternion(qreal scalar, const QVector3D& vector);
+ QQuaternion(float scalar, const QVector3D& vector);
#endif
#ifndef QT_NO_VECTOR4D
explicit QQuaternion(const QVector4D& vector);
@@ -74,20 +74,20 @@ public:
QVector3D vector() const;
void setVector(const QVector3D& vector);
#endif
- void setVector(qreal x, qreal y, qreal z);
+ void setVector(float x, float y, float z);
- qreal x() const;
- qreal y() const;
- qreal z() const;
- qreal scalar() const;
+ float x() const;
+ float y() const;
+ float z() const;
+ float scalar() const;
- void setX(qreal x);
- void setY(qreal y);
- void setZ(qreal z);
- void setScalar(qreal scalar);
+ void setX(float x);
+ void setY(float y);
+ void setZ(float z);
+ void setScalar(float scalar);
- qreal length() const;
- qreal lengthSquared() const;
+ float length() const;
+ float lengthSquared() const;
QQuaternion normalized() const;
void normalize();
@@ -98,19 +98,19 @@ public:
QQuaternion &operator+=(const QQuaternion &quaternion);
QQuaternion &operator-=(const QQuaternion &quaternion);
- QQuaternion &operator*=(qreal factor);
+ QQuaternion &operator*=(float factor);
QQuaternion &operator*=(const QQuaternion &quaternion);
- QQuaternion &operator/=(qreal divisor);
+ QQuaternion &operator/=(float divisor);
friend inline bool operator==(const QQuaternion &q1, const QQuaternion &q2);
friend inline bool operator!=(const QQuaternion &q1, const QQuaternion &q2);
friend inline const QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2);
friend inline const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2);
- friend inline const QQuaternion operator*(qreal factor, const QQuaternion &quaternion);
- friend inline const QQuaternion operator*(const QQuaternion &quaternion, qreal factor);
+ friend inline const QQuaternion operator*(float factor, const QQuaternion &quaternion);
+ friend inline const QQuaternion operator*(const QQuaternion &quaternion, float factor);
friend inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2);
friend inline const QQuaternion operator-(const QQuaternion &quaternion);
- friend inline const QQuaternion operator/(const QQuaternion &quaternion, qreal divisor);
+ friend inline const QQuaternion operator/(const QQuaternion &quaternion, float divisor);
friend inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2);
@@ -121,25 +121,25 @@ public:
operator QVariant() const;
#ifndef QT_NO_VECTOR3D
- static QQuaternion fromAxisAndAngle(const QVector3D& axis, qreal angle);
+ static QQuaternion fromAxisAndAngle(const QVector3D& axis, float angle);
#endif
static QQuaternion fromAxisAndAngle
- (qreal x, qreal y, qreal z, qreal angle);
+ (float x, float y, float z, float angle);
static QQuaternion slerp
- (const QQuaternion& q1, const QQuaternion& q2, qreal t);
+ (const QQuaternion& q1, const QQuaternion& q2, float t);
static QQuaternion nlerp
- (const QQuaternion& q1, const QQuaternion& q2, qreal t);
+ (const QQuaternion& q1, const QQuaternion& q2, float t);
private:
- qreal wp, xp, yp, zp;
+ float wp, xp, yp, zp;
};
Q_DECLARE_TYPEINFO(QQuaternion, Q_MOVABLE_TYPE);
inline QQuaternion::QQuaternion() : wp(1.0f), xp(0.0f), yp(0.0f), zp(0.0f) {}
-inline QQuaternion::QQuaternion(qreal aScalar, qreal xpos, qreal ypos, qreal zpos) : wp(aScalar), xp(xpos), yp(ypos), zp(zpos) {}
+inline QQuaternion::QQuaternion(float aScalar, float xpos, float ypos, float zpos) : wp(aScalar), xp(xpos), yp(ypos), zp(zpos) {}
inline bool QQuaternion::isNull() const
@@ -152,15 +152,15 @@ inline bool QQuaternion::isIdentity() const
return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && wp == 1.0f;
}
-inline qreal QQuaternion::x() const { return qreal(xp); }
-inline qreal QQuaternion::y() const { return qreal(yp); }
-inline qreal QQuaternion::z() const { return qreal(zp); }
-inline qreal QQuaternion::scalar() const { return qreal(wp); }
+inline float QQuaternion::x() const { return xp; }
+inline float QQuaternion::y() const { return yp; }
+inline float QQuaternion::z() const { return zp; }
+inline float QQuaternion::scalar() const { return wp; }
-inline void QQuaternion::setX(qreal aX) { xp = aX; }
-inline void QQuaternion::setY(qreal aY) { yp = aY; }
-inline void QQuaternion::setZ(qreal aZ) { zp = aZ; }
-inline void QQuaternion::setScalar(qreal aScalar) { wp = aScalar; }
+inline void QQuaternion::setX(float aX) { xp = aX; }
+inline void QQuaternion::setY(float aY) { yp = aY; }
+inline void QQuaternion::setZ(float aZ) { zp = aZ; }
+inline void QQuaternion::setScalar(float aScalar) { wp = aScalar; }
inline QQuaternion QQuaternion::conjugate() const
{
@@ -185,7 +185,7 @@ inline QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion)
return *this;
}
-inline QQuaternion &QQuaternion::operator*=(qreal factor)
+inline QQuaternion &QQuaternion::operator*=(float factor)
{
xp *= factor;
yp *= factor;
@@ -196,16 +196,16 @@ inline QQuaternion &QQuaternion::operator*=(qreal factor)
inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2)
{
- qreal ww = (q1.zp + q1.xp) * (q2.xp + q2.yp);
- qreal yy = (q1.wp - q1.yp) * (q2.wp + q2.zp);
- qreal zz = (q1.wp + q1.yp) * (q2.wp - q2.zp);
- qreal xx = ww + yy + zz;
- qreal qq = 0.5 * (xx + (q1.zp - q1.xp) * (q2.xp - q2.yp));
+ float ww = (q1.zp + q1.xp) * (q2.xp + q2.yp);
+ float yy = (q1.wp - q1.yp) * (q2.wp + q2.zp);
+ float zz = (q1.wp + q1.yp) * (q2.wp - q2.zp);
+ float xx = ww + yy + zz;
+ float qq = 0.5 * (xx + (q1.zp - q1.xp) * (q2.xp - q2.yp));
- qreal w = qq - ww + (q1.zp - q1.yp) * (q2.yp - q2.zp);
- qreal x = qq - xx + (q1.xp + q1.wp) * (q2.xp + q2.wp);
- qreal y = qq - yy + (q1.wp - q1.xp) * (q2.yp + q2.zp);
- qreal z = qq - zz + (q1.zp + q1.yp) * (q2.wp - q2.xp);
+ float w = qq - ww + (q1.zp - q1.yp) * (q2.yp - q2.zp);
+ float x = qq - xx + (q1.xp + q1.wp) * (q2.xp + q2.wp);
+ float y = qq - yy + (q1.wp - q1.xp) * (q2.yp + q2.zp);
+ float z = qq - zz + (q1.zp + q1.yp) * (q2.wp - q2.xp);
return QQuaternion(w, x, y, z);
}
@@ -216,7 +216,7 @@ inline QQuaternion &QQuaternion::operator*=(const QQuaternion &quaternion)
return *this;
}
-inline QQuaternion &QQuaternion::operator/=(qreal divisor)
+inline QQuaternion &QQuaternion::operator/=(float divisor)
{
xp /= divisor;
yp /= divisor;
@@ -245,12 +245,12 @@ inline const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2)
return QQuaternion(q1.wp - q2.wp, q1.xp - q2.xp, q1.yp - q2.yp, q1.zp - q2.zp);
}
-inline const QQuaternion operator*(qreal factor, const QQuaternion &quaternion)
+inline const QQuaternion operator*(float factor, const QQuaternion &quaternion)
{
return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor);
}
-inline const QQuaternion operator*(const QQuaternion &quaternion, qreal factor)
+inline const QQuaternion operator*(const QQuaternion &quaternion, float factor)
{
return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor);
}
@@ -260,7 +260,7 @@ inline const QQuaternion operator-(const QQuaternion &quaternion)
return QQuaternion(-quaternion.wp, -quaternion.xp, -quaternion.yp, -quaternion.zp);
}
-inline const QQuaternion operator/(const QQuaternion &quaternion, qreal divisor)
+inline const QQuaternion operator/(const QQuaternion &quaternion, float divisor)
{
return QQuaternion(quaternion.wp / divisor, quaternion.xp / divisor, quaternion.yp / divisor, quaternion.zp / divisor);
}
@@ -275,7 +275,7 @@ inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2)
#ifndef QT_NO_VECTOR3D
-inline QQuaternion::QQuaternion(qreal aScalar, const QVector3D& aVector)
+inline QQuaternion::QQuaternion(float aScalar, const QVector3D& aVector)
: wp(aScalar), xp(aVector.x()), yp(aVector.y()), zp(aVector.z()) {}
inline void QQuaternion::setVector(const QVector3D& aVector)
@@ -292,7 +292,7 @@ inline QVector3D QQuaternion::vector() const
#endif
-inline void QQuaternion::setVector(qreal aX, qreal aY, qreal aZ)
+inline void QQuaternion::setVector(float aX, float aY, float aZ)
{
xp = aX;
yp = aY;
diff --git a/src/gui/math3d/qvector2d.cpp b/src/gui/math3d/qvector2d.cpp
index 672e2e4dd7..5d542c6f72 100644
--- a/src/gui/math3d/qvector2d.cpp
+++ b/src/gui/math3d/qvector2d.cpp
@@ -62,11 +62,6 @@ QT_BEGIN_NAMESPACE
The QVector2D class can also be used to represent vertices in 2D space.
We therefore do not need to provide a separate vertex class.
- \b{Note:} By design values in the QVector2D instance are stored as \c float.
- This means that on platforms where the \c qreal arguments to QVector2D
- functions are represented by \c double values, it is possible to
- lose precision.
-
\sa QVector3D, QVector4D, QQuaternion
*/
@@ -77,7 +72,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QVector2D::QVector2D(qreal xpos, qreal ypos)
+ \fn QVector2D::QVector2D(float xpos, float ypos)
Constructs a vector with coordinates (\a xpos, \a ypos).
*/
@@ -134,7 +129,7 @@ QVector2D::QVector2D(const QVector4D& vector)
*/
/*!
- \fn qreal QVector2D::x() const
+ \fn float QVector2D::x() const
Returns the x coordinate of this point.
@@ -142,7 +137,7 @@ QVector2D::QVector2D(const QVector4D& vector)
*/
/*!
- \fn qreal QVector2D::y() const
+ \fn float QVector2D::y() const
Returns the y coordinate of this point.
@@ -150,7 +145,7 @@ QVector2D::QVector2D(const QVector4D& vector)
*/
/*!
- \fn void QVector2D::setX(qreal x)
+ \fn void QVector2D::setX(float x)
Sets the x coordinate of this point to the given \a x coordinate.
@@ -158,7 +153,7 @@ QVector2D::QVector2D(const QVector4D& vector)
*/
/*!
- \fn void QVector2D::setY(qreal y)
+ \fn void QVector2D::setY(float y)
Sets the y coordinate of this point to the given \a y coordinate.
@@ -170,9 +165,12 @@ QVector2D::QVector2D(const QVector4D& vector)
\sa lengthSquared(), normalized()
*/
-qreal QVector2D::length() const
+float QVector2D::length() const
{
- return qSqrt(xp * xp + yp * yp);
+ // Need some extra precision if the length is very small.
+ double len = double(xp) * double(xp) +
+ double(yp) * double(yp);
+ return float(sqrt(len));
}
/*!
@@ -181,7 +179,7 @@ qreal QVector2D::length() const
\sa length(), dotProduct()
*/
-qreal QVector2D::lengthSquared() const
+float QVector2D::lengthSquared() const
{
return xp * xp + yp * yp;
}
@@ -200,12 +198,14 @@ QVector2D QVector2D::normalized() const
// Need some extra precision if the length is very small.
double len = double(xp) * double(xp) +
double(yp) * double(yp);
- if (qFuzzyIsNull(len - 1.0f))
+ if (qFuzzyIsNull(len - 1.0f)) {
return *this;
- else if (!qFuzzyIsNull(len))
- return *this / qSqrt(len);
- else
+ } else if (!qFuzzyIsNull(len)) {
+ double sqrtLen = sqrt(len);
+ return QVector2D(float(double(xp) / sqrtLen), float(double(yp) / sqrtLen));
+ } else {
return QVector2D();
+ }
}
/*!
@@ -222,10 +222,10 @@ void QVector2D::normalize()
if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
return;
- len = qSqrt(len);
+ len = sqrt(len);
- xp /= len;
- yp /= len;
+ xp = float(double(xp) / len);
+ yp = float(double(yp) / len);
}
/*!
@@ -247,7 +247,7 @@ void QVector2D::normalize()
*/
/*!
- \fn QVector2D &QVector2D::operator*=(qreal factor)
+ \fn QVector2D &QVector2D::operator*=(float factor)
Multiplies this vector's coordinates by the given \a factor, and
returns a reference to this vector.
@@ -263,7 +263,7 @@ void QVector2D::normalize()
*/
/*!
- \fn QVector2D &QVector2D::operator/=(qreal divisor)
+ \fn QVector2D &QVector2D::operator/=(float divisor)
Divides this vector's coordinates by the given \a divisor, and
returns a reference to this vector.
@@ -274,7 +274,7 @@ void QVector2D::normalize()
/*!
Returns the dot product of \a v1 and \a v2.
*/
-qreal QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
+float QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
{
return v1.xp * v2.xp + v1.yp * v2.yp;
}
@@ -316,7 +316,7 @@ qreal QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
*/
/*!
- \fn const QVector2D operator*(qreal factor, const QVector2D &vector)
+ \fn const QVector2D operator*(float factor, const QVector2D &vector)
\relates QVector2D
Returns a copy of the given \a vector, multiplied by the given \a factor.
@@ -325,7 +325,7 @@ qreal QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
*/
/*!
- \fn const QVector2D operator*(const QVector2D &vector, qreal factor)
+ \fn const QVector2D operator*(const QVector2D &vector, float factor)
\relates QVector2D
Returns a copy of the given \a vector, multiplied by the given \a factor.
@@ -353,7 +353,7 @@ qreal QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
*/
/*!
- \fn const QVector2D operator/(const QVector2D &vector, qreal divisor)
+ \fn const QVector2D operator/(const QVector2D &vector, float divisor)
\relates QVector2D
Returns the QVector2D object formed by dividing all three components of
@@ -379,7 +379,7 @@ qreal QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
*/
QVector3D QVector2D::toVector3D() const
{
- return QVector3D(xp, yp, 0.0f, 1);
+ return QVector3D(xp, yp, 0.0f);
}
#endif
@@ -393,7 +393,7 @@ QVector3D QVector2D::toVector3D() const
*/
QVector4D QVector2D::toVector4D() const
{
- return QVector4D(xp, yp, 0.0f, 0.0f, 1);
+ return QVector4D(xp, yp, 0.0f, 0.0f);
}
#endif
@@ -446,7 +446,7 @@ QDebug operator<<(QDebug dbg, const QVector2D &vector)
QDataStream &operator<<(QDataStream &stream, const QVector2D &vector)
{
- stream << double(vector.x()) << double(vector.y());
+ stream << vector.x() << vector.y();
return stream;
}
@@ -462,11 +462,11 @@ QDataStream &operator<<(QDataStream &stream, const QVector2D &vector)
QDataStream &operator>>(QDataStream &stream, QVector2D &vector)
{
- double x, y;
+ float x, y;
stream >> x;
stream >> y;
- vector.setX(qreal(x));
- vector.setY(qreal(y));
+ vector.setX(x);
+ vector.setY(y);
return stream;
}
diff --git a/src/gui/math3d/qvector2d.h b/src/gui/math3d/qvector2d.h
index 882845db1b..34893c2a04 100644
--- a/src/gui/math3d/qvector2d.h
+++ b/src/gui/math3d/qvector2d.h
@@ -60,7 +60,7 @@ class Q_GUI_EXPORT QVector2D
{
public:
QVector2D();
- QVector2D(qreal xpos, qreal ypos);
+ QVector2D(float xpos, float ypos);
explicit QVector2D(const QPoint& point);
explicit QVector2D(const QPointF& point);
#ifndef QT_NO_VECTOR3D
@@ -72,35 +72,35 @@ public:
bool isNull() const;
- qreal x() const;
- qreal y() const;
+ float x() const;
+ float y() const;
- void setX(qreal x);
- void setY(qreal y);
+ void setX(float x);
+ void setY(float y);
- qreal length() const;
- qreal lengthSquared() const;
+ float length() const;
+ float lengthSquared() const;
QVector2D normalized() const;
void normalize();
QVector2D &operator+=(const QVector2D &vector);
QVector2D &operator-=(const QVector2D &vector);
- QVector2D &operator*=(qreal factor);
+ QVector2D &operator*=(float factor);
QVector2D &operator*=(const QVector2D &vector);
- QVector2D &operator/=(qreal divisor);
+ QVector2D &operator/=(float divisor);
- static qreal dotProduct(const QVector2D& v1, const QVector2D& v2);
+ static float dotProduct(const QVector2D& v1, const QVector2D& v2);
friend inline bool operator==(const QVector2D &v1, const QVector2D &v2);
friend inline bool operator!=(const QVector2D &v1, const QVector2D &v2);
friend inline const QVector2D operator+(const QVector2D &v1, const QVector2D &v2);
friend inline const QVector2D operator-(const QVector2D &v1, const QVector2D &v2);
- friend inline const QVector2D operator*(qreal factor, const QVector2D &vector);
- friend inline const QVector2D operator*(const QVector2D &vector, qreal factor);
+ friend inline const QVector2D operator*(float factor, const QVector2D &vector);
+ friend inline const QVector2D operator*(const QVector2D &vector, float factor);
friend inline const QVector2D operator*(const QVector2D &v1, const QVector2D &v2);
friend inline const QVector2D operator-(const QVector2D &vector);
- friend inline const QVector2D operator/(const QVector2D &vector, qreal divisor);
+ friend inline const QVector2D operator/(const QVector2D &vector, float divisor);
friend inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2);
@@ -119,8 +119,6 @@ public:
private:
float xp, yp;
- QVector2D(float xpos, float ypos, int dummy);
-
friend class QVector3D;
friend class QVector4D;
};
@@ -129,9 +127,7 @@ Q_DECLARE_TYPEINFO(QVector2D, Q_MOVABLE_TYPE);
inline QVector2D::QVector2D() : xp(0.0f), yp(0.0f) {}
-inline QVector2D::QVector2D(float xpos, float ypos, int) : xp(xpos), yp(ypos) {}
-
-inline QVector2D::QVector2D(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) {}
+inline QVector2D::QVector2D(float xpos, float ypos) : xp(xpos), yp(ypos) {}
inline QVector2D::QVector2D(const QPoint& point) : xp(point.x()), yp(point.y()) {}
@@ -142,11 +138,11 @@ inline bool QVector2D::isNull() const
return qIsNull(xp) && qIsNull(yp);
}
-inline qreal QVector2D::x() const { return qreal(xp); }
-inline qreal QVector2D::y() const { return qreal(yp); }
+inline float QVector2D::x() const { return xp; }
+inline float QVector2D::y() const { return yp; }
-inline void QVector2D::setX(qreal aX) { xp = aX; }
-inline void QVector2D::setY(qreal aY) { yp = aY; }
+inline void QVector2D::setX(float aX) { xp = aX; }
+inline void QVector2D::setY(float aY) { yp = aY; }
inline QVector2D &QVector2D::operator+=(const QVector2D &vector)
{
@@ -162,7 +158,7 @@ inline QVector2D &QVector2D::operator-=(const QVector2D &vector)
return *this;
}
-inline QVector2D &QVector2D::operator*=(qreal factor)
+inline QVector2D &QVector2D::operator*=(float factor)
{
xp *= factor;
yp *= factor;
@@ -176,7 +172,7 @@ inline QVector2D &QVector2D::operator*=(const QVector2D &vector)
return *this;
}
-inline QVector2D &QVector2D::operator/=(qreal divisor)
+inline QVector2D &QVector2D::operator/=(float divisor)
{
xp /= divisor;
yp /= divisor;
@@ -195,37 +191,37 @@ inline bool operator!=(const QVector2D &v1, const QVector2D &v2)
inline const QVector2D operator+(const QVector2D &v1, const QVector2D &v2)
{
- return QVector2D(v1.xp + v2.xp, v1.yp + v2.yp, 1);
+ return QVector2D(v1.xp + v2.xp, v1.yp + v2.yp);
}
inline const QVector2D operator-(const QVector2D &v1, const QVector2D &v2)
{
- return QVector2D(v1.xp - v2.xp, v1.yp - v2.yp, 1);
+ return QVector2D(v1.xp - v2.xp, v1.yp - v2.yp);
}
-inline const QVector2D operator*(qreal factor, const QVector2D &vector)
+inline const QVector2D operator*(float factor, const QVector2D &vector)
{
- return QVector2D(vector.xp * factor, vector.yp * factor, 1);
+ return QVector2D(vector.xp * factor, vector.yp * factor);
}
-inline const QVector2D operator*(const QVector2D &vector, qreal factor)
+inline const QVector2D operator*(const QVector2D &vector, float factor)
{
- return QVector2D(vector.xp * factor, vector.yp * factor, 1);
+ return QVector2D(vector.xp * factor, vector.yp * factor);
}
inline const QVector2D operator*(const QVector2D &v1, const QVector2D &v2)
{
- return QVector2D(v1.xp * v2.xp, v1.yp * v2.yp, 1);
+ return QVector2D(v1.xp * v2.xp, v1.yp * v2.yp);
}
inline const QVector2D operator-(const QVector2D &vector)
{
- return QVector2D(-vector.xp, -vector.yp, 1);
+ return QVector2D(-vector.xp, -vector.yp);
}
-inline const QVector2D operator/(const QVector2D &vector, qreal divisor)
+inline const QVector2D operator/(const QVector2D &vector, float divisor)
{
- return QVector2D(vector.xp / divisor, vector.yp / divisor, 1);
+ return QVector2D(vector.xp / divisor, vector.yp / divisor);
}
inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2)
diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp
index 076f5c9ff2..8002ef99e3 100644
--- a/src/gui/math3d/qvector3d.cpp
+++ b/src/gui/math3d/qvector3d.cpp
@@ -65,11 +65,6 @@ QT_BEGIN_NAMESPACE
The QVector3D class can also be used to represent vertices in 3D space.
We therefore do not need to provide a separate vertex class.
- \b{Note:} By design values in the QVector3D instance are stored as \c float.
- This means that on platforms where the \c qreal arguments to QVector3D
- functions are represented by \c double values, it is possible to
- lose precision.
-
\sa QVector2D, QVector4D, QQuaternion
*/
@@ -80,7 +75,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QVector3D::QVector3D(qreal xpos, qreal ypos, qreal zpos)
+ \fn QVector3D::QVector3D(float xpos, float ypos, float zpos)
Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos).
*/
@@ -120,7 +115,7 @@ QVector3D::QVector3D(const QVector2D& vector)
\sa toVector2D()
*/
-QVector3D::QVector3D(const QVector2D& vector, qreal zpos)
+QVector3D::QVector3D(const QVector2D& vector, float zpos)
{
xp = vector.xp;
yp = vector.yp;
@@ -154,7 +149,7 @@ QVector3D::QVector3D(const QVector4D& vector)
*/
/*!
- \fn qreal QVector3D::x() const
+ \fn float QVector3D::x() const
Returns the x coordinate of this point.
@@ -162,7 +157,7 @@ QVector3D::QVector3D(const QVector4D& vector)
*/
/*!
- \fn qreal QVector3D::y() const
+ \fn float QVector3D::y() const
Returns the y coordinate of this point.
@@ -170,7 +165,7 @@ QVector3D::QVector3D(const QVector4D& vector)
*/
/*!
- \fn qreal QVector3D::z() const
+ \fn float QVector3D::z() const
Returns the z coordinate of this point.
@@ -178,7 +173,7 @@ QVector3D::QVector3D(const QVector4D& vector)
*/
/*!
- \fn void QVector3D::setX(qreal x)
+ \fn void QVector3D::setX(float x)
Sets the x coordinate of this point to the given \a x coordinate.
@@ -186,7 +181,7 @@ QVector3D::QVector3D(const QVector4D& vector)
*/
/*!
- \fn void QVector3D::setY(qreal y)
+ \fn void QVector3D::setY(float y)
Sets the y coordinate of this point to the given \a y coordinate.
@@ -194,7 +189,7 @@ QVector3D::QVector3D(const QVector4D& vector)
*/
/*!
- \fn void QVector3D::setZ(qreal z)
+ \fn void QVector3D::setZ(float z)
Sets the z coordinate of this point to the given \a z coordinate.
@@ -216,12 +211,16 @@ QVector3D QVector3D::normalized() const
double len = double(xp) * double(xp) +
double(yp) * double(yp) +
double(zp) * double(zp);
- if (qFuzzyIsNull(len - 1.0f))
+ if (qFuzzyIsNull(len - 1.0f)) {
return *this;
- else if (!qFuzzyIsNull(len))
- return *this / qSqrt(len);
- else
+ } else if (!qFuzzyIsNull(len)) {
+ double sqrtLen = sqrt(len);
+ return QVector3D(float(double(xp) / sqrtLen),
+ float(double(yp) / sqrtLen),
+ float(double(zp) / sqrtLen));
+ } else {
return QVector3D();
+ }
}
/*!
@@ -239,11 +238,11 @@ void QVector3D::normalize()
if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
return;
- len = qSqrt(len);
+ len = sqrt(len);
- xp /= len;
- yp /= len;
- zp /= len;
+ xp = float(double(xp) / len);
+ yp = float(double(yp) / len);
+ zp = float(double(zp) / len);
}
/*!
@@ -265,7 +264,7 @@ void QVector3D::normalize()
*/
/*!
- \fn QVector3D &QVector3D::operator*=(qreal factor)
+ \fn QVector3D &QVector3D::operator*=(float factor)
Multiplies this vector's coordinates by the given \a factor, and
returns a reference to this vector.
@@ -287,7 +286,7 @@ void QVector3D::normalize()
*/
/*!
- \fn QVector3D &QVector3D::operator/=(qreal divisor)
+ \fn QVector3D &QVector3D::operator/=(float divisor)
Divides this vector's coordinates by the given \a divisor, and
returns a reference to this vector.
@@ -298,7 +297,7 @@ void QVector3D::normalize()
/*!
Returns the dot product of \a v1 and \a v2.
*/
-qreal QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2)
+float QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2)
{
return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp;
}
@@ -312,8 +311,8 @@ qreal QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2)
QVector3D QVector3D::crossProduct(const QVector3D& v1, const QVector3D& v2)
{
return QVector3D(v1.yp * v2.zp - v1.zp * v2.yp,
- v1.zp * v2.xp - v1.xp * v2.zp,
- v1.xp * v2.yp - v1.yp * v2.xp, 1);
+ v1.zp * v2.xp - v1.xp * v2.zp,
+ v1.xp * v2.yp - v1.yp * v2.xp);
}
/*!
@@ -358,7 +357,7 @@ QVector3D QVector3D::normal
\sa normal(), distanceToLine()
*/
-qreal QVector3D::distanceToPlane
+float QVector3D::distanceToPlane
(const QVector3D& plane, const QVector3D& normal) const
{
return dotProduct(*this - plane, normal);
@@ -378,7 +377,7 @@ qreal QVector3D::distanceToPlane
\sa normal(), distanceToLine()
*/
-qreal QVector3D::distanceToPlane
+float QVector3D::distanceToPlane
(const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const
{
QVector3D n = normal(plane2 - plane1, plane3 - plane1);
@@ -394,7 +393,7 @@ qreal QVector3D::distanceToPlane
\sa distanceToPlane()
*/
-qreal QVector3D::distanceToLine
+float QVector3D::distanceToLine
(const QVector3D& point, const QVector3D& direction) const
{
if (direction.isNull())
@@ -440,7 +439,7 @@ qreal QVector3D::distanceToLine
*/
/*!
- \fn const QVector3D operator*(qreal factor, const QVector3D &vector)
+ \fn const QVector3D operator*(float factor, const QVector3D &vector)
\relates QVector3D
Returns a copy of the given \a vector, multiplied by the given \a factor.
@@ -449,7 +448,7 @@ qreal QVector3D::distanceToLine
*/
/*!
- \fn const QVector3D operator*(const QVector3D &vector, qreal factor)
+ \fn const QVector3D operator*(const QVector3D &vector, float factor)
\relates QVector3D
Returns a copy of the given \a vector, multiplied by the given \a factor.
@@ -480,7 +479,7 @@ qreal QVector3D::distanceToLine
*/
/*!
- \fn const QVector3D operator/(const QVector3D &vector, qreal divisor)
+ \fn const QVector3D operator/(const QVector3D &vector, float divisor)
\relates QVector3D
Returns the QVector3D object formed by dividing all three components of
@@ -506,7 +505,7 @@ qreal QVector3D::distanceToLine
*/
QVector2D QVector3D::toVector2D() const
{
- return QVector2D(xp, yp, 1);
+ return QVector2D(xp, yp);
}
#endif
@@ -520,7 +519,7 @@ QVector2D QVector3D::toVector2D() const
*/
QVector4D QVector3D::toVector4D() const
{
- return QVector4D(xp, yp, zp, 0.0f, 1);
+ return QVector4D(xp, yp, zp, 0.0f);
}
#endif
@@ -556,9 +555,13 @@ QVector3D::operator QVariant() const
\sa lengthSquared(), normalized()
*/
-qreal QVector3D::length() const
+float QVector3D::length() const
{
- return qSqrt(xp * xp + yp * yp + zp * zp);
+ // Need some extra precision if the length is very small.
+ double len = double(xp) * double(xp) +
+ double(yp) * double(yp) +
+ double(zp) * double(zp);
+ return float(sqrt(len));
}
/*!
@@ -567,7 +570,7 @@ qreal QVector3D::length() const
\sa length(), dotProduct()
*/
-qreal QVector3D::lengthSquared() const
+float QVector3D::lengthSquared() const
{
return xp * xp + yp * yp + zp * zp;
}
@@ -597,8 +600,7 @@ QDebug operator<<(QDebug dbg, const QVector3D &vector)
QDataStream &operator<<(QDataStream &stream, const QVector3D &vector)
{
- stream << double(vector.x()) << double(vector.y())
- << double(vector.z());
+ stream << vector.x() << vector.y() << vector.z();
return stream;
}
@@ -614,13 +616,13 @@ QDataStream &operator<<(QDataStream &stream, const QVector3D &vector)
QDataStream &operator>>(QDataStream &stream, QVector3D &vector)
{
- double x, y, z;
+ float x, y, z;
stream >> x;
stream >> y;
stream >> z;
- vector.setX(qreal(x));
- vector.setY(qreal(y));
- vector.setZ(qreal(z));
+ vector.setX(x);
+ vector.setY(y);
+ vector.setZ(z);
return stream;
}
diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h
index d02fa7de8f..d6a8901c4f 100644
--- a/src/gui/math3d/qvector3d.h
+++ b/src/gui/math3d/qvector3d.h
@@ -60,12 +60,12 @@ class Q_GUI_EXPORT QVector3D
{
public:
QVector3D();
- QVector3D(qreal xpos, qreal ypos, qreal zpos);
+ QVector3D(float xpos, float ypos, float zpos);
explicit QVector3D(const QPoint& point);
explicit QVector3D(const QPointF& point);
#ifndef QT_NO_VECTOR2D
QVector3D(const QVector2D& vector);
- QVector3D(const QVector2D& vector, qreal zpos);
+ QVector3D(const QVector2D& vector, float zpos);
#endif
#ifndef QT_NO_VECTOR4D
explicit QVector3D(const QVector4D& vector);
@@ -73,45 +73,45 @@ public:
bool isNull() const;
- qreal x() const;
- qreal y() const;
- qreal z() const;
+ float x() const;
+ float y() const;
+ float z() const;
- void setX(qreal x);
- void setY(qreal y);
- void setZ(qreal z);
+ void setX(float x);
+ void setY(float y);
+ void setZ(float z);
- qreal length() const;
- qreal lengthSquared() const;
+ float length() const;
+ float lengthSquared() const;
QVector3D normalized() const;
void normalize();
QVector3D &operator+=(const QVector3D &vector);
QVector3D &operator-=(const QVector3D &vector);
- QVector3D &operator*=(qreal factor);
+ QVector3D &operator*=(float factor);
QVector3D &operator*=(const QVector3D& vector);
- QVector3D &operator/=(qreal divisor);
+ QVector3D &operator/=(float divisor);
- static qreal dotProduct(const QVector3D& v1, const QVector3D& v2);
+ static float dotProduct(const QVector3D& v1, const QVector3D& v2);
static QVector3D crossProduct(const QVector3D& v1, const QVector3D& v2);
static QVector3D normal(const QVector3D& v1, const QVector3D& v2);
static QVector3D normal
(const QVector3D& v1, const QVector3D& v2, const QVector3D& v3);
- qreal distanceToPlane(const QVector3D& plane, const QVector3D& normal) const;
- qreal distanceToPlane(const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const;
- qreal distanceToLine(const QVector3D& point, const QVector3D& direction) const;
+ float distanceToPlane(const QVector3D& plane, const QVector3D& normal) const;
+ float distanceToPlane(const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const;
+ float distanceToLine(const QVector3D& point, const QVector3D& direction) const;
friend inline bool operator==(const QVector3D &v1, const QVector3D &v2);
friend inline bool operator!=(const QVector3D &v1, const QVector3D &v2);
friend inline const QVector3D operator+(const QVector3D &v1, const QVector3D &v2);
friend inline const QVector3D operator-(const QVector3D &v1, const QVector3D &v2);
- friend inline const QVector3D operator*(qreal factor, const QVector3D &vector);
- friend inline const QVector3D operator*(const QVector3D &vector, qreal factor);
+ friend inline const QVector3D operator*(float factor, const QVector3D &vector);
+ friend inline const QVector3D operator*(const QVector3D &vector, float factor);
friend const QVector3D operator*(const QVector3D &v1, const QVector3D& v2);
friend inline const QVector3D operator-(const QVector3D &vector);
- friend inline const QVector3D operator/(const QVector3D &vector, qreal divisor);
+ friend inline const QVector3D operator/(const QVector3D &vector, float divisor);
friend inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2);
@@ -130,8 +130,6 @@ public:
private:
float xp, yp, zp;
- QVector3D(float xpos, float ypos, float zpos, int dummy);
-
friend class QVector2D;
friend class QVector4D;
#ifndef QT_NO_MATRIX4X4
@@ -144,9 +142,7 @@ Q_DECLARE_TYPEINFO(QVector3D, Q_MOVABLE_TYPE);
inline QVector3D::QVector3D() : xp(0.0f), yp(0.0f), zp(0.0f) {}
-inline QVector3D::QVector3D(qreal xpos, qreal ypos, qreal zpos) : xp(xpos), yp(ypos), zp(zpos) {}
-
-inline QVector3D::QVector3D(float xpos, float ypos, float zpos, int) : xp(xpos), yp(ypos), zp(zpos) {}
+inline QVector3D::QVector3D(float xpos, float ypos, float zpos) : xp(xpos), yp(ypos), zp(zpos) {}
inline QVector3D::QVector3D(const QPoint& point) : xp(point.x()), yp(point.y()), zp(0.0f) {}
@@ -157,13 +153,13 @@ inline bool QVector3D::isNull() const
return qIsNull(xp) && qIsNull(yp) && qIsNull(zp);
}
-inline qreal QVector3D::x() const { return qreal(xp); }
-inline qreal QVector3D::y() const { return qreal(yp); }
-inline qreal QVector3D::z() const { return qreal(zp); }
+inline float QVector3D::x() const { return xp; }
+inline float QVector3D::y() const { return yp; }
+inline float QVector3D::z() const { return zp; }
-inline void QVector3D::setX(qreal aX) { xp = aX; }
-inline void QVector3D::setY(qreal aY) { yp = aY; }
-inline void QVector3D::setZ(qreal aZ) { zp = aZ; }
+inline void QVector3D::setX(float aX) { xp = aX; }
+inline void QVector3D::setY(float aY) { yp = aY; }
+inline void QVector3D::setZ(float aZ) { zp = aZ; }
inline QVector3D &QVector3D::operator+=(const QVector3D &vector)
{
@@ -181,7 +177,7 @@ inline QVector3D &QVector3D::operator-=(const QVector3D &vector)
return *this;
}
-inline QVector3D &QVector3D::operator*=(qreal factor)
+inline QVector3D &QVector3D::operator*=(float factor)
{
xp *= factor;
yp *= factor;
@@ -197,7 +193,7 @@ inline QVector3D &QVector3D::operator*=(const QVector3D& vector)
return *this;
}
-inline QVector3D &QVector3D::operator/=(qreal divisor)
+inline QVector3D &QVector3D::operator/=(float divisor)
{
xp /= divisor;
yp /= divisor;
@@ -217,37 +213,37 @@ inline bool operator!=(const QVector3D &v1, const QVector3D &v2)
inline const QVector3D operator+(const QVector3D &v1, const QVector3D &v2)
{
- return QVector3D(v1.xp + v2.xp, v1.yp + v2.yp, v1.zp + v2.zp, 1);
+ return QVector3D(v1.xp + v2.xp, v1.yp + v2.yp, v1.zp + v2.zp);
}
inline const QVector3D operator-(const QVector3D &v1, const QVector3D &v2)
{
- return QVector3D(v1.xp - v2.xp, v1.yp - v2.yp, v1.zp - v2.zp, 1);
+ return QVector3D(v1.xp - v2.xp, v1.yp - v2.yp, v1.zp - v2.zp);
}
-inline const QVector3D operator*(qreal factor, const QVector3D &vector)
+inline const QVector3D operator*(float factor, const QVector3D &vector)
{
- return QVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor, 1);
+ return QVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor);
}
-inline const QVector3D operator*(const QVector3D &vector, qreal factor)
+inline const QVector3D operator*(const QVector3D &vector, float factor)
{
- return QVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor, 1);
+ return QVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor);
}
inline const QVector3D operator*(const QVector3D &v1, const QVector3D& v2)
{
- return QVector3D(v1.xp * v2.xp, v1.yp * v2.yp, v1.zp * v2.zp, 1);
+ return QVector3D(v1.xp * v2.xp, v1.yp * v2.yp, v1.zp * v2.zp);
}
inline const QVector3D operator-(const QVector3D &vector)
{
- return QVector3D(-vector.xp, -vector.yp, -vector.zp, 1);
+ return QVector3D(-vector.xp, -vector.yp, -vector.zp);
}
-inline const QVector3D operator/(const QVector3D &vector, qreal divisor)
+inline const QVector3D operator/(const QVector3D &vector, float divisor)
{
- return QVector3D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor, 1);
+ return QVector3D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor);
}
inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2)
diff --git a/src/gui/math3d/qvector4d.cpp b/src/gui/math3d/qvector4d.cpp
index a188333a3a..81eedaedb0 100644
--- a/src/gui/math3d/qvector4d.cpp
+++ b/src/gui/math3d/qvector4d.cpp
@@ -61,11 +61,6 @@ QT_BEGIN_NAMESPACE
The QVector4D class can also be used to represent vertices in 4D space.
We therefore do not need to provide a separate vertex class.
- \b{Note:} By design values in the QVector4D instance are stored as \c float.
- This means that on platforms where the \c qreal arguments to QVector4D
- functions are represented by \c double values, it is possible to
- lose precision.
-
\sa QQuaternion, QVector2D, QVector3D
*/
@@ -76,7 +71,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QVector4D::QVector4D(qreal xpos, qreal ypos, qreal zpos, qreal wpos)
+ \fn QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos)
Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos, \a wpos).
*/
@@ -117,7 +112,7 @@ QVector4D::QVector4D(const QVector2D& vector)
\sa toVector2D()
*/
-QVector4D::QVector4D(const QVector2D& vector, qreal zpos, qreal wpos)
+QVector4D::QVector4D(const QVector2D& vector, float zpos, float wpos)
{
xp = vector.xp;
yp = vector.yp;
@@ -149,7 +144,7 @@ QVector4D::QVector4D(const QVector3D& vector)
\sa toVector3D()
*/
-QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
+QVector4D::QVector4D(const QVector3D& vector, float wpos)
{
xp = vector.xp;
yp = vector.yp;
@@ -167,7 +162,7 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
*/
/*!
- \fn qreal QVector4D::x() const
+ \fn float QVector4D::x() const
Returns the x coordinate of this point.
@@ -175,7 +170,7 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
*/
/*!
- \fn qreal QVector4D::y() const
+ \fn float QVector4D::y() const
Returns the y coordinate of this point.
@@ -183,7 +178,7 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
*/
/*!
- \fn qreal QVector4D::z() const
+ \fn float QVector4D::z() const
Returns the z coordinate of this point.
@@ -191,7 +186,7 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
*/
/*!
- \fn qreal QVector4D::w() const
+ \fn float QVector4D::w() const
Returns the w coordinate of this point.
@@ -199,7 +194,7 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
*/
/*!
- \fn void QVector4D::setX(qreal x)
+ \fn void QVector4D::setX(float x)
Sets the x coordinate of this point to the given \a x coordinate.
@@ -207,7 +202,7 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
*/
/*!
- \fn void QVector4D::setY(qreal y)
+ \fn void QVector4D::setY(float y)
Sets the y coordinate of this point to the given \a y coordinate.
@@ -215,7 +210,7 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
*/
/*!
- \fn void QVector4D::setZ(qreal z)
+ \fn void QVector4D::setZ(float z)
Sets the z coordinate of this point to the given \a z coordinate.
@@ -223,7 +218,7 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
*/
/*!
- \fn void QVector4D::setW(qreal w)
+ \fn void QVector4D::setW(float w)
Sets the w coordinate of this point to the given \a w coordinate.
@@ -235,9 +230,14 @@ QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
\sa lengthSquared(), normalized()
*/
-qreal QVector4D::length() const
+float QVector4D::length() const
{
- return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp);
+ // Need some extra precision if the length is very small.
+ double len = double(xp) * double(xp) +
+ double(yp) * double(yp) +
+ double(zp) * double(zp) +
+ double(wp) * double(wp);
+ return float(sqrt(len));
}
/*!
@@ -246,7 +246,7 @@ qreal QVector4D::length() const
\sa length(), dotProduct()
*/
-qreal QVector4D::lengthSquared() const
+float QVector4D::lengthSquared() const
{
return xp * xp + yp * yp + zp * zp + wp * wp;
}
@@ -267,12 +267,17 @@ QVector4D QVector4D::normalized() const
double(yp) * double(yp) +
double(zp) * double(zp) +
double(wp) * double(wp);
- if (qFuzzyIsNull(len - 1.0f))
+ if (qFuzzyIsNull(len - 1.0f)) {
return *this;
- else if (!qFuzzyIsNull(len))
- return *this / qSqrt(len);
- else
+ } else if (!qFuzzyIsNull(len)) {
+ double sqrtLen = sqrt(len);
+ return QVector4D(float(double(xp) / sqrtLen),
+ float(double(yp) / sqrtLen),
+ float(double(zp) / sqrtLen),
+ float(double(wp) / sqrtLen));
+ } else {
return QVector4D();
+ }
}
/*!
@@ -291,12 +296,12 @@ void QVector4D::normalize()
if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
return;
- len = qSqrt(len);
+ len = sqrt(len);
- xp /= len;
- yp /= len;
- zp /= len;
- wp /= len;
+ xp = float(double(xp) / len);
+ yp = float(double(yp) / len);
+ zp = float(double(zp) / len);
+ wp = float(double(wp) / len);
}
/*!
@@ -318,7 +323,7 @@ void QVector4D::normalize()
*/
/*!
- \fn QVector4D &QVector4D::operator*=(qreal factor)
+ \fn QVector4D &QVector4D::operator*=(float factor)
Multiplies this vector's coordinates by the given \a factor, and
returns a reference to this vector.
@@ -334,7 +339,7 @@ void QVector4D::normalize()
*/
/*!
- \fn QVector4D &QVector4D::operator/=(qreal divisor)
+ \fn QVector4D &QVector4D::operator/=(float divisor)
Divides this vector's coordinates by the given \a divisor, and
returns a reference to this vector.
@@ -345,7 +350,7 @@ void QVector4D::normalize()
/*!
Returns the dot product of \a v1 and \a v2.
*/
-qreal QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
+float QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
{
return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp + v1.wp * v2.wp;
}
@@ -387,7 +392,7 @@ qreal QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
*/
/*!
- \fn const QVector4D operator*(qreal factor, const QVector4D &vector)
+ \fn const QVector4D operator*(float factor, const QVector4D &vector)
\relates QVector4D
Returns a copy of the given \a vector, multiplied by the given \a factor.
@@ -396,7 +401,7 @@ qreal QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
*/
/*!
- \fn const QVector4D operator*(const QVector4D &vector, qreal factor)
+ \fn const QVector4D operator*(const QVector4D &vector, float factor)
\relates QVector4D
Returns a copy of the given \a vector, multiplied by the given \a factor.
@@ -426,7 +431,7 @@ qreal QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
*/
/*!
- \fn const QVector4D operator/(const QVector4D &vector, qreal divisor)
+ \fn const QVector4D operator/(const QVector4D &vector, float divisor)
\relates QVector4D
Returns the QVector4D object formed by dividing all four components of
@@ -452,7 +457,7 @@ qreal QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
*/
QVector2D QVector4D::toVector2D() const
{
- return QVector2D(xp, yp, 1);
+ return QVector2D(xp, yp);
}
/*!
@@ -466,7 +471,7 @@ QVector2D QVector4D::toVector2DAffine() const
{
if (qIsNull(wp))
return QVector2D();
- return QVector2D(xp / wp, yp / wp, 1);
+ return QVector2D(xp / wp, yp / wp);
}
#endif
@@ -480,7 +485,7 @@ QVector2D QVector4D::toVector2DAffine() const
*/
QVector3D QVector4D::toVector3D() const
{
- return QVector3D(xp, yp, zp, 1);
+ return QVector3D(xp, yp, zp);
}
/*!
@@ -493,7 +498,7 @@ QVector3D QVector4D::toVector3DAffine() const
{
if (qIsNull(wp))
return QVector3D();
- return QVector3D(xp / wp, yp / wp, zp / wp, 1);
+ return QVector3D(xp / wp, yp / wp, zp / wp);
}
#endif
@@ -550,8 +555,8 @@ QDebug operator<<(QDebug dbg, const QVector4D &vector)
QDataStream &operator<<(QDataStream &stream, const QVector4D &vector)
{
- stream << double(vector.x()) << double(vector.y())
- << double(vector.z()) << double(vector.w());
+ stream << vector.x() << vector.y()
+ << vector.z() << vector.w();
return stream;
}
@@ -567,15 +572,15 @@ QDataStream &operator<<(QDataStream &stream, const QVector4D &vector)
QDataStream &operator>>(QDataStream &stream, QVector4D &vector)
{
- double x, y, z, w;
+ float x, y, z, w;
stream >> x;
stream >> y;
stream >> z;
stream >> w;
- vector.setX(qreal(x));
- vector.setY(qreal(y));
- vector.setZ(qreal(z));
- vector.setW(qreal(w));
+ vector.setX(x);
+ vector.setY(y);
+ vector.setZ(z);
+ vector.setW(w);
return stream;
}
diff --git a/src/gui/math3d/qvector4d.h b/src/gui/math3d/qvector4d.h
index 384dd6a2a6..c793c4ef37 100644
--- a/src/gui/math3d/qvector4d.h
+++ b/src/gui/math3d/qvector4d.h
@@ -60,53 +60,53 @@ class Q_GUI_EXPORT QVector4D
{
public:
QVector4D();
- QVector4D(qreal xpos, qreal ypos, qreal zpos, qreal wpos);
+ QVector4D(float xpos, float ypos, float zpos, float wpos);
explicit QVector4D(const QPoint& point);
explicit QVector4D(const QPointF& point);
#ifndef QT_NO_VECTOR2D
QVector4D(const QVector2D& vector);
- QVector4D(const QVector2D& vector, qreal zpos, qreal wpos);
+ QVector4D(const QVector2D& vector, float zpos, float wpos);
#endif
#ifndef QT_NO_VECTOR3D
QVector4D(const QVector3D& vector);
- QVector4D(const QVector3D& vector, qreal wpos);
+ QVector4D(const QVector3D& vector, float wpos);
#endif
bool isNull() const;
- qreal x() const;
- qreal y() const;
- qreal z() const;
- qreal w() const;
+ float x() const;
+ float y() const;
+ float z() const;
+ float w() const;
- void setX(qreal x);
- void setY(qreal y);
- void setZ(qreal z);
- void setW(qreal w);
+ void setX(float x);
+ void setY(float y);
+ void setZ(float z);
+ void setW(float w);
- qreal length() const;
- qreal lengthSquared() const;
+ float length() const;
+ float lengthSquared() const;
QVector4D normalized() const;
void normalize();
QVector4D &operator+=(const QVector4D &vector);
QVector4D &operator-=(const QVector4D &vector);
- QVector4D &operator*=(qreal factor);
+ QVector4D &operator*=(float factor);
QVector4D &operator*=(const QVector4D &vector);
- QVector4D &operator/=(qreal divisor);
+ QVector4D &operator/=(float divisor);
- static qreal dotProduct(const QVector4D& v1, const QVector4D& v2);
+ static float dotProduct(const QVector4D& v1, const QVector4D& v2);
friend inline bool operator==(const QVector4D &v1, const QVector4D &v2);
friend inline bool operator!=(const QVector4D &v1, const QVector4D &v2);
friend inline const QVector4D operator+(const QVector4D &v1, const QVector4D &v2);
friend inline const QVector4D operator-(const QVector4D &v1, const QVector4D &v2);
- friend inline const QVector4D operator*(qreal factor, const QVector4D &vector);
- friend inline const QVector4D operator*(const QVector4D &vector, qreal factor);
+ friend inline const QVector4D operator*(float factor, const QVector4D &vector);
+ friend inline const QVector4D operator*(const QVector4D &vector, float factor);
friend inline const QVector4D operator*(const QVector4D &v1, const QVector4D& v2);
friend inline const QVector4D operator-(const QVector4D &vector);
- friend inline const QVector4D operator/(const QVector4D &vector, qreal divisor);
+ friend inline const QVector4D operator/(const QVector4D &vector, float divisor);
friend inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2);
@@ -127,8 +127,6 @@ public:
private:
float xp, yp, zp, wp;
- QVector4D(float xpos, float ypos, float zpos, float wpos, int dummy);
-
friend class QVector2D;
friend class QVector3D;
#ifndef QT_NO_MATRIX4X4
@@ -141,9 +139,7 @@ Q_DECLARE_TYPEINFO(QVector4D, Q_MOVABLE_TYPE);
inline QVector4D::QVector4D() : xp(0.0f), yp(0.0f), zp(0.0f), wp(0.0f) {}
-inline QVector4D::QVector4D(qreal xpos, qreal ypos, qreal zpos, qreal wpos) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {}
-
-inline QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos, int) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {}
+inline QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {}
inline QVector4D::QVector4D(const QPoint& point) : xp(point.x()), yp(point.y()), zp(0.0f), wp(0.0f) {}
@@ -154,15 +150,15 @@ inline bool QVector4D::isNull() const
return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && qIsNull(wp);
}
-inline qreal QVector4D::x() const { return qreal(xp); }
-inline qreal QVector4D::y() const { return qreal(yp); }
-inline qreal QVector4D::z() const { return qreal(zp); }
-inline qreal QVector4D::w() const { return qreal(wp); }
+inline float QVector4D::x() const { return xp; }
+inline float QVector4D::y() const { return yp; }
+inline float QVector4D::z() const { return zp; }
+inline float QVector4D::w() const { return wp; }
-inline void QVector4D::setX(qreal aX) { xp = aX; }
-inline void QVector4D::setY(qreal aY) { yp = aY; }
-inline void QVector4D::setZ(qreal aZ) { zp = aZ; }
-inline void QVector4D::setW(qreal aW) { wp = aW; }
+inline void QVector4D::setX(float aX) { xp = aX; }
+inline void QVector4D::setY(float aY) { yp = aY; }
+inline void QVector4D::setZ(float aZ) { zp = aZ; }
+inline void QVector4D::setW(float aW) { wp = aW; }
inline QVector4D &QVector4D::operator+=(const QVector4D &vector)
{
@@ -182,7 +178,7 @@ inline QVector4D &QVector4D::operator-=(const QVector4D &vector)
return *this;
}
-inline QVector4D &QVector4D::operator*=(qreal factor)
+inline QVector4D &QVector4D::operator*=(float factor)
{
xp *= factor;
yp *= factor;
@@ -200,7 +196,7 @@ inline QVector4D &QVector4D::operator*=(const QVector4D &vector)
return *this;
}
-inline QVector4D &QVector4D::operator/=(qreal divisor)
+inline QVector4D &QVector4D::operator/=(float divisor)
{
xp /= divisor;
yp /= divisor;
@@ -221,37 +217,37 @@ inline bool operator!=(const QVector4D &v1, const QVector4D &v2)
inline const QVector4D operator+(const QVector4D &v1, const QVector4D &v2)
{
- return QVector4D(v1.xp + v2.xp, v1.yp + v2.yp, v1.zp + v2.zp, v1.wp + v2.wp, 1);
+ return QVector4D(v1.xp + v2.xp, v1.yp + v2.yp, v1.zp + v2.zp, v1.wp + v2.wp);
}
inline const QVector4D operator-(const QVector4D &v1, const QVector4D &v2)
{
- return QVector4D(v1.xp - v2.xp, v1.yp - v2.yp, v1.zp - v2.zp, v1.wp - v2.wp, 1);
+ return QVector4D(v1.xp - v2.xp, v1.yp - v2.yp, v1.zp - v2.zp, v1.wp - v2.wp);
}
-inline const QVector4D operator*(qreal factor, const QVector4D &vector)
+inline const QVector4D operator*(float factor, const QVector4D &vector)
{
- return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor, 1);
+ return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor);
}
-inline const QVector4D operator*(const QVector4D &vector, qreal factor)
+inline const QVector4D operator*(const QVector4D &vector, float factor)
{
- return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor, 1);
+ return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor);
}
inline const QVector4D operator*(const QVector4D &v1, const QVector4D& v2)
{
- return QVector4D(v1.xp * v2.xp, v1.yp * v2.yp, v1.zp * v2.zp, v1.wp * v2.wp, 1);
+ return QVector4D(v1.xp * v2.xp, v1.yp * v2.yp, v1.zp * v2.zp, v1.wp * v2.wp);
}
inline const QVector4D operator-(const QVector4D &vector)
{
- return QVector4D(-vector.xp, -vector.yp, -vector.zp, -vector.wp, 1);
+ return QVector4D(-vector.xp, -vector.yp, -vector.zp, -vector.wp);
}
-inline const QVector4D operator/(const QVector4D &vector, qreal divisor)
+inline const QVector4D operator/(const QVector4D &vector, float divisor)
{
- return QVector4D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor, vector.wp / divisor, 1);
+ return QVector4D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor, vector.wp / divisor);
}
inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2)
diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp
index 100fc0bbdb..e74d4952d0 100644
--- a/src/gui/opengl/qopenglshaderprogram.cpp
+++ b/src/gui/opengl/qopenglshaderprogram.cpp
@@ -2131,35 +2131,6 @@ void QOpenGLShaderProgram::setUniformValue(const char *name, const QSizeF& size)
setUniformValue(uniformLocation(name), size);
}
-// We have to repack matrices from qreal to GLfloat.
-#define setUniformMatrix(func,location,value,cols,rows) \
- if (location == -1) \
- return; \
- if (sizeof(qreal) == sizeof(GLfloat)) { \
- func(location, 1, GL_FALSE, \
- reinterpret_cast<const GLfloat *>(value.constData())); \
- } else { \
- GLfloat mat[cols * rows]; \
- const qreal *data = value.constData(); \
- for (int i = 0; i < cols * rows; ++i) \
- mat[i] = data[i]; \
- func(location, 1, GL_FALSE, mat); \
- }
-#define setUniformGenericMatrix(colfunc,location,value,cols,rows) \
- if (location == -1) \
- return; \
- if (sizeof(qreal) == sizeof(GLfloat)) { \
- const GLfloat *data = reinterpret_cast<const GLfloat *> \
- (value.constData()); \
- colfunc(location, cols, data); \
- } else { \
- GLfloat mat[cols * rows]; \
- const qreal *data = value.constData(); \
- for (int i = 0; i < cols * rows; ++i) \
- mat[i] = data[i]; \
- colfunc(location, cols, mat); \
- }
-
/*!
Sets the uniform variable at \a location in the current context
to a 2x2 matrix \a value.
@@ -2170,7 +2141,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x2& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformMatrix(d->glfuncs->glUniformMatrix2fv, location, value, 2, 2);
+ d->glfuncs->glUniformMatrix2fv(location, 1, GL_FALSE, value.constData());
}
/*!
@@ -2196,8 +2167,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x3& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform3fv, location, value, 2, 3);
+ d->glfuncs->glUniform3fv(location, 2, value.constData());
}
/*!
@@ -2223,8 +2193,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x4& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform4fv, location, value, 2, 4);
+ d->glfuncs->glUniform4fv(location, 2, value.constData());
}
/*!
@@ -2250,8 +2219,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x2& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform2fv, location, value, 3, 2);
+ d->glfuncs->glUniform2fv(location, 3, value.constData());
}
/*!
@@ -2277,7 +2245,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x3& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformMatrix(d->glfuncs->glUniformMatrix3fv, location, value, 3, 3);
+ d->glfuncs->glUniformMatrix3fv(location, 1, GL_FALSE, value.constData());
}
/*!
@@ -2303,8 +2271,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x4& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform4fv, location, value, 3, 4);
+ d->glfuncs->glUniform4fv(location, 3, value.constData());
}
/*!
@@ -2330,8 +2297,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x2& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform2fv, location, value, 4, 2);
+ d->glfuncs->glUniform2fv(location, 4, value.constData());
}
/*!
@@ -2357,8 +2323,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x3& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform3fv, location, value, 4, 3);
+ d->glfuncs->glUniform3fv(location, 4, value.constData());
}
/*!
@@ -2384,7 +2349,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x4& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformMatrix(d->glfuncs->glUniformMatrix4fv, location, value, 4, 4);
+ d->glfuncs->glUniformMatrix4fv(location, 1, GL_FALSE, value.constData());
}
/*!