|
matrix2.h00001 /* 00002 Copyright (C) 2000 by Jorrit Tyberghein 00003 Largely rewritten by Ivan Avramovic <ivan@avramovic.com> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_MATRIX2_H__ 00021 #define __CS_MATRIX2_H__ 00022 00023 #include "csgeom/vector2.h" 00024 00028 class csMatrix2 00029 { 00030 public: 00031 float m11, m12; 00032 float m21, m22; 00033 00034 public: 00036 csMatrix2 (); 00037 00039 csMatrix2 (float m11, float m12, 00040 float m21, float m22); 00041 00043 inline csVector2 Row1() const { return csVector2 (m11,m12); } 00044 00046 inline csVector2 Row2() const { return csVector2 (m21,m22); } 00047 00049 inline csVector2 Col1() const { return csVector2 (m11,m21); } 00050 00052 inline csVector2 Col2() const { return csVector2 (m12,m22); } 00053 00055 inline void Set (float m11, float m12, 00056 float m21, float m22) 00057 { 00058 csMatrix2::m11 = m11; csMatrix2::m12 = m12; 00059 csMatrix2::m21 = m21; csMatrix2::m22 = m22; 00060 } 00061 00063 csMatrix2& operator+= (const csMatrix2& m); 00064 00066 csMatrix2& operator-= (const csMatrix2& m); 00067 00069 csMatrix2& operator*= (const csMatrix2& m); 00070 00072 csMatrix2& operator*= (float s); 00073 00075 csMatrix2& operator/= (float s); 00076 00078 inline csMatrix2 operator+ () const { return *this; } 00080 inline csMatrix2 operator- () const 00081 { 00082 return csMatrix2(-m11,-m12, -m21,-m22); 00083 } 00084 00086 void Transpose (); 00087 00089 csMatrix2 GetTranspose () const; 00090 00092 inline csMatrix2 GetInverse () const 00093 { 00094 float inv_det = 1 / (m11 * m22 - m12 * m21); 00095 return csMatrix2 (m22 * inv_det, -m12 * inv_det, -m21 * inv_det, m11 * inv_det); 00096 } 00097 00099 void Invert () { *this = GetInverse (); } 00100 00102 float Determinant () const; 00103 00105 void Identity (); 00106 00108 friend csMatrix2 operator+ (const csMatrix2& m1, const csMatrix2& m2); 00110 friend csMatrix2 operator- (const csMatrix2& m1, const csMatrix2& m2); 00112 friend csMatrix2 operator* (const csMatrix2& m1, const csMatrix2& m2); 00113 00115 inline friend csVector2 operator* (const csMatrix2& m, const csVector2& v) 00116 { 00117 return csVector2 (m.m11*v.x + m.m12*v.y, m.m21*v.x + m.m22*v.y); 00118 } 00119 00121 friend csMatrix2 operator* (const csMatrix2& m, float f); 00123 friend csMatrix2 operator* (float f, const csMatrix2& m); 00125 friend csMatrix2 operator/ (const csMatrix2& m, float f); 00126 }; 00127 00128 #endif // __CS_MATRIX2_H__ 00129 Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |