Google

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       : m11(1), m12(0), m13(0),
00045         m21(0), m22(1), m23(0),
00046         m31(0), m32(0), m33(1)
00047   {}
00048 
00050   csMatrix3 (float am11, float am12, float am13,
00051              float am21, float am22, float am23,
00052              float am31, float am32, float am33)
00053       : m11(am11), m12(am12), m13(am13),
00054         m21(am21), m22(am22), m23(am23),
00055         m31(am31), m32(am32), m33(am33)
00056   {}
00057 
00059   explicit csMatrix3 (const csQuaternion &quat) { Set (quat); }
00060 
00062   inline csVector3 Row1() const { return csVector3 (m11,m12,m13); }
00063 
00065   inline csVector3 Row2() const { return csVector3 (m21,m22,m23); }
00066 
00068   inline csVector3 Row3() const { return csVector3 (m31,m32,m33); }
00069 
00071   inline csVector3 Col1() const { return csVector3 (m11,m21,m31); }
00072 
00074   inline csVector3 Col2() const { return csVector3 (m12,m22,m32); }
00075 
00077   inline csVector3 Col3() const { return csVector3 (m13,m23,m33); }
00078 
00080   inline void Set (float m11, float m12, float m13,
00081                    float m21, float m22, float m23,
00082                    float m31, float m32, float m33)
00083   {
00084     csMatrix3::m11 = m11; csMatrix3::m12 = m12; csMatrix3::m13 = m13;
00085     csMatrix3::m21 = m21; csMatrix3::m22 = m22; csMatrix3::m23 = m23;
00086     csMatrix3::m31 = m31; csMatrix3::m32 = m32; csMatrix3::m33 = m33;
00087   }
00088 
00090   void Set (const csQuaternion &quat);
00091 
00093   csMatrix3& operator+= (const csMatrix3& m);
00094 
00096   csMatrix3& operator-= (const csMatrix3& m);
00097 
00099   csMatrix3& operator*= (const csMatrix3& m);
00100 
00102   csMatrix3& operator*= (float s);
00103 
00105   csMatrix3& operator/= (float s);
00106 
00108   inline csMatrix3 operator+ () const { return *this; }
00110   inline csMatrix3 operator- () const
00111   {
00112     return csMatrix3(-m11,-m12,-m13,
00113                      -m21,-m22,-m23,
00114                     -m31,-m32,-m33);
00115   }
00116 
00118   void Transpose ();
00119 
00121   csMatrix3 GetTranspose () const;
00122 
00124   inline csMatrix3 GetInverse () const
00125   {
00126     csMatrix3 C(
00127              (m22*m33 - m23*m32), -(m12*m33 - m13*m32),  (m12*m23 - m13*m22),
00128             -(m21*m33 - m23*m31),  (m11*m33 - m13*m31), -(m11*m23 - m13*m21),
00129              (m21*m32 - m22*m31), -(m11*m32 - m12*m31),  (m11*m22 - m12*m21) );
00130     float s = (float)1./(m11*C.m11 + m12*C.m21 + m13*C.m31);
00131 
00132     C *= s;
00133 
00134     return C;
00135   }
00136 
00138   void Invert() { *this = GetInverse (); }
00139 
00141   float Determinant () const;
00142 
00144   void Identity ();
00145 
00147   bool IsIdentity () const;
00148 
00150   friend csMatrix3 operator+ (const csMatrix3& m1, const csMatrix3& m2);
00152   friend csMatrix3 operator- (const csMatrix3& m1, const csMatrix3& m2);
00154   friend csMatrix3 operator* (const csMatrix3& m1, const csMatrix3& m2);
00155 
00157   inline friend csVector3 operator* (const csMatrix3& m, const csVector3& v)
00158   {
00159     return csVector3 (m.m11*v.x + m.m12*v.y + m.m13*v.z,
00160                       m.m21*v.x + m.m22*v.y + m.m23*v.z,
00161                       m.m31*v.x + m.m32*v.y + m.m33*v.z);
00162   }
00163 
00165   friend csMatrix3 operator* (const csMatrix3& m, float f);
00167   friend csMatrix3 operator* (float f, const csMatrix3& m);
00169   friend csMatrix3 operator/ (const csMatrix3& m, float f);
00171   friend bool operator== (const csMatrix3& m1, const csMatrix3& m2);
00173   friend bool operator!= (const csMatrix3& m1, const csMatrix3& m2);
00175   friend bool operator< (const csMatrix3& m, float f);
00177   friend bool operator> (float f, const csMatrix3& m);
00178 };
00179 
00181 class csXRotMatrix3 : public csMatrix3
00182 {
00183 public:
00188   csXRotMatrix3 (float angle);
00189 };
00190 
00192 class csYRotMatrix3 : public csMatrix3
00193 {
00194 public:
00199   csYRotMatrix3 (float angle);
00200 };
00201 
00203 class csZRotMatrix3 : public csMatrix3
00204 {
00205 public:
00210   csZRotMatrix3 (float angle);
00211 };
00212 
00214 class csXScaleMatrix3 : public csMatrix3
00215 {
00216 public:
00220   csXScaleMatrix3 (float scaler) : csMatrix3(scaler, 0, 0, 0, 1, 0, 0, 0, 1) {}
00221 };
00222 
00224 class csYScaleMatrix3 : public csMatrix3
00225 {
00226 public:
00230   csYScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, scaler, 0, 0, 0, 1) {}
00231 };
00232 
00234 class csZScaleMatrix3 : public csMatrix3
00235 {
00236 public:
00240   csZScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, 1, 0, 0, 0, scaler) {}
00241 };
00242 
00243 #endif // __CS_MATRIX3_H__

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