00001 #ifndef _MERCURYTYPES_H
00002 #define _MERCURYTYPES_H
00003
00004 #include "global.h"
00005 #include "MercuryMath.h"
00006 #include "MercuryMatrix.h"
00007
00009 class MercuryPoint
00010 {
00011 public:
00012 MercuryPoint() : x(0), y(0), z(0) { };
00013 MercuryPoint( float ix, float iy, float iz ) : x(ix), y(iy), z(iz) { };
00014 MercuryPoint( const float * in ) : x(in[0]), y(in[1]), z(in[2]) { };
00015
00017 operator float* () { return &x; }
00019 operator const float* () const { return &x; }
00020
00022 inline const float GetX() const { return x; }
00024 inline const float GetY() const { return y; }
00026 inline const float GetZ() const { return z; }
00028 inline bool SetX(const float ix) { if (ix == x) { return false; } x = ix; return true; }
00030 inline bool SetY(const float iy) { if (iy == y) { return false; } y = iy; return true; }
00032 inline bool SetZ(const float iz) { if (iz == z) { return false; } z = iz; return true; }
00034 inline void Clear() { x = 0; y = 0; z = 0; }
00035
00036
00037 float & operator[] ( const int rhs );
00038 const float operator[] ( const int rhs ) const;
00039
00041 void NormalizeSelf();
00043 const MercuryPoint Normalize() const;
00045 float Magnitude() const;
00046
00047 float GetBiggestElement() const { if( x > y ) return (x>z)?x:z; else return (y>z)?y:z; }
00048
00050 inline void ConvertToVector3( float* out ) const { out[0] = x; out[1] = y; out[2] = z; }
00052 inline void ConvertToVector4( float* out ) const { out[0] = x; out[1] = y; out[2] = z; out[3] = 0; }
00054 inline void ConvertToIVector4( float* out ) const { out[0] = -x; out[1] = -y; out[2] = -z; out[3] = 0; }
00055
00057 MercuryPoint operator*(const MercuryPoint& p) const;
00059 MercuryPoint operator/(const MercuryPoint& p) const;
00060
00061 inline MercuryPoint& operator += ( const MercuryPoint& other ) { x+=other.x; y+=other.y; z+=other.z; return *this; }
00062 inline MercuryPoint& operator -= ( const MercuryPoint& other ) { x-=other.x; y-=other.y; z-=other.z; return *this; }
00063 inline MercuryPoint& operator *= ( float f ) { x*=f; y*=f; z*=f; return *this; }
00064 inline MercuryPoint& operator /= ( float f ) { x/=f; y/=f; z/=f; return *this; }
00065
00066 inline MercuryPoint operator + ( const MercuryPoint& other ) const { return MercuryPoint( x+other.x, y+other.y, z+other.z ); }
00067 inline MercuryPoint operator - ( const MercuryPoint& other ) const { return MercuryPoint( x-other.x, y-other.y, z-other.z ); }
00068 inline MercuryPoint operator * ( float f ) const { return MercuryPoint( x*f, y*f, z*f ); }
00069 inline MercuryPoint operator / ( float f ) const { return MercuryPoint( x/f, y/f, z/f ); }
00070
00071 friend MercuryPoint operator * ( float f, const MercuryPoint& other ) { return other*f; }
00072
00073 bool operator==(const MercuryPoint& p) const;
00074 inline bool operator!=(const MercuryPoint& p) const { return !(*this == p); }
00075
00076 bool operator==(const float f) const;
00077 inline bool operator!=(const float f) const { return !(*this == f); }
00078
00080 MercuryPoint CrossProduct(const MercuryPoint& p) const;
00081
00082 float x;
00083 float y;
00084 float z;
00085 };
00086
00088 extern const MercuryPoint gpZero;
00090 extern const MercuryPoint gpOne;
00091
00092
00093
00095 MercuryPoint Rotate2DPoint( float fAngle, MercuryPoint pIn );
00096
00098 void AngleMatrix (const MercuryPoint & angles, MercuryMatrix & mat );
00100 void TranslationMatrix( const MercuryPoint & position, MercuryMatrix & mat );
00102 void R_ConcatTransforms3 ( MercuryMatrix in1, MercuryMatrix in2, MercuryMatrix & out );
00103
00105 void VectorIRotate (const MercuryPoint & in1, MercuryMatrix &in2, MercuryPoint & out);
00106 void VectorRotate (const MercuryPoint & in1, const MercuryMatrix &in2, MercuryPoint & out);
00107
00109 void VectorMultiply( MercuryMatrix &m, const MercuryPoint &p, MercuryPoint &out );
00110
00112 void InvertMatrix( MercuryMatrix &in, MercuryMatrix & out );
00113
00115 class MQuaternion {
00116 public:
00117
00118 float w,x,y,z;
00119 MQuaternion() : w(0), x(0), y(0), z(0) { };
00120 MQuaternion(float W, float X, float Y, float Z) : w(W), x(X), y(Y), z(Z) { };
00121 MQuaternion(float* wxyz) : w(wxyz[0]), x(wxyz[1]), y(wxyz[2]), z(wxyz[3]) { };
00122 MQuaternion(const MercuryPoint& p) : w(0), x(p.GetX()), y(p.GetY()), z(p.GetZ()) {};
00123
00125 void SetEuler(const MercuryPoint& angles);
00126
00128 void CreateFromAxisAngle(const MercuryPoint& p, const float radians);
00129
00131 float & operator[] ( const int rhs );
00132 const float & operator[] ( const int rhs ) const;
00133
00135 float magnitude() const;
00137 MQuaternion normalize() const;
00139 MQuaternion conjugate() const;
00141 MQuaternion reciprocal() const;
00143 MQuaternion rotateAbout(const MQuaternion &spinAxis) const;
00145 void toMatrix( MercuryMatrix & mat ) const;
00147 void toMatrix4( MercuryMatrix & mat ) const;
00149 MercuryPoint ToPoint() { return MercuryPoint( x,y,z ); }
00150
00151
00152
00153
00154
00155 MQuaternion operator + (const MQuaternion &rhs) const;
00156 MQuaternion operator - (const MQuaternion &rhs) const;
00157 MQuaternion operator * (const MQuaternion &rhs) const;
00158 MQuaternion& operator = (const MQuaternion &rhs);
00159 MQuaternion& operator += (const MQuaternion &rhs);
00160 MQuaternion& operator -= (const MQuaternion &rhs);
00161 MQuaternion& operator *= (const MQuaternion &rhs);
00162 MQuaternion operator * (const float &rhs) const;
00163 MQuaternion operator / (const float &rhs) const;
00164 MQuaternion& operator *= (const float &rhs);
00165 MQuaternion& operator /= (const float &rhs);
00166 } M_ALIGN(32);
00167
00169 float innerProduct( const MQuaternion &a, const MQuaternion &b );
00170
00172 MercuryPoint outerProduct( const MQuaternion &a, const MQuaternion &b );
00173
00175 MQuaternion evenProduct(const MQuaternion &a, const MQuaternion &b );
00176
00178 MercuryPoint oddProduct( const MQuaternion &a, const MQuaternion &b );
00179
00181 MQuaternion SLERP( const MQuaternion &a, const MQuaternion &b, float t );
00182
00183 #endif
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212