Main Page   Class Hierarchy   Compound List   File List   Compound Members  

matrix3.h

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 
00023 #ifndef __CS_CSSYSDEFS_H__
00024 #error "cssysdef.h must be included in EVERY source file!"
00025 #endif
00026 
00027 #include "csgeom/vector3.h"
00028 
00029 class csQuaternion;
00030 
00034 class csMatrix3
00035 {
00036 public:
00037   float m11, m12, m13;
00038   float m21, m22, m23;
00039   float m31, m32, m33;
00040 
00041 public:
00043   csMatrix3 ();
00044 
00046   csMatrix3 (float m11, float m12, float m13,
00047              float m21, float m22, float m23,
00048              float m31, float m32, float m33);
00049 
00051   explicit csMatrix3 (const csQuaternion &quat) { Set (quat); }
00052 
00054   inline csVector3 Row1() const { return csVector3 (m11,m12,m13); }
00055 
00057   inline csVector3 Row2() const { return csVector3 (m21,m22,m23); }
00058 
00060   inline csVector3 Row3() const { return csVector3 (m31,m32,m33); }
00061 
00063   inline csVector3 Col1() const { return csVector3 (m11,m21,m31); }
00064 
00066   inline csVector3 Col2() const { return csVector3 (m12,m22,m32); }
00067 
00069   inline csVector3 Col3() const { return csVector3 (m13,m23,m33); }
00070 
00072   inline void Set (float m11, float m12, float m13,
00073                    float m21, float m22, float m23,
00074                    float m31, float m32, float m33)
00075   {
00076     csMatrix3::m11 = m11; csMatrix3::m12 = m12; csMatrix3::m13 = m13;
00077     csMatrix3::m21 = m21; csMatrix3::m22 = m22; csMatrix3::m23 = m23;
00078     csMatrix3::m31 = m31; csMatrix3::m32 = m32; csMatrix3::m33 = m33;
00079   }
00080 
00082   void Set (const csQuaternion &quat);
00083 
00085   csMatrix3& operator+= (const csMatrix3& m);
00086 
00088   csMatrix3& operator-= (const csMatrix3& m);
00089 
00091   csMatrix3& operator*= (const csMatrix3& m);
00092 
00094   csMatrix3& operator*= (float s);
00095 
00097   csMatrix3& operator/= (float s);
00098 
00100   inline csMatrix3 operator+ () const { return *this; }
00102   inline csMatrix3 operator- () const
00103   {
00104     return csMatrix3(-m11,-m12,-m13,
00105                      -m21,-m22,-m23,
00106                     -m31,-m32,-m33);
00107   }
00108 
00110   void Transpose ();
00111 
00113   csMatrix3 GetTranspose () const;
00114 
00116   inline csMatrix3 GetInverse () const
00117   {
00118     csMatrix3 C(
00119              (m22*m33 - m23*m32), -(m12*m33 - m13*m32),  (m12*m23 - m13*m22),
00120             -(m21*m33 - m23*m31),  (m11*m33 - m13*m31), -(m11*m23 - m13*m21),
00121              (m21*m32 - m22*m31), -(m11*m32 - m12*m31),  (m11*m22 - m12*m21) );
00122     float s = (float)1./(m11*C.m11 + m12*C.m21 + m13*C.m31);
00123 
00124     C *= s;
00125 
00126     return C;
00127   }
00128 
00130   void Invert() { *this = GetInverse (); }
00131 
00133   float Determinant () const;
00134 
00136   void Identity ();
00137 
00139   bool IsIdentity () const;
00140 
00142   friend csMatrix3 operator+ (const csMatrix3& m1, const csMatrix3& m2);
00144   friend csMatrix3 operator- (const csMatrix3& m1, const csMatrix3& m2);
00146   friend csMatrix3 operator* (const csMatrix3& m1, const csMatrix3& m2);
00147 
00149   inline friend csVector3 operator* (const csMatrix3& m, const csVector3& v)
00150   {
00151     return csVector3 (m.m11*v.x + m.m12*v.y + m.m13*v.z,
00152                       m.m21*v.x + m.m22*v.y + m.m23*v.z,
00153                       m.m31*v.x + m.m32*v.y + m.m33*v.z);
00154   }
00155 
00157   friend csMatrix3 operator* (const csMatrix3& m, float f);
00159   friend csMatrix3 operator* (float f, const csMatrix3& m);
00161   friend csMatrix3 operator/ (const csMatrix3& m, float f);
00163   friend bool operator== (const csMatrix3& m1, const csMatrix3& m2);
00165   friend bool operator!= (const csMatrix3& m1, const csMatrix3& m2);
00167   friend bool operator< (const csMatrix3& m, float f);
00169   friend bool operator> (float f, const csMatrix3& m);
00170 };
00171 
00173 class csXRotMatrix3 : public csMatrix3
00174 {
00175 public:
00180   csXRotMatrix3 (float angle);
00181 };
00182 
00184 class csYRotMatrix3 : public csMatrix3
00185 {
00186 public:
00191   csYRotMatrix3 (float angle);
00192 };
00193 
00195 class csZRotMatrix3 : public csMatrix3
00196 {
00197 public:
00202   csZRotMatrix3 (float angle);
00203 };
00204 
00206 class csXScaleMatrix3 : public csMatrix3
00207 {
00208 public:
00212   csXScaleMatrix3 (float scaler) : csMatrix3(scaler, 0, 0, 0, 1, 0, 0, 0, 1) {}
00213 };
00214 
00216 class csYScaleMatrix3 : public csMatrix3
00217 {
00218 public:
00222   csYScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, scaler, 0, 0, 0, 1) {}
00223 };
00224 
00226 class csZScaleMatrix3 : public csMatrix3
00227 {
00228 public:
00232   csZScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, 1, 0, 0, 0, scaler) {}
00233 };
00234 
00235 #endif // __CS_MATRIX3_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000