Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
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 #include "csextern.h" 00030 #include "csgeom/vector3.h" 00031 00032 class csQuaternion; 00033 00037 class CS_CSGEOM_EXPORT csMatrix3 00038 { 00039 public: 00040 float m11, m12, m13; 00041 float m21, m22, m23; 00042 float m31, m32, m33; 00043 00044 public: 00046 csMatrix3 () 00047 : m11(1), m12(0), m13(0), 00048 m21(0), m22(1), m23(0), 00049 m31(0), m32(0), m33(1) 00050 {} 00051 00053 csMatrix3 (float am11, float am12, float am13, 00054 float am21, float am22, float am23, 00055 float am31, float am32, float am33) 00056 : m11(am11), m12(am12), m13(am13), 00057 m21(am21), m22(am22), m23(am23), 00058 m31(am31), m32(am32), m33(am33) 00059 {} 00060 00062 csMatrix3 (csMatrix3 const& o) { Set(o); } 00063 00065 csMatrix3 (float x,float y, float z, float angle); 00066 00068 explicit csMatrix3 (const csQuaternion &quat) { Set (quat); } 00069 00071 csVector3 Row1() const { return csVector3 (m11,m12,m13); } 00072 00074 csVector3 Row2() const { return csVector3 (m21,m22,m23); } 00075 00077 csVector3 Row3() const { return csVector3 (m31,m32,m33); } 00078 00080 csVector3 Col1() const { return csVector3 (m11,m21,m31); } 00081 00083 csVector3 Col2() const { return csVector3 (m12,m22,m32); } 00084 00086 csVector3 Col3() const { return csVector3 (m13,m23,m33); } 00087 00089 void Set (float o11, float o12, float o13, 00090 float o21, float o22, float o23, 00091 float o31, float o32, float o33) 00092 { 00093 m11 = o11; m12 = o12; m13 = o13; 00094 m21 = o21; m22 = o22; m23 = o23; 00095 m31 = o31; m32 = o32; m33 = o33; 00096 } 00097 00098 void Set (csMatrix3 const &o) 00099 { 00100 m11 = o.m11; m12 = o.m12; m13 = o.m13; 00101 m21 = o.m21; m22 = o.m22; m23 = o.m23; 00102 m31 = o.m31; m32 = o.m32; m33 = o.m33; 00103 } 00104 00106 void Set (const csQuaternion&); 00107 00109 csMatrix3& operator= (const csMatrix3& o) { Set(o); return *this; } 00110 00112 csMatrix3& operator+= (const csMatrix3&); 00113 00115 csMatrix3& operator-= (const csMatrix3&); 00116 00118 csMatrix3& operator*= (const csMatrix3&); 00119 00121 csMatrix3& operator*= (float); 00122 00124 csMatrix3& operator/= (float); 00125 00127 csMatrix3 operator+ () const { return *this; } 00129 csMatrix3 operator- () const 00130 { 00131 return csMatrix3(-m11,-m12,-m13, 00132 -m21,-m22,-m23, 00133 -m31,-m32,-m33); 00134 } 00135 00137 void Transpose (); 00138 00140 csMatrix3 GetTranspose () const; 00141 00143 csMatrix3 GetInverse () const 00144 { 00145 csMatrix3 C( 00146 (m22*m33 - m23*m32), -(m12*m33 - m13*m32), (m12*m23 - m13*m22), 00147 -(m21*m33 - m23*m31), (m11*m33 - m13*m31), -(m11*m23 - m13*m21), 00148 (m21*m32 - m22*m31), -(m11*m32 - m12*m31), (m11*m22 - m12*m21)); 00149 float s = (float)1./(m11*C.m11 + m12*C.m21 + m13*C.m31); 00150 C *= s; 00151 return C; 00152 } 00153 00155 void Invert() { *this = GetInverse (); } 00156 00158 float Determinant () const; 00159 00161 void Identity (); 00162 00164 bool IsIdentity () const; 00165 00167 friend CS_CSGEOM_EXPORT csMatrix3 operator+ (const csMatrix3& m1, 00168 const csMatrix3& m2); 00170 friend CS_CSGEOM_EXPORT csMatrix3 operator- (const csMatrix3& m1, 00171 const csMatrix3& m2); 00173 friend CS_CSGEOM_EXPORT csMatrix3 operator* (const csMatrix3& m1, 00174 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 CS_CSGEOM_EXPORT csMatrix3 operator* (const csMatrix3& m, float f); 00187 friend CS_CSGEOM_EXPORT csMatrix3 operator* (float f, const csMatrix3& m); 00189 friend CS_CSGEOM_EXPORT csMatrix3 operator/ (const csMatrix3& m, float f); 00191 friend CS_CSGEOM_EXPORT bool operator== (const csMatrix3& m1, 00192 const csMatrix3& m2); 00194 friend CS_CSGEOM_EXPORT bool operator!= (const csMatrix3& m1, 00195 const csMatrix3& m2); 00197 friend CS_CSGEOM_EXPORT bool operator< (const csMatrix3& m, float f); 00199 friend CS_CSGEOM_EXPORT bool operator> (float f, const csMatrix3& m); 00200 }; 00201 00203 class CS_CSGEOM_EXPORT csXRotMatrix3 : public csMatrix3 00204 { 00205 public: 00212 csXRotMatrix3 (float angle); 00213 }; 00214 00216 class CS_CSGEOM_EXPORT csYRotMatrix3 : public csMatrix3 00217 { 00218 public: 00225 csYRotMatrix3 (float angle); 00226 }; 00227 00229 class CS_CSGEOM_EXPORT csZRotMatrix3 : public csMatrix3 00230 { 00231 public: 00238 csZRotMatrix3 (float angle); 00239 }; 00240 00242 class CS_CSGEOM_EXPORT csXScaleMatrix3 : public csMatrix3 00243 { 00244 public: 00248 csXScaleMatrix3 (float scaler) : csMatrix3(scaler, 0, 0, 0, 1, 0, 0, 0, 1) {} 00249 }; 00250 00252 class CS_CSGEOM_EXPORT csYScaleMatrix3 : public csMatrix3 00253 { 00254 public: 00258 csYScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, scaler, 0, 0, 0, 1) {} 00259 }; 00260 00262 class CS_CSGEOM_EXPORT csZScaleMatrix3 : public csMatrix3 00263 { 00264 public: 00268 csZScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, 1, 0, 0, 0, scaler) {} 00269 }; 00270 00273 #endif // __CS_MATRIX3_H__
Generated for Crystal Space by doxygen 1.3.9.1