OgreQuaternion.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
// This file is based on material originally from:
// Geometric Tools, LLC
// Copyright (c) 1998-2010
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
#ifndef __Quaternion_H__
#define __Quaternion_H__
#include "OgrePrerequisites.h"
#include "OgreMath.h"
namespace Ogre {
class _OgreExport Quaternion
{
public:
inline Quaternion ()
: w(1), x(0), y(0), z(0)
{
}
inline Quaternion (
Real fW,
Real fX, Real fY, Real fZ)
: w(fW), x(fX), y(fY), z(fZ)
{
}
inline Quaternion(const Matrix3& rot)
{
this->FromRotationMatrix(rot);
}
inline Quaternion(const Radian& rfAngle, const Vector3& rkAxis)
{
this->FromAngleAxis(rfAngle, rkAxis);
}
inline Quaternion(const Vector3& xaxis, const Vector3& yaxis, const Vector3& zaxis)
{
this->FromAxes(xaxis, yaxis, zaxis);
}
inline Quaternion(const Vector3* akAxis)
{
this->FromAxes(akAxis);
}
inline Quaternion(Real* valptr)
{
memcpy(&w, valptr, sizeof(Real)*4);
}
inline void swap(Quaternion& other)
{
std::swap(w, other.w);
std::swap(x, other.x);
std::swap(y, other.y);
std::swap(z, other.z);
}
inline Real operator [] ( const size_t i ) const
{
assert( i < 4 );
return *(&w+i);
}
inline Real& operator [] ( const size_t i )
{
assert( i < 4 );
return *(&w+i);
}
inline Real* ptr()
{
return &w;
}
inline const Real* ptr() const
{
return &w;
}
void FromRotationMatrix (const Matrix3& kRot);
void ToRotationMatrix (Matrix3& kRot) const;
void FromAngleAxis (const Radian& rfAngle, const Vector3& rkAxis);
void ToAngleAxis (Radian& rfAngle, Vector3& rkAxis) const;
inline void ToAngleAxis (Degree& dAngle, Vector3& rkAxis) const {
Radian rAngle;
ToAngleAxis ( rAngle, rkAxis );
dAngle = rAngle;
}
void FromAxes (const Vector3* akAxis);
void FromAxes (const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
void ToAxes (Vector3* akAxis) const;
void ToAxes (Vector3& xAxis, Vector3& yAxis, Vector3& zAxis) const;
Vector3 xAxis(void) const;
Vector3 yAxis(void) const;
Vector3 zAxis(void) const;
inline Quaternion& operator= (const Quaternion& rkQ)
{
w = rkQ.w;
x = rkQ.x;
y = rkQ.y;
z = rkQ.z;
return *this;
}
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;
inline bool operator== (const Quaternion& rhs) const
{
return (rhs.x == x) && (rhs.y == y) &&
(rhs.z == z) && (rhs.w == w);
}
inline bool operator!= (const Quaternion& rhs) const
{
return !operator==(rhs);
}
// functions of a quaternion
Real Dot (const Quaternion& rkQ) const;
/* Returns the normal length of this quaternion.
@note This does <b>not</b> alter any values.
*/
Real Norm () const;
Real normalise(void);
Quaternion Inverse () const;
Quaternion UnitInverse () const;
Quaternion Exp () const;
Quaternion Log () const;
Vector3 operator* (const Vector3& rkVector) const;
Radian getRoll(bool reprojectAxis = true) const;
Radian getPitch(bool reprojectAxis = true) const;
Radian getYaw(bool reprojectAxis = true) const;
bool equals(const Quaternion& rhs, const Radian& tolerance) const;
static Quaternion Slerp (Real fT, const Quaternion& rkP,
const Quaternion& rkQ, bool shortestPath = false);
static Quaternion SlerpExtraSpins (Real fT,
const Quaternion& rkP, const Quaternion& rkQ,
int iExtraSpins);
static void Intermediate (const Quaternion& rkQ0,
const Quaternion& rkQ1, const Quaternion& rkQ2,
Quaternion& rka, Quaternion& rkB);
static Quaternion Squad (Real fT, const Quaternion& rkP,
const Quaternion& rkA, const Quaternion& rkB,
const Quaternion& rkQ, bool shortestPath = false);
static Quaternion nlerp(Real fT, const Quaternion& rkP,
const Quaternion& rkQ, bool shortestPath = false);
static const Real msEpsilon;
// special values
static const Quaternion ZERO;
static const Quaternion IDENTITY;
Real w, x, y, z;
inline bool isNaN() const
{
return Math::isNaN(x) || Math::isNaN(y) || Math::isNaN(z) || Math::isNaN(w);
}
inline _OgreExport friend std::ostream& operator <<
( std::ostream& o, const Quaternion& q )
{
o << "Quaternion(" << q.w << ", " << q.x << ", " << q.y << ", " << q.z << ")";
return o;
}
};
}
#endif
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::Quaternion::ptr
Real * ptr()
Pointer accessor for direct copying.
Definition: OgreQuaternion.h:125
Ogre::Quaternion
Implementation of a Quaternion, i.e.
Definition: OgreQuaternion.h:57
Ogre::Matrix3
A 3x3 matrix which can represent rotations around axes.
Definition: OgreMatrix3.h:68
Ogre::Quaternion::Quaternion
Quaternion(const Radian &rfAngle, const Vector3 &rkAxis)
Construct a quaternion from an angle/axis.
Definition: OgreQuaternion.h:78
Ogre::Math::isNaN
static bool isNaN(Real f)
Definition: OgreMath.h:305
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Quaternion::msEpsilon
static const Real msEpsilon
Cutoff for sine near zero.
Definition: OgreQuaternion.h:297
Ogre::Quaternion::Quaternion
Quaternion(const Vector3 &xaxis, const Vector3 &yaxis, const Vector3 &zaxis)
Construct a quaternion from 3 orthonormal local axes.
Definition: OgreQuaternion.h:83
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
OgrePrerequisites.h
Ogre::Quaternion::ToAngleAxis
void ToAngleAxis(Degree &dAngle, Vector3 &rkAxis) const
Definition: OgreQuaternion.h:143
Ogre::Quaternion::y
Real y
Definition: OgreQuaternion.h:303
Ogre::Quaternion::ZERO
static const Quaternion ZERO
Definition: OgreQuaternion.h:300
Ogre::Quaternion::ptr
const Real * ptr() const
Pointer accessor for direct copying.
Definition: OgreQuaternion.h:131
Ogre::operator!=
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
Definition: OgreMemorySTLAllocator.h:202
Ogre::Quaternion::Quaternion
Quaternion(const Matrix3 &rot)
Construct a quaternion from a rotation matrix.
Definition: OgreQuaternion.h:73
Ogre::Quaternion::x
Real x
Definition: OgreQuaternion.h:303
Ogre::Quaternion::Quaternion
Quaternion(Real fW, Real fX, Real fY, Real fZ)
Construct from an explicit list of values.
Definition: OgreQuaternion.h:66
Ogre::Quaternion::w
Real w
Definition: OgreQuaternion.h:303
std::swap
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: OgreSmallVector.h:802
Ogre::Log
Definition: OgreLog.h:103
Ogre::Quaternion::isNaN
bool isNaN() const
Check whether this quaternion contains valid values.
Definition: OgreQuaternion.h:306
Ogre::Quaternion::Quaternion
Quaternion()
Default constructor, initializes to identity rotation (aka 0°)
Definition: OgreQuaternion.h:61
Ogre
Definition: OgreAndroidLogListener.h:34
OgreMath.h
Ogre::Quaternion::z
Real z
Definition: OgreQuaternion.h:303
Ogre::Quaternion::Quaternion
Quaternion(Real *valptr)
Construct a quaternion from 4 manual w/x/y/z values.
Definition: OgreQuaternion.h:93
Ogre::operator==
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
Definition: OgreMemorySTLAllocator.h:184
Ogre::Quaternion::swap
void swap(Quaternion &other)
Exchange the contents of this quaternion with another.
Definition: OgreQuaternion.h:100
Ogre::Degree
Wrapper class which indicates a given angle value is in Degrees.
Definition: OgreMath.h:98
Ogre::Quaternion::IDENTITY
static const Quaternion IDENTITY
Definition: OgreQuaternion.h:301
Ogre::operator*
Radian operator*(Real a, const Radian &b)
Definition: OgreMath.h:747
Ogre::Quaternion::Quaternion
Quaternion(const Vector3 *akAxis)
Construct a quaternion from 3 orthonormal local axes.
Definition: OgreQuaternion.h:88
Ogre::Radian
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:47

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.