summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d/qquaternion.cpp
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-09-04 04:12:08 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-09-04 07:00:23 (GMT)
commit974aec137dfdbb1dd68c41113b22eb25131965b8 (patch)
treeadbf042502fd35d1bce5a2aea811d41633ecd495 /src/gui/math3d/qquaternion.cpp
parent4c501d7fce503a610edabfba5d6efc3ef2778bef (diff)
downloadQt-974aec137dfdbb1dd68c41113b22eb25131965b8.zip
Qt-974aec137dfdbb1dd68c41113b22eb25131965b8.tar.gz
Qt-974aec137dfdbb1dd68c41113b22eb25131965b8.tar.bz2
Modify QMatrix4x4 and QQuaternion to use qreal internally
Some concerns were expressed about the float precision of QMatrix4x4, which this change addresses by using qreal instead. The QVector2D/3D/4D classes still use float internally, so that they can be used directly in large arrays of vertex values to be uploaded to an OpenGL server. QQuaternion is a client-side class, and it should produce rotations that are consistent with QMatrix4x4. So its precision was changed too. A consequence of this change is that the following no longer works in a portable fashion: QMatrix4x4 mat; ... glLoadMatrixf(mat.constData()); The caller must now repack the argument to convert from qreal to GLfloat. Reviewed-by: Michael Goddard Reviewed-by: Andreas
Diffstat (limited to 'src/gui/math3d/qquaternion.cpp')
-rw-r--r--src/gui/math3d/qquaternion.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp
index ece4482..7206e9a 100644
--- a/src/gui/math3d/qquaternion.cpp
+++ b/src/gui/math3d/qquaternion.cpp
@@ -353,7 +353,7 @@ QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle)
qreal s = qSin(a);
qreal c = qCos(a);
QVector3D ax = axis.normalized();
- return QQuaternion(c, ax.xp * s, ax.yp * s, ax.zp * s, 1).normalized();
+ return QQuaternion(c, ax.x() * s, ax.y() * s, ax.z() * s).normalized();
}
#endif
@@ -365,19 +365,16 @@ QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle)
QQuaternion QQuaternion::fromAxisAndAngle
(qreal x, qreal y, qreal z, qreal angle)
{
- float xp = x;
- float yp = y;
- float zp = z;
- qreal length = qSqrt(xp * xp + yp * yp + zp * zp);
- if (!qIsNull(length)) {
- xp /= length;
- yp /= length;
- zp /= length;
+ qreal 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);
- return QQuaternion(c, xp * s, yp * s, zp * s, 1).normalized();
+ return QQuaternion(c, x * s, y * s, z * s).normalized();
}
/*!