FMath/FMQuaternion.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2005-2007 Feeling Software Inc.
00003     Portions of the code are:
00004     Copyright (C) 2005-2007 Sony Computer Entertainment America
00005     
00006     MIT License: http://www.opensource.org/licenses/mit-license.php
00007 */
00008 
00014 #ifndef _FM_QUATERNION_H_
00015 #define _FM_QUATERNION_H_
00016 
00024 class FCOLLADA_EXPORT FMQuaternion
00025 {
00026 public:
00027     float x;    
00028     float y;    
00029     float z;    
00030     float w;    
00032 #ifndef _DEBUG
00033 
00035     FMQuaternion() {}
00036 #else
00037     FMQuaternion() { x = 123456789.0f; y = 123456789.0f; z = 123456789.0f; w = 123456789.0f; }
00038 #endif 
00039 
00045     FMQuaternion(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; }
00046 
00049     FMQuaternion(const float* values);
00050     FMQuaternion(const double* values); 
00055     FMQuaternion(const FMVector3& axis, float angle);
00056 
00059     inline operator float*() { return &x; }
00060     inline operator const float*() const { return &x; } 
00068     inline FMQuaternion& operator =(const float* v) { x = *v; y = *(v + 1); z = *(v + 2); w = *(v + 3); return *this; }
00069 
00072     inline float LengthSquared() const { return x * x + y * y + z * z + w * w; }
00073 
00076     inline float Length() const { return sqrtf(x * x + y * y + z * z + w * w); }
00077 
00079     inline void NormalizeIt() { float l = Length(); if (l > 0.0f) { x /= l; y /= l; z /= l; w /= l; }}
00080 
00083     inline FMQuaternion Normalize() const { float l = Length(); return FMQuaternion(x / l, y / l, z / l, w / l); }
00084 
00089     FMQuaternion operator*(const FMQuaternion& q) const;
00090 
00096     FMVector3 operator*(const FMVector3& v) const;
00097 
00100     inline FMQuaternion operator~() const { return FMQuaternion(-x, -y, -z, w); }
00101 
00106     inline FMQuaternion& operator*=(const FMQuaternion& q) { return (*this) = (*this) * q; }
00107 
00112     inline FMQuaternion& operator=(const FMQuaternion& q) { x = q.x; y = q.y; z = q.z; w = q.w; return (*this); }
00113 
00118     FMQuaternion slerp(const FMQuaternion& other, float time) const;
00119 
00126     FMVector3 ToEuler(FMVector3* previousAngles = NULL) const;
00127 
00131     void ToAngleAxis(FMVector3& axis, float& angle) const;
00132 
00135     FMMatrix44 ToMatrix() const;
00136 
00140     void SetToMatrix(FMMatrix44& m) const;
00141 
00147     static FMQuaternion EulerRotationQuaternion(float x, float y, float z);
00148 
00151     static FMQuaternion MatrixRotationQuaternion(const FMMatrix44& mat);
00152 
00153 public:
00154     static const FMQuaternion Zero; 
00159     static const FMQuaternion Identity;
00160 };
00161 
00166 inline bool IsEquivalent(const FMQuaternion& a, const FMQuaternion& b)
00167 {
00168     return IsEquivalent(a.x, b.x) && IsEquivalent(a.y, b.y) && IsEquivalent(a.z, b.z) && IsEquivalent(a.w, b.w);
00169 }
00170 
00171 #endif // _FM_QUATERNION_H_

Generated on Thu Feb 14 16:58:35 2008 for FCollada by  doxygen 1.4.6-NO