CrystalSpace

Public API Reference

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 <[email protected]>
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 
00030 #include "csextern.h"
00031 #include "csgeom/vector3.h"
00032 
00033 class csQuaternion;
00034 
00038 class CS_CRYSTALSPACE_EXPORT csMatrix3
00039 {
00040 public:
00041   float m11, m12, m13;
00042   float m21, m22, m23;
00043   float m31, m32, m33;
00044 
00045 public:
00047   csMatrix3 ()
00048       : m11(1), m12(0), m13(0),
00049         m21(0), m22(1), m23(0),
00050         m31(0), m32(0), m33(1)
00051   {}
00052 
00054   csMatrix3 (float am11, float am12, float am13,
00055              float am21, float am22, float am23,
00056              float am31, float am32, float am33)
00057       : m11(am11), m12(am12), m13(am13),
00058         m21(am21), m22(am22), m23(am23),
00059         m31(am31), m32(am32), m33(am33)
00060   {}
00061 
00063   csMatrix3 (csMatrix3 const& o) { Set(o); }
00064 
00066   csMatrix3 (float x,float y, float z, float angle);
00067 
00069   explicit csMatrix3 (const csQuaternion &quat) { Set (quat); }
00070 
00072   inline csVector3 Row1() const { return csVector3 (m11,m12,m13); }
00073 
00075   inline csVector3 Row2() const { return csVector3 (m21,m22,m23); }
00076 
00078   inline csVector3 Row3() const { return csVector3 (m31,m32,m33); }
00079 
00081   inline csVector3 Col1() const { return csVector3 (m11,m21,m31); }
00082 
00084   inline csVector3 Col2() const { return csVector3 (m12,m22,m32); }
00085 
00087   inline csVector3 Col3() const { return csVector3 (m13,m23,m33); }
00088 
00090   inline void Set (float o11, float o12, float o13,
00091                    float o21, float o22, float o23,
00092                    float o31, float o32, float o33)
00093   {
00094     m11 = o11; m12 = o12; m13 = o13;
00095     m21 = o21; m22 = o22; m23 = o23;
00096     m31 = o31; m32 = o32; m33 = o33;
00097   }
00098 
00099   inline void Set (csMatrix3 const &o)
00100   {
00101     m11 = o.m11; m12 = o.m12; m13 = o.m13;
00102     m21 = o.m21; m22 = o.m22; m23 = o.m23;
00103     m31 = o.m31; m32 = o.m32; m33 = o.m33;
00104   }
00105 
00107   void Set (const csQuaternion&);
00108 
00110   csMatrix3& operator= (const csMatrix3& o) { Set(o); return *this; }
00111 
00113   csMatrix3& operator+= (const csMatrix3&);
00114 
00116   csMatrix3& operator-= (const csMatrix3&);
00117 
00119   csMatrix3& operator*= (const csMatrix3&);
00120 
00122   csMatrix3& operator*= (float);
00123 
00125   csMatrix3& operator/= (float);
00126 
00128   csMatrix3 operator+ () const { return *this; }
00130   csMatrix3 operator- () const
00131   {
00132     return csMatrix3(-m11,-m12,-m13,
00133                      -m21,-m22,-m23,
00134                      -m31,-m32,-m33);
00135   }
00136 
00138   void Transpose ();
00139 
00141   csMatrix3 GetTranspose () const;
00142 
00144   inline csMatrix3 GetInverse () const
00145   {
00146     csMatrix3 C(
00147              (m22*m33 - m23*m32), -(m12*m33 - m13*m32),  (m12*m23 - m13*m22),
00148             -(m21*m33 - m23*m31),  (m11*m33 - m13*m31), -(m11*m23 - m13*m21),
00149              (m21*m32 - m22*m31), -(m11*m32 - m12*m31),  (m11*m22 - m12*m21));
00150     float s = (float)1./(m11*C.m11 + m12*C.m21 + m13*C.m31);
00151     C *= s;
00152     return C;
00153   }
00154 
00156   inline void Invert() { *this = GetInverse (); }
00157 
00159   float Determinant () const;
00160 
00162   void Identity ();
00163 
00165   bool IsIdentity () const;
00166 
00168   friend CS_CRYSTALSPACE_EXPORT csMatrix3 operator+ (const csMatrix3& m1, 
00169     const csMatrix3& m2);
00171   friend CS_CRYSTALSPACE_EXPORT csMatrix3 operator- (const csMatrix3& m1, 
00172     const csMatrix3& m2);
00174   friend CS_CRYSTALSPACE_EXPORT csMatrix3 operator* (const csMatrix3& m1, 
00175     const csMatrix3& m2);
00176 
00178   inline friend csVector3 operator* (const csMatrix3& m, const csVector3& v)
00179   {
00180     return csVector3 (m.m11*v.x + m.m12*v.y + m.m13*v.z,
00181                       m.m21*v.x + m.m22*v.y + m.m23*v.z,
00182                       m.m31*v.x + m.m32*v.y + m.m33*v.z);
00183   }
00184 
00186   friend CS_CRYSTALSPACE_EXPORT csMatrix3 operator* (const csMatrix3& m,
00187         float f);
00189   friend CS_CRYSTALSPACE_EXPORT csMatrix3 operator* (float f,
00190         const csMatrix3& m);
00192   friend CS_CRYSTALSPACE_EXPORT csMatrix3 operator/ (const csMatrix3& m,
00193         float f);
00195   friend CS_CRYSTALSPACE_EXPORT bool operator== (const csMatrix3& m1, 
00196     const csMatrix3& m2);
00198   friend CS_CRYSTALSPACE_EXPORT bool operator!= (const csMatrix3& m1, 
00199     const csMatrix3& m2);
00201   friend CS_CRYSTALSPACE_EXPORT bool operator< (const csMatrix3& m, float f);
00203   friend CS_CRYSTALSPACE_EXPORT bool operator> (float f,
00204         const csMatrix3& m);
00205 };
00206 
00208 class CS_CRYSTALSPACE_EXPORT csXRotMatrix3 : public csMatrix3
00209 {
00210 public:
00217   csXRotMatrix3 (float angle);
00218 };
00219 
00221 class CS_CRYSTALSPACE_EXPORT csYRotMatrix3 : public csMatrix3
00222 {
00223 public:
00230   csYRotMatrix3 (float angle);
00231 };
00232 
00234 class CS_CRYSTALSPACE_EXPORT csZRotMatrix3 : public csMatrix3
00235 {
00236 public:
00243   csZRotMatrix3 (float angle);
00244 };
00245 
00247 class CS_CRYSTALSPACE_EXPORT csXScaleMatrix3 : public csMatrix3
00248 {
00249 public:
00253   csXScaleMatrix3 (float scaler) : csMatrix3(scaler, 0, 0, 0, 1, 0, 0, 0, 1) {}
00254 };
00255 
00257 class CS_CRYSTALSPACE_EXPORT csYScaleMatrix3 : public csMatrix3
00258 {
00259 public:
00263   csYScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, scaler, 0, 0, 0, 1) {}
00264 };
00265 
00267 class CS_CRYSTALSPACE_EXPORT csZScaleMatrix3 : public csMatrix3
00268 {
00269 public:
00273   csZScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, 1, 0, 0, 0, scaler) {}
00274 };
00275 
00276 
00279 #endif // __CS_MATRIX3_H__

Generated for Crystal Space by doxygen 1.4.7