CrystalSpace

Public API Reference

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

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 <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 "csextern.h"
00034 
00035 #include "csgeom/vector3.h"
00036 
00037 class csQuaternion;
00038 
00042 class CS_CSGEOM_EXPORT csMatrix3
00043 {
00044 public:
00045   float m11, m12, m13;
00046   float m21, m22, m23;
00047   float m31, m32, m33;
00048 
00049 public:
00051   csMatrix3 ()
00052       : m11(1), m12(0), m13(0),
00053         m21(0), m22(1), m23(0),
00054         m31(0), m32(0), m33(1)
00055   {}
00056 
00058   csMatrix3 (float am11, float am12, float am13,
00059              float am21, float am22, float am23,
00060              float am31, float am32, float am33)
00061       : m11(am11), m12(am12), m13(am13),
00062         m21(am21), m22(am22), m23(am23),
00063         m31(am31), m32(am32), m33(am33)
00064   {}
00065 
00067   csMatrix3 (csMatrix3 const& o) { Set(o); }
00068 
00070   csMatrix3 (float x,float y, float z, float angle);
00071 
00073   explicit csMatrix3 (const csQuaternion &quat) { Set (quat); }
00074 
00076   csVector3 Row1() const { return csVector3 (m11,m12,m13); }
00077 
00079   csVector3 Row2() const { return csVector3 (m21,m22,m23); }
00080 
00082   csVector3 Row3() const { return csVector3 (m31,m32,m33); }
00083 
00085   csVector3 Col1() const { return csVector3 (m11,m21,m31); }
00086 
00088   csVector3 Col2() const { return csVector3 (m12,m22,m32); }
00089 
00091   csVector3 Col3() const { return csVector3 (m13,m23,m33); }
00092 
00094   void Set (float o11, float o12, float o13,
00095             float o21, float o22, float o23,
00096             float o31, float o32, float o33)
00097   {
00098     m11 = o11; m12 = o12; m13 = o13;
00099     m21 = o21; m22 = o22; m23 = o23;
00100     m31 = o31; m32 = o32; m33 = o33;
00101   }
00102 
00103   void Set (csMatrix3 const &o)
00104   {
00105     m11 = o.m11; m12 = o.m12; m13 = o.m13;
00106     m21 = o.m21; m22 = o.m22; m23 = o.m23;
00107     m31 = o.m31; m32 = o.m32; m33 = o.m33;
00108   }
00109 
00111   void Set (const csQuaternion&);
00112 
00114   csMatrix3& operator= (const csMatrix3& o) { Set(o); return *this; }
00115 
00117   csMatrix3& operator+= (const csMatrix3&);
00118 
00120   csMatrix3& operator-= (const csMatrix3&);
00121 
00123   csMatrix3& operator*= (const csMatrix3&);
00124 
00126   csMatrix3& operator*= (float);
00127 
00129   csMatrix3& operator/= (float);
00130 
00132   csMatrix3 operator+ () const { return *this; }
00134   csMatrix3 operator- () const
00135   {
00136     return csMatrix3(-m11,-m12,-m13,
00137                      -m21,-m22,-m23,
00138                      -m31,-m32,-m33);
00139   }
00140 
00142   void Transpose ();
00143 
00145   csMatrix3 GetTranspose () const;
00146 
00148   csMatrix3 GetInverse () const
00149   {
00150     csMatrix3 C(
00151              (m22*m33 - m23*m32), -(m12*m33 - m13*m32),  (m12*m23 - m13*m22),
00152             -(m21*m33 - m23*m31),  (m11*m33 - m13*m31), -(m11*m23 - m13*m21),
00153              (m21*m32 - m22*m31), -(m11*m32 - m12*m31),  (m11*m22 - m12*m21));
00154     float s = (float)1./(m11*C.m11 + m12*C.m21 + m13*C.m31);
00155     C *= s;
00156     return C;
00157   }
00158 
00160   void Invert() { *this = GetInverse (); }
00161 
00163   float Determinant () const;
00164 
00166   void Identity ();
00167 
00169   bool IsIdentity () const;
00170 
00172   friend CS_CSGEOM_EXPORT csMatrix3 operator+ (const csMatrix3& m1, 
00173     const csMatrix3& m2);
00175   friend CS_CSGEOM_EXPORT csMatrix3 operator- (const csMatrix3& m1, 
00176     const csMatrix3& m2);
00178   friend CS_CSGEOM_EXPORT csMatrix3 operator* (const csMatrix3& m1, 
00179     const csMatrix3& m2);
00180 
00182   inline friend csVector3 operator* (const csMatrix3& m, const csVector3& v)
00183   {
00184     return csVector3 (m.m11*v.x + m.m12*v.y + m.m13*v.z,
00185                       m.m21*v.x + m.m22*v.y + m.m23*v.z,
00186                       m.m31*v.x + m.m32*v.y + m.m33*v.z);
00187   }
00188 
00190   friend CS_CSGEOM_EXPORT csMatrix3 operator* (const csMatrix3& m, float f);
00192   friend CS_CSGEOM_EXPORT csMatrix3 operator* (float f, const csMatrix3& m);
00194   friend CS_CSGEOM_EXPORT csMatrix3 operator/ (const csMatrix3& m, float f);
00196   friend CS_CSGEOM_EXPORT bool operator== (const csMatrix3& m1, 
00197     const csMatrix3& m2);
00199   friend CS_CSGEOM_EXPORT bool operator!= (const csMatrix3& m1, 
00200     const csMatrix3& m2);
00202   friend CS_CSGEOM_EXPORT bool operator< (const csMatrix3& m, float f);
00204   friend CS_CSGEOM_EXPORT bool operator> (float f, const csMatrix3& m);
00205 };
00206 
00208 class CS_CSGEOM_EXPORT csXRotMatrix3 : public csMatrix3
00209 {
00210 public:
00217   csXRotMatrix3 (float angle);
00218 };
00219 
00221 class CS_CSGEOM_EXPORT csYRotMatrix3 : public csMatrix3
00222 {
00223 public:
00230   csYRotMatrix3 (float angle);
00231 };
00232 
00234 class CS_CSGEOM_EXPORT csZRotMatrix3 : public csMatrix3
00235 {
00236 public:
00243   csZRotMatrix3 (float angle);
00244 };
00245 
00247 class CS_CSGEOM_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_CSGEOM_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_CSGEOM_EXPORT csZScaleMatrix3 : public csMatrix3
00268 {
00269 public:
00273   csZScaleMatrix3 (float scaler) : csMatrix3(1, 0, 0, 0, 1, 0, 0, 0, scaler) {}
00274 };
00275 
00278 #endif // __CS_MATRIX3_H__

Generated for Crystal Space by doxygen 1.2.18