csgeom/matrix3.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 1998,1999,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_MATRIX3_H__ 00021 #define __CS_MATRIX3_H__ 00022 00029 #ifndef __CS_CSSYSDEFS_H__ 00030 #error "cssysdef.h must be included in EVERY source file!" 00031 #endif 00032 00033 #include "csgeom/vector3.h" 00034 00035 class csQuaternion; 00036 00040 class csMatrix3 00041 { 00042 public: 00043 float m11, m12, m13; 00044 float m21, m22, m23; 00045 float m31, m32, m33; 00046 00047 public: 00049 csMatrix3 () 00050 : m11(1), m12(0), m13(0), 00051 m21(0), m22(1), m23(0), 00052 m31(0), m32(0), m33(1) 00053 {} 00054 00056 csMatrix3 (float am11, float am12, float am13, 00057 float am21, float am22, float am23, 00058 float am31, float am32, float am33) 00059 : m11(am11), m12(am12), m13(am13), 00060 m21(am21), m22(am22), m23(am23), 00061 m31(am31), m32(am32), m33(am33) 00062 {} 00063 00065 csMatrix3 (csMatrix3 const& o) { Set(o); } 00066 00068 csMatrix3 (float x,float y, float z, float angle); 00069 00071 explicit csMatrix3 (const csQuaternion &quat) { Set (quat); } 00072 00074 csVector3 Row1() const { return csVector3 (m11,m12,m13); } 00075 00077 csVector3 Row2() const { return csVector3 (m21,m22,m23); } 00078 00080 csVector3 Row3() const { return csVector3 (m31,m32,m33); } 00081 00083 csVector3 Col1() const { return csVector3 (m11,m21,m31); } 00084 00086 csVector3 Col2() const { return csVector3 (m12,m22,m32); } 00087 00089 csVector3 Col3() const { return csVector3 (m13,m23,m33); } 00090 00092 void Set (float o11, float o12, float o13, 00093 float o21, float o22, float o23, 00094 float o31, float o32, float o33) 00095 { 00096 m11 = o11; m12 = o12; m13 = o13; 00097 m21 = o21; m22 = o22; m23 = o23; 00098 m31 = o31; m32 = o32; m33 = o33; 00099 } 00100 00101 void Set (csMatrix3 const &o) 00102 { 00103 m11 = o.m11; m12 = o.m12; m13 = o.m13; 00104 m21 = o.m21; m22 = o.m22; m23 = o.m23; 00105 m31 = o.m31; m32 = o.m32; m33 = o.m33; 00106 } 00107 00109 void Set (const csQuaternion&); 00110 00112 csMatrix3& operator= (const csMatrix3& o) { Set(o); return *this; } 00113 00115 csMatrix3& operator+= (const csMatrix3&); 00116 00118 csMatrix3& operator-= (const csMatrix3&); 00119 00121 csMatrix3& operator*= (const csMatrix3&); 00122 00124 csMatrix3& operator*= (float); 00125 00127 csMatrix3& operator/= (float); 00128 00130 csMatrix3 operator+ () const { return *this; } 00132 csMatrix3 operator- () const 00133 { 00134 return csMatrix3(-m11,-m12,-m13, 00135 -m21,-m22,-m23, 00136 -m31,-m32,-m33); 00137 } 00138 00140 void Transpose (); 00141 00143 csMatrix3 GetTranspose () const; 00144 00146 csMatrix3 GetInverse () const 00147 { 00148 csMatrix3 C( 00149 (m22*m33 - m23*m32), -(m12*m33 - m13*m32), (m12*m23 - m13*m22), 00150 -(m21*m33 - m23*m31), (m11*m33 - m13*m31), -(m11*m23 - m13*m21), 00151 (m21*m32 - m22*m31), -(m11*m32 - m12*m31), (m11*m22 - m12*m21)); 00152 float s = (float)1./(m11*C.m11 + m12*C.m21 + m13*C.m31); 00153 C *= s; 00154 return C; 00155 } 00156 00158 void Invert() { *this = GetInverse (); } 00159 00161 float Determinant () const; 00162 00164 void Identity (); 00165 00167 bool IsIdentity () const; 00168 00170 friend csMatrix3 operator+ (const csMatrix3& m1, const csMatrix3& m2); 00172 friend csMatrix3 operator- (const csMatrix3& m1, const csMatrix3& m2); 00174 friend csMatrix3 operator* (const csMatrix3& m1, const csMatrix3& m2); 00175 00177 inline friend csVector3 operator* (const csMatrix3& m, const csVector3& v) 00178 { 00179 return csVector3 (m.m11*v.x + m.m12*v.y + m.m13*v.z, 00180 m.m21*v.x + m.m22*v.y + m.m23*v.z, 00181 m.m31*v.x + m.m32*v.y + m.m33*v.z); 00182 } 00183 00185 friend csMatrix3 operator* (const csMatrix3& m, float f); 00187 friend csMatrix3 operator* (float f, const csMatrix3& m); 00189 friend csMatrix3 operator/ (const csMatrix3& m, float f); 00191 friend bool operator== (const csMatrix3& m1, const csMatrix3& m2); 00193 friend bool operator!= (const csMatrix3& m1, const csMatrix3& m2); 00195 friend bool operator< (const csMatrix3& m, float f); 00197 friend bool operator> (float f, const csMatrix3& m); 00198 }; 00199 00201 class csXRotMatrix3 : public csMatrix3 00202 { 00203 public: 00210 csXRotMatrix3 (float angle); 00211 }; 00212 00214 class csYRotMatrix3 : public csMatrix3 00215 { 00216 public: 00223 csYRotMatrix3 (float angle); 00224 }; 00225 00227 class csZRotMatrix3 : public csMatrix3 00228 { 00229 public: 00236 csZRotMatrix3 (float angle); 00237 }; 00238 00240 class csXScaleMatrix3 : public csMatrix3 00241 { 00242 public: 00246 csXScaleMatrix3 (float scaler) : csMatrix3(scaler, 0, 0, 0, 1, 0, 0, 0, 1) {} 00247 }; 00248 00250 class csYScaleMatrix3 : public csMatrix3 00251 { 00252 public: 00256 csYScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, scaler, 0, 0, 0, 1) {} 00257 }; 00258 00260 class csZScaleMatrix3 : public csMatrix3 00261 { 00262 public: 00266 csZScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, 1, 0, 0, 0, scaler) {} 00267 }; 00268 00271 #endif // __CS_MATRIX3_H__
Generated for Crystal Space by doxygen 1.2.18