Skip to content

Commit

Permalink
Main: Quaternion - inline several trivial member functions
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Jan 11, 2019
1 parent 420a296 commit e1c3732
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 51 deletions.
37 changes: 28 additions & 9 deletions OgreMain/include/OgreQuaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
42 changes: 0 additions & 42 deletions OgreMain/src/OgreQuaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit e1c3732

Please sign in to comment.