summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d/qquaternion.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-04-20 22:10:33 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-07-07 05:22:54 +0000
commit596e157d3cdedf875447514a3cf55e728304c7a1 (patch)
tree129290f3b0b3c05dc10ee0b24e6ac78dba235918 /src/gui/math3d/qquaternion.h
parent84770d6375dab57d07a2d3028182a1d920bb58c1 (diff)
QQuaternion: perform some operations in memory order
The order of member variables is wp, xp, yp, zp. When performing operations that touch all members, do so in declaration (=memory) order. Might enable autovectorization. Probably leads to slightly better cache behavior. Change-Id: Id9541e5a8011c349f5d24c5e9322bb232a7607b6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui/math3d/qquaternion.h')
-rw-r--r--src/gui/math3d/qquaternion.h28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h
index 5b0006ac56..3716220a60 100644
--- a/src/gui/math3d/qquaternion.h
+++ b/src/gui/math3d/qquaternion.h
@@ -164,12 +164,12 @@ inline QQuaternion::QQuaternion(float aScalar, float xpos, float ypos, float zpo
inline bool QQuaternion::isNull() const
{
- return xp == 0.0f && yp == 0.0f && zp == 0.0f && wp == 0.0f;
+ return wp == 0.0f && xp == 0.0f && yp == 0.0f && zp == 0.0f;
}
inline bool QQuaternion::isIdentity() const
{
- return xp == 0.0f && yp == 0.0f && zp == 0.0f && wp == 1.0f;
+ return wp == 1.0f && xp == 0.0f && yp == 0.0f && zp == 0.0f;
}
inline float QQuaternion::x() const { return xp; }
@@ -184,16 +184,16 @@ inline void QQuaternion::setScalar(float aScalar) { wp = aScalar; }
Q_DECL_CONSTEXPR inline float QQuaternion::dotProduct(const QQuaternion &q1, const QQuaternion &q2)
{
- return q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp;
+ return q1.wp * q2.wp + q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp;
}
inline QQuaternion QQuaternion::inverted() const
{
// Need some extra precision if the length is very small.
- double len = double(xp) * double(xp) +
+ double len = double(wp) * double(wp) +
+ double(xp) * double(xp) +
double(yp) * double(yp) +
- double(zp) * double(zp) +
- double(wp) * double(wp);
+ double(zp) * double(zp);
if (!qFuzzyIsNull(len))
return QQuaternion(wp / len, -xp / len, -yp / len, -zp / len);
return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
@@ -213,28 +213,28 @@ inline QQuaternion QQuaternion::conjugate() const
inline QQuaternion &QQuaternion::operator+=(const QQuaternion &quaternion)
{
+ wp += quaternion.wp;
xp += quaternion.xp;
yp += quaternion.yp;
zp += quaternion.zp;
- wp += quaternion.wp;
return *this;
}
inline QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion)
{
+ wp -= quaternion.wp;
xp -= quaternion.xp;
yp -= quaternion.yp;
zp -= quaternion.zp;
- wp -= quaternion.wp;
return *this;
}
inline QQuaternion &QQuaternion::operator*=(float factor)
{
+ wp *= factor;
xp *= factor;
yp *= factor;
zp *= factor;
- wp *= factor;
return *this;
}
@@ -262,16 +262,16 @@ inline QQuaternion &QQuaternion::operator*=(const QQuaternion &quaternion)
inline QQuaternion &QQuaternion::operator/=(float divisor)
{
+ wp /= divisor;
xp /= divisor;
yp /= divisor;
zp /= divisor;
- wp /= divisor;
return *this;
}
inline bool operator==(const QQuaternion &q1, const QQuaternion &q2)
{
- return q1.xp == q2.xp && q1.yp == q2.yp && q1.zp == q2.zp && q1.wp == q2.wp;
+ return q1.wp == q2.wp && q1.xp == q2.xp && q1.yp == q2.yp && q1.zp == q2.zp;
}
inline bool operator!=(const QQuaternion &q1, const QQuaternion &q2)
@@ -311,10 +311,10 @@ inline const QQuaternion operator/(const QQuaternion &quaternion, float divisor)
inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2)
{
- return qFuzzyCompare(q1.xp, q2.xp) &&
+ return qFuzzyCompare(q1.wp, q2.wp) &&
+ qFuzzyCompare(q1.xp, q2.xp) &&
qFuzzyCompare(q1.yp, q2.yp) &&
- qFuzzyCompare(q1.zp, q2.zp) &&
- qFuzzyCompare(q1.wp, q2.wp);
+ qFuzzyCompare(q1.zp, q2.zp);
}
#ifndef QT_NO_VECTOR3D