36#ifndef __Quaternion_H__
37#define __Quaternion_H__
61 : w(1), x(0), y(0), z(0)
68 : w(fW), x(fX), y(fY), z(fZ)
74 this->FromRotationMatrix(rot);
79 this->FromAngleAxis(rfAngle, rkAxis);
84 this->FromAxes(xaxis, yaxis, zaxis);
89 this->FromAxes(akAxis);
94 memcpy(&w, valptr,
sizeof(
Real)*4);
108 inline Real operator [] (
const size_t i )
const
116 inline Real& operator [] (
const size_t i )
144 ToAngleAxis ( rAngle, rkAxis );
188 return (rhs.
x == x) && (rhs.
y == y) &&
189 (rhs.
z == z) && (rhs.
w == w);
256 Real d = this->Dot(other);
257 return 1 - d*d < tolerance;
273 const Quaternion& rkQ,
bool shortestPath =
false);
291 const Quaternion& rkQ,
bool shortestPath =
false);
308 const Quaternion& rkQ,
bool shortestPath =
false);
322 return Math::isNaN(x) || Math::isNaN(y) || Math::isNaN(z) || Math::isNaN(w);
331 o <<
"Quaternion(" << q.w <<
", " << q.x <<
", " << q.y <<
", " << q.z <<
")";
Wrapper class which indicates a given angle value is in Degrees.
A 3x3 matrix which can represent rotations around axes.
Implementation of a Quaternion, i.e.
bool orientationEquals(const Quaternion &other, Real tolerance=1e-3) const
Compare two quaternions which are assumed to be used as orientations.
Quaternion(const Vector3 &xaxis, const Vector3 &yaxis, const Vector3 &zaxis)
Construct a quaternion from 3 orthonormal local axes.
Radian getYaw(bool reprojectAxis=true) const
Calculate the local yaw element of this quaternion.
static Quaternion nlerp(Real fT, const Quaternion &rkP, const Quaternion &rkQ, bool shortestPath=false)
Performs Normalised linear interpolation between two quaternions, and returns the result.
Quaternion(Real *valptr)
Construct a quaternion from 4 manual w/x/y/z values.
static Quaternion SlerpExtraSpins(Real fT, const Quaternion &rkP, const Quaternion &rkQ, int iExtraSpins)
void ToAngleAxis(Degree &dAngle, Vector3 &rkAxis) const
void FromAxes(const Vector3 &xAxis, const Vector3 &yAxis, const Vector3 &zAxis)
Vector3 zAxis(void) const
Returns the Z orthonormal axis defining the quaternion.
Quaternion(const Vector3 *akAxis)
Construct a quaternion from 3 orthonormal local axes.
static const Quaternion IDENTITY
static const Quaternion ZERO
void swap(Quaternion &other)
Exchange the contents of this quaternion with another.
Vector3 xAxis(void) const
Returns the X orthonormal axis defining the quaternion.
static Quaternion Squad(Real fT, const Quaternion &rkP, const Quaternion &rkA, const Quaternion &rkB, const Quaternion &rkQ, bool shortestPath=false)
Spherical quadratic interpolation.
void ToRotationMatrix(Matrix3 &kRot) const
static const Real msEpsilon
Cutoff for sine near zero.
void FromAxes(const Vector3 *akAxis)
Constructs the quaternion using 3 axes, the axes are assumed to be orthonormal.
Quaternion(const Radian &rfAngle, const Vector3 &rkAxis)
Construct a quaternion from an angle/axis.
void ToAngleAxis(Radian &rfAngle, Vector3 &rkAxis) const
Quaternion UnitInverse() const
Apply to non-zero quaternion.
Real * ptr()
Pointer accessor for direct copying.
static void Intermediate(const Quaternion &rkQ0, const Quaternion &rkQ1, const Quaternion &rkQ2, Quaternion &rka, Quaternion &rkB)
Setup for spherical quadratic interpolation.
Quaternion(Real fW, Real fX, Real fY, Real fZ)
Construct from an explicit list of values.
Real Dot(const Quaternion &rkQ) const
Returns the dot product of the quaternion.
Vector3 yAxis(void) const
Returns the Y orthonormal axis defining the quaternion.
bool equals(const Quaternion &rhs, const Radian &tolerance) const
Equality with tolerance (tolerance is max angle difference)
static Quaternion Slerp(Real fT, const Quaternion &rkP, const Quaternion &rkQ, bool shortestPath=false)
Performs Spherical linear interpolation between two quaternions, and returns the result.
Quaternion()
Default constructor, initializes to identity rotation (aka 0°)
void FromAngleAxis(const Radian &rfAngle, const Vector3 &rkAxis)
Setups the quaternion using the supplied vector, and "roll" around that vector by the specified radia...
bool isNaN() const
Check whether this quaternion contains valid values.
Quaternion(const Matrix3 &rot)
Construct a quaternion from a rotation matrix.
void ToAxes(Vector3 &xAxis, Vector3 &yAxis, Vector3 &zAxis) const
Radian getRoll(bool reprojectAxis=true) const
Calculate the local roll element of this quaternion.
Quaternion Inverse() const
Radian getPitch(bool reprojectAxis=true) const
Calculate the local pitch element of this quaternion.
void FromRotationMatrix(const Matrix3 &kRot)
void ToAxes(Vector3 *akAxis) const
Gets the 3 orthonormal axes defining the quaternion.
const Real * ptr() const
Pointer accessor for direct copying.
Quaternion Exp() const
Apply to unit-length quaternion.
Real normalise(void)
Normalises this quaternion, and returns the previous length.
Wrapper class which indicates a given angle value is in Radians.
Standard 3-dimensional vector.
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
float Real
Software floating point type.
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.