From e1c3732c51f9099bed10d36805b738015adc8f47 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Fri, 11 Jan 2019 02:50:43 +0100 Subject: [PATCH] Main: Quaternion - inline several trivial member functions --- OgreMain/include/OgreQuaternion.h | 37 ++++++++++++++++++++------- OgreMain/src/OgreQuaternion.cpp | 42 ------------------------------- 2 files changed, 28 insertions(+), 51 deletions(-) diff --git a/OgreMain/include/OgreQuaternion.h b/OgreMain/include/OgreQuaternion.h index ec9ac89f0af..136b72f22e4 100644 --- a/OgreMain/include/OgreQuaternion.h +++ b/OgreMain/include/OgreQuaternion.h @@ -178,11 +178,16 @@ namespace Ogre { } Quaternion operator+ (const Quaternion& rkQ) const; Quaternion operator- (const Quaternion& rkQ) const; - Quaternion operator* (const Quaternion& rkQ) const; - Quaternion operator* (Real fScalar) const; - _OgreExport friend Quaternion operator* (Real fScalar, - const Quaternion& rkQ); - Quaternion operator- () const; + Quaternion operator*(const Quaternion& rkQ) const; + Quaternion operator*(Real s) const + { + return Quaternion(s * w, s * x, s * y, s * z); + } + _OgreExport friend Quaternion operator*(Real s, const Quaternion& q) + { + return q * s; + } + Quaternion operator-() const { return Quaternion(-w, -x, -y, -z); } inline bool operator== (const Quaternion& rhs) const { return (rhs.x == x) && (rhs.y == y) && @@ -194,11 +199,19 @@ namespace Ogre { } // functions of a quaternion /// Returns the dot product of the quaternion - Real Dot (const Quaternion& rkQ) const; + Real Dot(const Quaternion& rkQ) const + { + return w * rkQ.w + x * rkQ.x + y * rkQ.y + z * rkQ.z; + } /// Returns the normal length of this quaternion. - Real Norm () const; + Real Norm() const { return Math::Sqrt(w * w + x * x + y * y + z * z); } /// Normalises this quaternion, and returns the previous length - Real normalise(void); + Real normalise(void) + { + Real len = Norm(); + *this = 1.0f / len * *this; + return len; + } Quaternion Inverse () const; /// Apply to non-zero quaternion Quaternion UnitInverse () const; /// Apply to unit-length quaternion Quaternion Exp () const; @@ -245,7 +258,13 @@ namespace Ogre { @remark Both equals() and orientationEquals() measure the exact same thing. One measures the difference by angle, the other by a different, non-linear metric. */ - bool equals(const Quaternion& rhs, const Radian& tolerance) const; + bool equals(const Quaternion& rhs, const Radian& tolerance) const + { + Real d = Dot(rhs); + Radian angle = Math::ACos(2.0f * d*d - 1.0f); + + return Math::Abs(angle.valueRadians()) <= tolerance.valueRadians(); + } /** Compare two quaternions which are assumed to be used as orientations. @remark Both equals() and orientationEquals() measure the exact same thing. diff --git a/OgreMain/src/OgreQuaternion.cpp b/OgreMain/src/OgreQuaternion.cpp index b8dc4d820a6..9682ab66733 100644 --- a/OgreMain/src/OgreQuaternion.cpp +++ b/OgreMain/src/OgreQuaternion.cpp @@ -271,32 +271,6 @@ namespace Ogre { ); } //----------------------------------------------------------------------- - Quaternion Quaternion::operator* (Real fScalar) const - { - return Quaternion(fScalar*w,fScalar*x,fScalar*y,fScalar*z); - } - //----------------------------------------------------------------------- - Quaternion operator* (Real fScalar, const Quaternion& rkQ) - { - return Quaternion(fScalar*rkQ.w,fScalar*rkQ.x,fScalar*rkQ.y, - fScalar*rkQ.z); - } - //----------------------------------------------------------------------- - Quaternion Quaternion::operator- () const - { - return Quaternion(-w,-x,-y,-z); - } - //----------------------------------------------------------------------- - Real Quaternion::Dot (const Quaternion& rkQ) const - { - return w*rkQ.w+x*rkQ.x+y*rkQ.y+z*rkQ.z; - } - //----------------------------------------------------------------------- - Real Quaternion::Norm () const - { - return Math::Sqrt(w * w + x * x + y * y + z * z); - } - //----------------------------------------------------------------------- Quaternion Quaternion::Inverse () const { Real fNorm = w*w+x*x+y*y+z*z; @@ -395,14 +369,6 @@ namespace Ogre { return v + uv + uuv; } - //----------------------------------------------------------------------- - bool Quaternion::equals(const Quaternion& rhs, const Radian& tolerance) const - { - Real d = Dot(rhs); - Radian angle = Math::ACos(2.0f * d*d - 1.0f); - - return Math::Abs(angle.valueRadians()) <= tolerance.valueRadians(); - } //----------------------------------------------------------------------- Quaternion Quaternion::Slerp (Real fT, const Quaternion& rkP, const Quaternion& rkQ, bool shortestPath) @@ -489,14 +455,6 @@ namespace Ogre { Quaternion kSlerpQ = Slerp(fT, rkA, rkB); return Slerp(fSlerpT, kSlerpP ,kSlerpQ); } - //----------------------------------------------------------------------- - Real Quaternion::normalise(void) - { - Real len = Norm(); - Real factor = 1.0f / len; - *this = *this * factor; - return len; - } //----------------------------------------------------------------------- Radian Quaternion::getRoll(bool reprojectAxis) const {