CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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   explicit csMatrix3 (const csQuaternion &quat) { Set (quat); }
00066 
00068   inline csVector3 Row1() const { return csVector3 (m11,m12,m13); }
00069 
00071   inline csVector3 Row2() const { return csVector3 (m21,m22,m23); }
00072 
00074   inline csVector3 Row3() const { return csVector3 (m31,m32,m33); }
00075 
00077   inline csVector3 Col1() const { return csVector3 (m11,m21,m31); }
00078 
00080   inline csVector3 Col2() const { return csVector3 (m12,m22,m32); }
00081 
00083   inline csVector3 Col3() const { return csVector3 (m13,m23,m33); }
00084 
00086   inline void Set (float m11, float m12, float m13,
00087                    float m21, float m22, float m23,
00088                    float m31, float m32, float m33)
00089   {
00090     csMatrix3::m11 = m11; csMatrix3::m12 = m12; csMatrix3::m13 = m13;
00091     csMatrix3::m21 = m21; csMatrix3::m22 = m22; csMatrix3::m23 = m23;
00092     csMatrix3::m31 = m31; csMatrix3::m32 = m32; csMatrix3::m33 = m33;
00093   }
00094 
00096   void Set (const csQuaternion &quat);
00097 
00099   csMatrix3& operator+= (const csMatrix3& m);
00100 
00102   csMatrix3& operator-= (const csMatrix3& m);
00103 
00105   csMatrix3& operator*= (const csMatrix3& m);
00106 
00108   csMatrix3& operator*= (float s);
00109 
00111   csMatrix3& operator/= (float s);
00112 
00114   inline csMatrix3 operator+ () const { return *this; }
00116   inline csMatrix3 operator- () const
00117   {
00118     return csMatrix3(-m11,-m12,-m13,
00119                      -m21,-m22,-m23,
00120                     -m31,-m32,-m33);
00121   }
00122 
00124   void Transpose ();
00125 
00127   csMatrix3 GetTranspose () const;
00128 
00130   inline csMatrix3 GetInverse () const
00131   {
00132     csMatrix3 C(
00133              (m22*m33 - m23*m32), -(m12*m33 - m13*m32),  (m12*m23 - m13*m22),
00134             -(m21*m33 - m23*m31),  (m11*m33 - m13*m31), -(m11*m23 - m13*m21),
00135              (m21*m32 - m22*m31), -(m11*m32 - m12*m31),  (m11*m22 - m12*m21) );
00136     float s = (float)1./(m11*C.m11 + m12*C.m21 + m13*C.m31);
00137 
00138     C *= s;
00139 
00140     return C;
00141   }
00142 
00144   void Invert() { *this = GetInverse (); }
00145 
00147   float Determinant () const;
00148 
00150   void Identity ();
00151 
00153   bool IsIdentity () const;
00154 
00156   friend csMatrix3 operator+ (const csMatrix3& m1, const csMatrix3& m2);
00158   friend csMatrix3 operator- (const csMatrix3& m1, const csMatrix3& m2);
00160   friend csMatrix3 operator* (const csMatrix3& m1, const csMatrix3& m2);
00161 
00163   inline friend csVector3 operator* (const csMatrix3& m, const csVector3& v)
00164   {
00165     return csVector3 (m.m11*v.x + m.m12*v.y + m.m13*v.z,
00166                       m.m21*v.x + m.m22*v.y + m.m23*v.z,
00167                       m.m31*v.x + m.m32*v.y + m.m33*v.z);
00168   }
00169 
00171   friend csMatrix3 operator* (const csMatrix3& m, float f);
00173   friend csMatrix3 operator* (float f, const csMatrix3& m);
00175   friend csMatrix3 operator/ (const csMatrix3& m, float f);
00177   friend bool operator== (const csMatrix3& m1, const csMatrix3& m2);
00179   friend bool operator!= (const csMatrix3& m1, const csMatrix3& m2);
00181   friend bool operator< (const csMatrix3& m, float f);
00183   friend bool operator> (float f, const csMatrix3& m);
00184 };
00185 
00187 class csXRotMatrix3 : public csMatrix3
00188 {
00189 public:
00194   csXRotMatrix3 (float angle);
00195 };
00196 
00198 class csYRotMatrix3 : public csMatrix3
00199 {
00200 public:
00205   csYRotMatrix3 (float angle);
00206 };
00207 
00209 class csZRotMatrix3 : public csMatrix3
00210 {
00211 public:
00216   csZRotMatrix3 (float angle);
00217 };
00218 
00220 class csXScaleMatrix3 : public csMatrix3
00221 {
00222 public:
00226   csXScaleMatrix3 (float scaler) : csMatrix3(scaler, 0, 0, 0, 1, 0, 0, 0, 1) {}
00227 };
00228 
00230 class csYScaleMatrix3 : public csMatrix3
00231 {
00232 public:
00236   csYScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, scaler, 0, 0, 0, 1) {}
00237 };
00238 
00240 class csZScaleMatrix3 : public csMatrix3
00241 {
00242 public:
00246   csZScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, 1, 0, 0, 0, scaler) {}
00247 };
00248 
00251 #endif // __CS_MATRIX3_H__

Generated for Crystal Space by doxygen 1.2.14