Lumino.Math
|
00001 00002 #ifndef LUMINO_MATH_MATRIX_H 00003 #define LUMINO_MATH_MATRIX_H 00004 00005 #include <stdio.h> 00006 #include <string.h> 00007 #include "Common.h" 00008 #include "Vector4.h" 00009 00010 namespace Lumino 00011 { 00012 class Vector3; 00013 class Quaternion; 00014 class SQTTransform; 00015 class Plane; 00016 00037 class LUMINO_EXPORT Matrix 00038 { 00039 public: 00040 00041 union 00042 { 00043 struct 00044 { 00045 float M11, M12, M13, M14; 00046 float M21, M22, M23, M24; 00047 float M31, M32, M33, M34; 00048 float M41, M42, M43, M44; 00049 }; 00050 float M[4][4]; 00051 float m[16]; 00052 }; 00053 00054 public: 00055 00056 static const Matrix Identity; 00057 00058 public: 00059 00063 Matrix(); 00064 00068 Matrix( float m11, float m12, float m13, float m14, 00069 float m21, float m22, float m23, float m24, 00070 float m31, float m32, float m33, float m34, 00071 float m41, float m42, float m43, float m44); 00072 00076 Matrix(const Vector4& row1, const Vector4& row2, const Vector4& row3, const Vector4& row4); 00077 00081 Matrix(const SQTTransform& transform); 00082 00083 public: 00084 00088 void Set( float m11, float m12, float m13, float m14, 00089 float m21, float m22, float m23, float m24, 00090 float m31, float m32, float m33, float m34, 00091 float m41, float m42, float m43, float m44); 00092 00097 bool IsIdentity() const; 00098 00102 const Vector3& GetRight() const; 00103 00107 const Vector3& GetUp() const; 00108 00112 const Vector3& GetFront() const; 00113 00117 const Vector3& GetPosition() const; 00118 00122 void SetRow(int index, const Vector4& row); 00123 00127 const Vector4& GetRow(int index) const; 00128 00135 void Translate(float x, float y, float z); 00136 00141 void Translate(const Vector3& vec); 00142 00147 void RotateX(float r); 00148 00153 void RotateY(float r); 00154 00159 void RotateZ(float r); 00160 00169 void RotateEulerAngles(float x, float y, float z, RotationOrder order = RotationOrder_ZXY); 00170 00177 void RotateEulerAngles(const Vector3& angles, RotationOrder order = RotationOrder_ZXY); 00178 00185 void RotateAxis(const Vector3& axis, float r); 00186 00191 void RotateQuaternion(const Quaternion& qua); 00192 00199 void Scale(float x, float y, float z); 00200 00205 void Scale(const Vector3& vec); 00206 00211 void Scale(float xyz); 00212 00216 void Inverse(); 00217 00221 void Transpose(); 00222 00230 void Decompose(Vector3* scale, Quaternion* rotation, Vector3* translation) const; 00231 00239 void DecomposeMatrices(Matrix* scale, Matrix* rotation, Matrix* translation) const; 00240 00250 Vector3 ToEulerAngles(RotationOrder order = RotationOrder_ZXY, bool* locked = NULL) const; 00251 00257 Matrix GetRotationMatrix() const; 00258 00262 bool IsNaNOrInf() const; 00263 00270 void Print(const char* format = NULL, FILE* stream = NULL) const; 00271 00272 public: 00273 00280 static Matrix Multiply(const Matrix& mat1, const Matrix& mat2); 00281 00289 static Matrix Translation(float x, float y, float z); 00290 00296 static Matrix Translation(const Vector3& vec); 00297 00303 static Matrix RotationX(float r); 00304 00310 static Matrix RotationY(float r); 00311 00317 static Matrix RotationZ(float r); 00318 00326 static Matrix RotationAxis(const Vector3& axis, float r); 00327 00333 static Matrix RotationQuaternion(const Quaternion& qua); 00334 00343 static Matrix RotationEulerAngles(float x, float y, float z, RotationOrder order = RotationOrder_ZXY); 00344 00351 static Matrix RotationEulerAngles(const Vector3& angles, RotationOrder order = RotationOrder_ZXY); 00352 00363 static Matrix RotationYawPitchRoll(float yaw, float pitch, float roll); 00364 00372 static Matrix Scaling(float x, float y, float z); 00373 00379 static Matrix Scaling(const Vector3& vec); 00380 00386 static Matrix Scaling(float xyz); 00387 00393 static Matrix Inverse(const Matrix& mat); 00394 00400 static Matrix Transpose(const Matrix& mat); 00401 00409 static Matrix Reflection(const Plane& plane); 00410 00418 static Matrix LookAtLH(const Vector3& position, const Vector3& lookAt, const Vector3& up); 00419 00427 static Matrix LookAtRH(const Vector3& position, const Vector3& lookAt, const Vector3& up); 00428 00437 static Matrix PerspectiveFovLH(float fovY, float aspect, float near, float far); 00438 00447 static Matrix PerspectiveFovRH(float fovY, float aspect, float near, float far); 00448 00457 static Matrix OrthoLH(float width, float height, float near, float far); 00458 00467 static Matrix OrthoRH(float width, float height, float near, float far); 00468 00477 static Matrix AffineTransformation(const Vector3& scaling, const Vector3& rotationCenter, const Quaternion& rotation, const Vector3& translation); 00478 00479 public: 00480 00481 Matrix& operator *= (const Matrix& mat); 00482 00483 friend Matrix operator * (const Matrix& mat1, const Matrix& mat2); 00484 friend Matrix operator * (const Matrix& mat1, float v); 00485 00486 bool operator == (const Matrix& mat) const; 00487 bool operator != (const Matrix& mat) const; 00488 00489 00490 #ifdef LN_MATH_MATRIX_EXTENSION 00491 LN_MATH_MATRIX_EXTENSION 00492 #endif 00493 }; 00494 00495 } // namespace Lumino 00496 00497 #include "Matrix.inl" 00498 00499 #endif // LUMINO_MATH_MATRIX_H