00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #ifndef __Matrix3_H__ 00026 #define __Matrix3_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 00030 #include "OgreVector3.h" 00031 00032 // NB All code adapted from Wild Magic 0.2 Matrix math (free source code) 00033 // http://www.magic-software.com 00034 00035 // NOTE. The (x,y,z) coordinate system is assumed to be right-handed. 00036 // Coordinate axis rotation matrices are of the form 00037 // RX = 1 0 0 00038 // 0 cos(t) -sin(t) 00039 // 0 sin(t) cos(t) 00040 // where t > 0 indicates a counterclockwise rotation in the yz-plane 00041 // RY = cos(t) 0 sin(t) 00042 // 0 1 0 00043 // -sin(t) 0 cos(t) 00044 // where t > 0 indicates a counterclockwise rotation in the zx-plane 00045 // RZ = cos(t) -sin(t) 0 00046 // sin(t) cos(t) 0 00047 // 0 0 1 00048 // where t > 0 indicates a counterclockwise rotation in the xy-plane. 00049 00050 namespace Ogre 00051 { 00059 class _OgreExport Matrix3 00060 { 00061 public: 00062 // construction 00063 Matrix3 (); 00064 Matrix3 (const Real arr[3][3]); 00065 Matrix3 (const Matrix3& rkMatrix); 00066 Matrix3 (Real fEntry00, Real fEntry01, Real fEntry02, 00067 Real fEntry10, Real fEntry11, Real fEntry12, 00068 Real fEntry20, Real fEntry21, Real fEntry22); 00069 00070 // member access, allows use of construct mat[r][c] 00071 Real* operator[] (int iRow) const; 00072 operator Real* (); 00073 Vector3 GetColumn (int iCol) const; 00074 void SetColumn(int iCol, const Vector3& vec); 00075 void FromAxes(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis); 00076 00077 // assignment and comparison 00078 Matrix3& operator= (const Matrix3& rkMatrix); 00079 bool operator== (const Matrix3& rkMatrix) const; 00080 bool operator!= (const Matrix3& rkMatrix) const; 00081 00082 // arithmetic operations 00083 Matrix3 operator+ (const Matrix3& rkMatrix) const; 00084 Matrix3 operator- (const Matrix3& rkMatrix) const; 00085 Matrix3 operator* (const Matrix3& rkMatrix) const; 00086 Matrix3 operator- () const; 00087 00088 // matrix * vector [3x3 * 3x1 = 3x1] 00089 Vector3 operator* (const Vector3& rkVector) const; 00090 00091 // vector * matrix [1x3 * 3x3 = 1x3] 00092 friend Vector3 operator* (const Vector3& rkVector, 00093 const Matrix3& rkMatrix); 00094 00095 // matrix * scalar 00096 Matrix3 operator* (Real fScalar) const; 00097 00098 // scalar * matrix 00099 friend Matrix3 operator* (Real fScalar, const Matrix3& rkMatrix); 00100 00101 // utilities 00102 Matrix3 Transpose () const; 00103 bool Inverse (Matrix3& rkInverse, Real fTolerance = 1e-06) const; 00104 Matrix3 Inverse (Real fTolerance = 1e-06) const; 00105 Real Determinant () const; 00106 00107 // singular value decomposition 00108 void SingularValueDecomposition (Matrix3& rkL, Vector3& rkS, 00109 Matrix3& rkR) const; 00110 void SingularValueComposition (const Matrix3& rkL, 00111 const Vector3& rkS, const Matrix3& rkR); 00112 00113 // Gram-Schmidt orthonormalization (applied to columns of rotation matrix) 00114 void Orthonormalize (); 00115 00116 // orthogonal Q, diagonal D, upper triangular U stored as (u01,u02,u12) 00117 void QDUDecomposition (Matrix3& rkQ, Vector3& rkD, 00118 Vector3& rkU) const; 00119 00120 Real SpectralNorm () const; 00121 00122 // matrix must be orthonormal 00123 void ToAxisAngle (Vector3& rkAxis, Real& rfRadians) const; 00124 void FromAxisAngle (const Vector3& rkAxis, Real fRadians); 00125 00126 // The matrix must be orthonormal. The decomposition is yaw*pitch*roll 00127 // where yaw is rotation about the Up vector, pitch is rotation about the 00128 // Right axis, and roll is rotation about the Direction axis. 00129 bool ToEulerAnglesXYZ (float& rfYAngle, float& rfPAngle, 00130 float& rfRAngle) const; 00131 bool ToEulerAnglesXZY (float& rfYAngle, float& rfPAngle, 00132 float& rfRAngle) const; 00133 bool ToEulerAnglesYXZ (float& rfYAngle, float& rfPAngle, 00134 float& rfRAngle) const; 00135 bool ToEulerAnglesYZX (float& rfYAngle, float& rfPAngle, 00136 float& rfRAngle) const; 00137 bool ToEulerAnglesZXY (float& rfYAngle, float& rfPAngle, 00138 float& rfRAngle) const; 00139 bool ToEulerAnglesZYX (float& rfYAngle, float& rfPAngle, 00140 float& rfRAngle) const; 00141 void FromEulerAnglesXYZ (float fYAngle, float fPAngle, float fRAngle); 00142 void FromEulerAnglesXZY (float fYAngle, float fPAngle, float fRAngle); 00143 void FromEulerAnglesYXZ (float fYAngle, float fPAngle, float fRAngle); 00144 void FromEulerAnglesYZX (float fYAngle, float fPAngle, float fRAngle); 00145 void FromEulerAnglesZXY (float fYAngle, float fPAngle, float fRAngle); 00146 void FromEulerAnglesZYX (float fYAngle, float fPAngle, float fRAngle); 00147 00148 // eigensolver, matrix must be symmetric 00149 void EigenSolveSymmetric (Real afEigenvalue[3], 00150 Vector3 akEigenvector[3]) const; 00151 00152 static void TensorProduct (const Vector3& rkU, const Vector3& rkV, 00153 Matrix3& rkProduct); 00154 00155 static const Real EPSILON; 00156 static const Matrix3 ZERO; 00157 static const Matrix3 IDENTITY; 00158 00159 protected: 00160 // support for eigensolver 00161 void Tridiagonal (Real afDiag[3], Real afSubDiag[3]); 00162 bool QLAlgorithm (Real afDiag[3], Real afSubDiag[3]); 00163 00164 // support for singular value decomposition 00165 static const Real ms_fSvdEpsilon; 00166 static const int ms_iSvdMaxIterations; 00167 static void Bidiagonalize (Matrix3& kA, Matrix3& kL, 00168 Matrix3& kR); 00169 static void GolubKahanStep (Matrix3& kA, Matrix3& kL, 00170 Matrix3& kR); 00171 00172 // support for spectral norm 00173 static Real MaxCubicRoot (Real afCoeff[3]); 00174 00175 Real m[3][3]; 00176 00177 // for faster access 00178 friend class Matrix4; 00179 }; 00180 } 00181 #endif
Copyright © 2002 by The OGRE Team