nux-0.9.48
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef MATRIX3_H 00024 #define MATRIX3_H 00025 00026 00027 #include "Vector3.h" 00028 00029 namespace nux 00030 { 00031 00032 template<typename T> 00033 class Matrix3x3 00034 { 00035 public: 00036 Matrix3x3<T>(); 00037 ~Matrix3x3(); 00038 00039 Matrix3x3 (const Matrix3x3<T>&); 00040 Matrix3x3<T> ( 00041 T a00, T a01, T a02, 00042 T a10, T a11, T a12, 00043 T a20, T a21, T a22); 00044 00045 Matrix3x3<T>& operator = (const Matrix3x3<T>&); 00046 t_bool operator == (const Matrix3x3<T>&); 00047 Matrix3x3<T> operator * (const Matrix3x3<T>&) const; 00048 Matrix3x3<T> operator + (const Matrix3x3<T>&) const; 00049 Matrix3x3<T> operator - (const Matrix3x3<T>&) const; 00050 Matrix3x3<T>& operator *= (const Matrix3x3<T>&) const; 00051 Matrix3x3<T>& operator += (const Matrix3x3<T>&) const; 00052 Matrix3x3<T>& operator -= (const Matrix3x3<T>&) const; 00053 00054 Matrix3x3<T> operator * (const T &) const; 00055 Matrix3x3<T> operator / (const T &) const; 00056 Matrix3x3<T>& operator *= (const T &) const; 00057 Matrix3x3<T>& operator /= (const T &) const; 00058 00059 Vec3<T> operator * (const Vec3<T>&) const; 00060 Matrix3x3<T> operator - (); 00061 00062 // Get the (i, j) element of the current matrix. 00063 T &operator() (unsigned int i, unsigned int j); 00064 T operator () (unsigned int i, unsigned int j) const; 00065 00066 T Determinant() const ; 00067 void Inverse(); 00068 Matrix3x3<T> GetInverse() const; 00069 00070 //Matrix2x2<T> GetUpper2x2() const; 00071 00072 void Zero(); 00073 void Identity(); 00074 00075 static Matrix3x3<T> IDENTITY(); 00076 static Matrix3x3<T> ZERO(); 00077 T m[3][3]; 00078 }; 00079 00080 00081 /***************************************************************************************\ 00082 Function: Matrix3x3<T>::Matrix3x3 00083 00084 Description: Constructor. Initialize the matrix to identity. 00085 00086 Parameters: None. 00087 00088 Return Value: None. 00089 00090 Comments: None. 00091 \***************************************************************************************/ 00092 template <typename T> 00093 Matrix3x3<T>::Matrix3x3() 00094 { 00095 Identity(); 00096 } 00097 00098 /***************************************************************************************\ 00099 Function: Matrix3x3<T>::~Matrix3x3 00100 00101 Description: Destructor. 00102 00103 Parameters: None. 00104 00105 Return Value: None. 00106 00107 Comments: None. 00108 \***************************************************************************************/ 00109 template <typename T> 00110 Matrix3x3<T>::~Matrix3x3() 00111 { 00112 00113 } 00114 00115 /***************************************************************************************\ 00116 Function: Matrix3x3<T>::Matrix3x3 00117 00118 Description: None. 00119 00120 Parameters: - M 00121 00122 Return Value: None. 00123 00124 Comments: None. 00125 \***************************************************************************************/ 00126 template <typename T> 00127 Matrix3x3<T>::Matrix3x3 (const Matrix3x3<T>& M) 00128 { 00129 m[0][0] = M.m[0][0]; 00130 m[0][1] = M.m[0][1]; 00131 m[0][2] = M.m[0][2]; 00132 m[1][0] = M.m[1][0]; 00133 m[1][1] = M.m[1][1]; 00134 m[1][2] = M.m[1][2]; 00135 m[2][0] = M.m[2][0]; 00136 m[2][1] = M.m[2][1]; 00137 m[2][2] = M.m[2][2]; 00138 } 00139 00140 /***************************************************************************************\ 00141 Function: Matrix3x3<T>::Matrix3x3 00142 00143 Description: None. 00144 00145 Parameters: T a00, T a01, T a02, 00146 T a10, T a11, T a12, 00147 T a20, T a21, T a22 00148 00149 Return Value: None. 00150 00151 Comments: None. 00152 \***************************************************************************************/ 00153 template<typename T> 00154 Matrix3x3<T>::Matrix3x3 ( 00155 T a00, T a01, T a02, 00156 T a10, T a11, T a12, 00157 T a20, T a21, T a22) 00158 { 00159 m[0][0] = a00; 00160 m[0][1] = a01; 00161 m[0][2] = a02; 00162 m[1][0] = a10; 00163 m[1][1] = a11; 00164 m[1][2] = a12; 00165 m[2][0] = a20; 00166 m[2][1] = a21; 00167 m[2][2] = a22; 00168 } 00169 00170 /***************************************************************************************\ 00171 Function: Matrix3x3<T>::operator = 00172 00173 Description: None. 00174 00175 Parameters: - M 00176 00177 Return Value: Matrix3x3<T>. 00178 00179 Comments: None. 00180 \***************************************************************************************/ 00181 template <typename T> 00182 Matrix3x3<T>& Matrix3x3<T>::operator = (const Matrix3x3<T>& M) 00183 { 00184 m[0][0] = M.m[0][0]; 00185 m[0][1] = M.m[0][1]; 00186 m[0][2] = M.m[0][2]; 00187 m[1][0] = M.m[1][0]; 00188 m[1][1] = M.m[1][1]; 00189 m[1][2] = M.m[1][2]; 00190 m[2][0] = M.m[2][0]; 00191 m[2][1] = M.m[2][1]; 00192 m[2][2] = M.m[2][2]; 00193 00194 return (*this); 00195 } 00196 00197 template <typename T> 00198 t_bool Matrix3x3<T>::operator == (const Matrix3x3<T>& M) 00199 { 00200 for (int i = 0; i < 3; i++) 00201 for (int j = 0; j < 3; j++) 00202 { 00203 if (m[i][j] != M.m[i][j]) 00204 return false; 00205 } 00206 00207 return true; 00208 } 00209 00210 /***************************************************************************************\ 00211 Function: Matrix3x3<T>::operator * 00212 00213 Description: Multiply by matrix iM. 00214 00215 Parameters: - iM 00216 00217 Return Value: Matrix3x3<T>. 00218 00219 Comments: None. 00220 \***************************************************************************************/ 00221 template <typename T> 00222 Matrix3x3<T> Matrix3x3<T>::operator * (const Matrix3x3<T>& iM) const 00223 { 00224 Matrix3x3<T> oM; 00225 00226 oM.m[0][0] = m[0][0] * iM.m[0][0] + m[0][1] * iM.m[1][0] + m[0][2] * iM.m[2][0]; 00227 oM.m[1][0] = m[1][0] * iM.m[0][0] + m[1][1] * iM.m[1][0] + m[1][2] * iM.m[2][0]; 00228 oM.m[2][0] = m[2][0] * iM.m[0][0] + m[2][1] * iM.m[1][0] + m[2][2] * iM.m[2][0]; 00229 00230 oM.m[0][1] = m[0][0] * iM.m[0][1] + m[0][1] * iM.m[1][1] + m[0][2] * iM.m[2][1]; 00231 oM.m[1][1] = m[1][0] * iM.m[0][1] + m[1][1] * iM.m[1][1] + m[1][2] * iM.m[2][1]; 00232 oM.m[2][1] = m[2][0] * iM.m[0][1] + m[2][1] * iM.m[1][1] + m[2][2] * iM.m[2][1]; 00233 00234 oM.m[0][2] = m[0][0] * iM.m[0][2] + m[0][1] * iM.m[1][2] + m[0][2] * iM.m[2][2]; 00235 oM.m[1][2] = m[1][0] * iM.m[0][2] + m[1][1] * iM.m[1][2] + m[1][2] * iM.m[2][2]; 00236 oM.m[2][2] = m[2][0] * iM.m[0][2] + m[2][1] * iM.m[1][2] + m[2][2] * iM.m[2][2]; 00237 00238 return oM; 00239 } 00240 00241 /***************************************************************************************\ 00242 Function: Matrix3x3<T>::operator + 00243 00244 Description: Add matrix iM. 00245 00246 Parameters: - iM 00247 00248 Return Value: Matrix3x3<T>. 00249 00250 Comments: None. 00251 \***************************************************************************************/ 00252 template <typename T> 00253 Matrix3x3<T> Matrix3x3<T>::operator+ (const Matrix3x3<T>& iM) const 00254 { 00255 Matrix3x3<T> oM; 00256 00257 oM.m[0][0] = m[0][0] + iM.m[0][0]; 00258 oM.m[0][1] = m[0][1] + iM.m[0][1]; 00259 oM.m[0][2] = m[0][2] + iM.m[0][2]; 00260 oM.m[1][0] = m[1][0] + iM.m[1][0]; 00261 oM.m[1][1] = m[1][1] + iM.m[1][1]; 00262 oM.m[1][2] = m[1][2] + iM.m[1][2]; 00263 oM.m[2][0] = m[2][0] + iM.m[2][0]; 00264 oM.m[2][1] = m[2][1] + iM.m[2][1]; 00265 oM.m[2][2] = m[2][2] + iM.m[2][2]; 00266 00267 return oM; 00268 } 00269 00270 /***************************************************************************************\ 00271 Function: Matrix3x3<T>::operator - 00272 00273 Description: Substract matrix iM. 00274 00275 Parameters: - iM 00276 00277 Return Value: Matrix3x3<T>. 00278 00279 Comments: None. 00280 \***************************************************************************************/ 00281 template <typename T> 00282 Matrix3x3<T> Matrix3x3<T>::operator- (const Matrix3x3<T>& iM) const 00283 { 00284 Matrix3x3<T> oM; 00285 00286 oM.m[0][0] = m[0][0] - iM.m[0][0]; 00287 oM.m[0][1] = m[0][1] - iM.m[0][1]; 00288 oM.m[0][2] = m[0][2] - iM.m[0][2]; 00289 oM.m[1][0] = m[1][0] - iM.m[1][0]; 00290 oM.m[1][1] = m[1][1] - iM.m[1][1]; 00291 oM.m[1][2] = m[1][2] - iM.m[1][2]; 00292 oM.m[2][0] = m[2][0] - iM.m[2][0]; 00293 oM.m[2][1] = m[2][1] - iM.m[2][1]; 00294 oM.m[2][2] = m[2][2] - iM.m[2][2]; 00295 00296 return oM; 00297 } 00298 00299 00300 00301 00302 00303 00304 00305 /***************************************************************************************\ 00306 Function: Matrix3x3<T>::operator *= 00307 00308 Description: Multiply by matrix iM. 00309 00310 Parameters: - iM 00311 00312 Return Value: Matrix3x3<T>. 00313 00314 Comments: None. 00315 \***************************************************************************************/ 00316 template <typename T> 00317 Matrix3x3<T>& Matrix3x3<T>::operator *= (const Matrix3x3<T>& iM) const 00318 { 00319 Matrix3x3<T> oM; 00320 00321 oM.m[0][0] = m[0][0] * iM.m[0][0] + m[0][1] * iM.m[1][0] + m[0][2] * iM.m[2][0]; 00322 oM.m[1][0] = m[1][0] * iM.m[0][0] + m[1][1] * iM.m[1][0] + m[1][2] * iM.m[2][0]; 00323 oM.m[2][0] = m[2][0] * iM.m[0][0] + m[2][1] * iM.m[1][0] + m[2][2] * iM.m[2][0]; 00324 00325 oM.m[0][1] = m[0][0] * iM.m[0][1] + m[0][1] * iM.m[1][1] + m[0][2] * iM.m[2][1]; 00326 oM.m[1][1] = m[1][0] * iM.m[0][1] + m[1][1] * iM.m[1][1] + m[1][2] * iM.m[2][1]; 00327 oM.m[2][1] = m[2][0] * iM.m[0][1] + m[2][1] * iM.m[1][1] + m[2][2] * iM.m[2][1]; 00328 00329 oM.m[0][2] = m[0][0] * iM.m[0][2] + m[0][1] * iM.m[1][2] + m[0][2] * iM.m[2][2]; 00330 oM.m[1][2] = m[1][0] * iM.m[0][2] + m[1][1] * iM.m[1][2] + m[1][2] * iM.m[2][2]; 00331 oM.m[2][2] = m[2][0] * iM.m[0][2] + m[2][1] * iM.m[1][2] + m[2][2] * iM.m[2][2]; 00332 00333 *this = oM; 00334 return *this; 00335 } 00336 00337 /***************************************************************************************\ 00338 Function: Matrix3x3<T>::operator += 00339 00340 Description: Add matrix iM. 00341 00342 Parameters: - iM 00343 00344 Return Value: Matrix3x3<T>. 00345 00346 Comments: None. 00347 \***************************************************************************************/ 00348 template <typename T> 00349 Matrix3x3<T>& Matrix3x3<T>::operator += (const Matrix3x3<T>& iM) const 00350 { 00351 Matrix3x3<T> oM; 00352 00353 oM.m[0][0] = m[0][0] + iM.m[0][0]; 00354 oM.m[0][1] = m[0][1] + iM.m[0][1]; 00355 oM.m[0][2] = m[0][2] + iM.m[0][2]; 00356 oM.m[1][0] = m[1][0] + iM.m[1][0]; 00357 oM.m[1][1] = m[1][1] + iM.m[1][1]; 00358 oM.m[1][2] = m[1][2] + iM.m[1][2]; 00359 oM.m[2][0] = m[2][0] + iM.m[2][0]; 00360 oM.m[2][1] = m[2][1] + iM.m[2][1]; 00361 oM.m[2][2] = m[2][2] + iM.m[2][2]; 00362 00363 *this = oM; 00364 return *this; 00365 } 00366 00367 /***************************************************************************************\ 00368 Function: Matrix3x3<T>::operator -= 00369 00370 Description: Substract matrix iM. 00371 00372 Parameters: - iM 00373 00374 Return Value: Matrix3x3<T>. 00375 00376 Comments: None. 00377 \***************************************************************************************/ 00378 template <typename T> 00379 Matrix3x3<T>& Matrix3x3<T>::operator -= (const Matrix3x3<T>& iM) const 00380 { 00381 Matrix3x3<T> oM; 00382 00383 oM.m[0][0] = m[0][0] - iM.m[0][0]; 00384 oM.m[0][1] = m[0][1] - iM.m[0][1]; 00385 oM.m[0][2] = m[0][2] - iM.m[0][2]; 00386 oM.m[1][0] = m[1][0] - iM.m[1][0]; 00387 oM.m[1][1] = m[1][1] - iM.m[1][1]; 00388 oM.m[1][2] = m[1][2] - iM.m[1][2]; 00389 oM.m[2][0] = m[2][0] - iM.m[2][0]; 00390 oM.m[2][1] = m[2][1] - iM.m[2][1]; 00391 oM.m[2][2] = m[2][2] - iM.m[2][2]; 00392 00393 *this = oM; 00394 return *this; 00395 } 00396 00397 00398 /***************************************************************************************\ 00399 Function: Matrix3x3<T>::operator * 00400 00401 Description: Multiply all elements by f. 00402 00403 Parameters: - f 00404 00405 Return Value: Matrix3x3<T>. 00406 00407 Comments: None. 00408 \***************************************************************************************/ 00409 template <typename T> 00410 Matrix3x3<T> Matrix3x3<T>::operator * (const T &f) const 00411 { 00412 Matrix3x3<T> oM; 00413 00414 oM.m[0][0] = m[0][0] * f; 00415 oM.m[0][1] = m[0][1] * f; 00416 oM.m[0][2] = m[0][2] * f; 00417 oM.m[1][0] = m[1][0] * f; 00418 oM.m[1][1] = m[1][1] * f; 00419 oM.m[1][2] = m[1][2] * f; 00420 oM.m[2][0] = m[2][0] * f; 00421 oM.m[2][1] = m[2][1] * f; 00422 oM.m[2][2] = m[2][2] * f; 00423 00424 return oM; 00425 } 00426 00427 /***************************************************************************************\ 00428 Function: Matrix3x3<T>::operator / 00429 00430 Description: Divide all elements by f. 00431 00432 Parameters: - f 00433 00434 Return Value: Matrix3x3<T>. 00435 00436 Comments: None. 00437 \***************************************************************************************/ 00438 template <typename T> 00439 Matrix3x3<T> Matrix3x3<T>::operator/ (const T &f) const 00440 { 00441 Matrix3x3<T> oM; 00442 00443 oM.m[0][0] = m[0][0] / f; 00444 oM.m[0][1] = m[0][1] / f; 00445 oM.m[0][2] = m[0][2] / f; 00446 oM.m[1][0] = m[1][0] / f; 00447 oM.m[1][1] = m[1][1] / f; 00448 oM.m[1][2] = m[1][2] / f; 00449 oM.m[2][0] = m[2][0] / f; 00450 oM.m[2][1] = m[2][1] / f; 00451 oM.m[2][2] = m[2][2] / f; 00452 00453 return oM; 00454 } 00455 00456 00457 00458 00459 00460 /***************************************************************************************\ 00461 Function: Matrix3x3<T>::operator *= 00462 00463 Description: Multiply all elements by f. 00464 00465 Parameters: - f 00466 00467 Return Value: Matrix3x3<T>. 00468 00469 Comments: None. 00470 \***************************************************************************************/ 00471 template <typename T> 00472 Matrix3x3<T>& Matrix3x3<T>::operator *= (const T &f) const 00473 { 00474 Matrix3x3<T> oM; 00475 00476 oM.m[0][0] = m[0][0] * f; 00477 oM.m[0][1] = m[0][1] * f; 00478 oM.m[0][2] = m[0][2] * f; 00479 oM.m[1][0] = m[1][0] * f; 00480 oM.m[1][1] = m[1][1] * f; 00481 oM.m[1][2] = m[1][2] * f; 00482 oM.m[2][0] = m[2][0] * f; 00483 oM.m[2][1] = m[2][1] * f; 00484 oM.m[2][2] = m[2][2] * f; 00485 00486 *this = oM; 00487 return *this; 00488 } 00489 00490 /***************************************************************************************\ 00491 Function: Matrix3x3<T>::operator /= 00492 00493 Description: Divide all elements by f. 00494 00495 Parameters: - f 00496 00497 Return Value: Matrix3x3<T>. 00498 00499 Comments: None. 00500 \***************************************************************************************/ 00501 template <typename T> 00502 Matrix3x3<T>& Matrix3x3<T>::operator /= (const T &f) const 00503 { 00504 Matrix3x3<T> oM; 00505 00506 oM.m[0][0] = m[0][0] / f; 00507 oM.m[0][1] = m[0][1] / f; 00508 oM.m[0][2] = m[0][2] / f; 00509 oM.m[1][0] = m[1][0] / f; 00510 oM.m[1][1] = m[1][1] / f; 00511 oM.m[1][2] = m[1][2] / f; 00512 oM.m[2][0] = m[2][0] / f; 00513 oM.m[2][1] = m[2][1] / f; 00514 oM.m[2][2] = m[2][2] / f; 00515 00516 *this = oM; 00517 return *this; 00518 } 00519 00520 /***************************************************************************************\ 00521 Function: Matrix3x3<T>::operator * 00522 00523 Description: Multiply a matrix by a vector. 00524 00525 Parameters: - V 00526 00527 Return Value: Vector4. 00528 00529 Comments: None. 00530 \***************************************************************************************/ 00531 template <typename T> 00532 Vec3<T> Matrix3x3<T>::operator * (const Vec3<T>& V) const 00533 { 00534 Vec3<T> oV; 00535 00536 oV.x = V.x * m[0][0] + V.y * m[0][1] + V.z * m[0][2]; 00537 oV.y = V.x * m[1][0] + V.y * m[1][1] + V.z * m[1][2]; 00538 oV.z = V.x * m[2][0] + V.y * m[2][1] + V.z * m[2][2]; 00539 00540 return oV; 00541 } 00542 00543 /***************************************************************************************\ 00544 Function: Matrix3x3<T>::operator - () 00545 00546 Description: Negate all elements of the matrix. 00547 00548 Parameters: None. 00549 00550 Return Value: Matrix3x3<T>. 00551 00552 Comments: None. 00553 \***************************************************************************************/ 00554 template <typename T> 00555 Matrix3x3<T> Matrix3x3<T>::operator- () 00556 { 00557 Matrix3x3<T> oM; 00558 00559 oM.m[0][0] = -m[0][0]; 00560 oM.m[0][1] = -m[0][1]; 00561 oM.m[0][2] = -m[0][2]; 00562 oM.m[1][0] = -m[1][0]; 00563 oM.m[1][1] = -m[1][1]; 00564 oM.m[1][2] = -m[1][2]; 00565 oM.m[2][0] = -m[2][0]; 00566 oM.m[2][1] = -m[2][1]; 00567 oM.m[2][2] = -m[2][2]; 00568 00569 return oM; 00570 } 00571 00572 template <typename T> 00573 T &Matrix3x3<T>::operator () (unsigned int i, unsigned int j) 00574 { 00575 return m[i][j]; 00576 } 00577 00578 template <typename T> 00579 T Matrix3x3<T>::operator () (unsigned int i, unsigned int j) const 00580 { 00581 return m[i][j]; 00582 } 00583 00584 /***************************************************************************************\ 00585 Function: Matrix3x3<T>::zero 00586 00587 Description: Set the matrix to zero. 00588 00589 Parameters: None. 00590 00591 Return Value: None. 00592 00593 Comments: None. 00594 \***************************************************************************************/ 00595 template <typename T> 00596 void Matrix3x3<T>::Zero() 00597 { 00598 m[0][0] = 0.0; 00599 m[0][1] = 0.0; 00600 m[0][2] = 0.0; 00601 m[1][0] = 0.0; 00602 m[1][1] = 0.0; 00603 m[1][2] = 0.0; 00604 m[2][0] = 0.0; 00605 m[2][1] = 0.0; 00606 m[2][2] = 0.0; 00607 00608 //memset(m, 0, sizeof(m)); 00609 } 00610 00611 /***************************************************************************************\ 00612 Function: Matrix3x3<T>::identity 00613 00614 Description: Set the matrix to identity. 00615 00616 Parameters: None. 00617 00618 Return Value: None. 00619 00620 Comments: None. 00621 \***************************************************************************************/ 00622 template <typename T> 00623 void Matrix3x3<T>::Identity() 00624 { 00625 m[0][0] = 1.0; 00626 m[0][1] = 0.0; 00627 m[0][2] = 0.0; 00628 m[1][0] = 0.0; 00629 m[1][1] = 1.0; 00630 m[1][2] = 0.0; 00631 m[2][0] = 0.0; 00632 m[2][1] = 0.0; 00633 m[2][2] = 1.0; 00634 } 00635 00636 template <typename T> 00637 T Matrix3x3<T>::Determinant() const 00638 { 00639 T det; 00640 det = m[0][0] * m[1][1] * m[2][2] + 00641 m[0][1] * m[1][2] * m[2][0] + 00642 m[0][2] * m[2][0] * m[2][1] - 00643 m[0][0] * m[1][2] * m[2][1] - 00644 m[0][1] * m[1][0] * m[2][2] - 00645 m[0][2] * m[1][1] * m[2][0]; 00646 00647 return det; 00648 } 00649 00650 template <typename T> 00651 void Matrix3x3<T>::Inverse() 00652 { 00653 T det = Determinant(); 00654 00655 if (det == T (0) ) 00656 { 00657 // Determinant is null. Matrix cannot be inverted. 00658 #ifdef NUX_DEBUG 00659 NUX_HARDWARE_BREAK; 00660 #endif 00661 return; 00662 } 00663 00664 Matrix3x3<T> Temp; 00665 Temp.m[0][0] = m[1][1] * m[2][2] - m[1][2] * m[2][1]; 00666 Temp.m[0][1] = m[0][2] * m[2][1] - m[0][1] * m[2][2]; 00667 Temp.m[0][2] = m[0][1] * m[1][2] - m[0][2] * m[1][1]; 00668 00669 Temp.m[1][0] = m[1][2] * m[2][0] - m[1][0] * m[2][2]; 00670 Temp.m[1][1] = m[0][0] * m[2][2] - m[0][2] * m[2][0]; 00671 Temp.m[1][2] = m[0][2] * m[1][0] - m[0][0] * m[1][2]; 00672 00673 Temp.m[2][0] = m[1][0] * m[2][1] - m[1][1] * m[2][0]; 00674 Temp.m[2][1] = m[0][1] * m[2][0] - m[0][0] * m[2][1]; 00675 Temp.m[2][2] = m[0][0] * m[1][1] - m[0][1] * m[1][0]; 00676 00677 *this = (T (1) / det) * Temp; 00678 } 00679 00680 template <typename T> 00681 Matrix3x3<T> Matrix3x3<T>::GetInverse() const 00682 { 00683 Matrix3x3<T> Temp = *this; 00684 Temp.Inverse(); 00685 return Temp; 00686 } 00687 00688 // template <typename T> 00689 // Matrix2x2<T> Matrix3x3<T>::GetUpper2x2() const 00690 // { 00691 // Matrix2x2<T> Temp; 00692 // Temp.m[0][0] = m[0][0]; 00693 // Temp.m[0][1] = m[0][1]; 00694 // 00695 // Temp.m[1][0] = m[1][0]; 00696 // Temp.m[1][1] = m[1][1]; 00697 // 00698 // return Temp; 00699 // } 00700 00701 template <typename T> 00702 Matrix3x3<T> Matrix3x3<T>::IDENTITY() 00703 { 00704 Matrix3x3<T> matrix; 00705 matrix.Identity(); 00706 return matrix; 00707 } 00708 00709 template <typename T> 00710 Matrix3x3<T> Matrix3x3<T>::ZERO() 00711 { 00712 Matrix3x3<T> matrix; 00713 matrix.Zero(); 00714 return matrix; 00715 } 00716 00717 /***************************************************************************************\ 00718 Function: Matrix3x3<T>::operator * 00719 00720 Description: Multiply matrix rhs by constant lhs. 00721 Allow "f * matrix" operation.. 00722 00723 Parameters: None. 00724 00725 Return Value: Matrix3x3<T>. 00726 00727 Comments: None. 00728 \***************************************************************************************/ 00729 template <typename T> 00730 Matrix3x3<T> operator * (const T &lhs, const Matrix3x3<T>& rhs) 00731 { 00732 Matrix3x3<T> oM; 00733 00734 oM.m[0][0] = rhs.m[0][0] / lhs; 00735 oM.m[0][1] = rhs.m[0][1] / lhs; 00736 oM.m[0][2] = rhs.m[0][2] / lhs; 00737 oM.m[1][0] = rhs.m[1][0] / lhs; 00738 oM.m[1][1] = rhs.m[1][1] / lhs; 00739 oM.m[1][2] = rhs.m[1][2] / lhs; 00740 oM.m[2][0] = rhs.m[2][0] / lhs; 00741 oM.m[2][1] = rhs.m[2][1] / lhs; 00742 oM.m[2][2] = rhs.m[2][2] / lhs; 00743 00744 return oM; 00745 } 00746 00747 typedef Matrix3x3<float> Matrix3; 00748 00749 } 00750 00751 00752 #endif // MATRIX3_H 00753