summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d/qquaternion.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/math3d/qquaternion.h')
-rw-r--r--src/gui/math3d/qquaternion.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h
index e0e52cefdd..2bef926b76 100644
--- a/src/gui/math3d/qquaternion.h
+++ b/src/gui/math3d/qquaternion.h
@@ -82,6 +82,8 @@ public:
QQuaternion normalized() const;
void normalize();
+ inline QQuaternion inverted() const;
+
QQuaternion conjugate() const;
QVector3D rotatedVector(const QVector3D& vector) const;
@@ -152,6 +154,18 @@ 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::inverted() const
+{
+ // 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);
+ if (!qFuzzyIsNull(len))
+ return QQuaternion(wp / len, -xp / len, -yp / len, -zp / len);
+ return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
+}
+
inline QQuaternion QQuaternion::conjugate() const
{
return QQuaternion(wp, -xp, -yp, -zp);