CrystalSpace

Public API Reference

csgeom/matrix2.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 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_MATRIX2_H__
00021 #define __CS_MATRIX2_H__
00022 
00023 #include "csextern.h"
00024 
00025 #include "csgeom/vector2.h"
00026 
00037 class CS_CRYSTALSPACE_EXPORT csMatrix2
00038 {
00039 public:
00040   float m11, m12;
00041   float m21, m22;
00042 
00043 public:
00045   csMatrix2 ();
00046 
00048   csMatrix2 (float m11, float m12,
00049              float m21, float m22);
00050 
00052   inline csVector2 Row1() const { return csVector2 (m11,m12); }
00053 
00055   inline csVector2 Row2() const { return csVector2 (m21,m22); }
00056 
00058   inline csVector2 Col1() const { return csVector2 (m11,m21); }
00059 
00061   inline csVector2 Col2() const { return csVector2 (m12,m22); }
00062 
00064   inline void Set (float m11, float m12,
00065                    float m21, float m22)
00066   {
00067     csMatrix2::m11 = m11; csMatrix2::m12 = m12;
00068     csMatrix2::m21 = m21; csMatrix2::m22 = m22;
00069   }
00070 
00072   csMatrix2& operator+= (const csMatrix2& m);
00073 
00075   csMatrix2& operator-= (const csMatrix2& m);
00076 
00078   csMatrix2& operator*= (const csMatrix2& m);
00079 
00081   csMatrix2& operator*= (float s);
00082 
00084   csMatrix2& operator/= (float s);
00085 
00087   inline csMatrix2 operator+ () const { return *this; }
00089   inline csMatrix2 operator- () const
00090   {
00091     return csMatrix2(-m11,-m12, -m21,-m22);
00092   }
00093 
00095   void Transpose ();
00096 
00098   csMatrix2 GetTranspose () const;
00099 
00101   inline csMatrix2 GetInverse () const
00102   {
00103     float inv_det = 1 / (m11 * m22 - m12 * m21);
00104     return csMatrix2 (m22 * inv_det, -m12 * inv_det,
00105                       -m21 * inv_det, m11 * inv_det);
00106   }
00107 
00109   void Invert () { *this = GetInverse (); }
00110 
00112   float Determinant () const;
00113 
00115   void Identity ();
00116 
00118   friend csMatrix2 operator+ (const csMatrix2& m1, const csMatrix2& m2);
00120   friend csMatrix2 operator- (const csMatrix2& m1, const csMatrix2& m2);
00122   friend csMatrix2 operator* (const csMatrix2& m1, const csMatrix2& m2);
00123 
00125   inline friend csVector2 operator* (const csMatrix2& m, const csVector2& v)
00126   {
00127     return csVector2 (m.m11*v.x + m.m12*v.y, m.m21*v.x + m.m22*v.y);
00128   }
00129 
00131   friend csMatrix2 operator* (const csMatrix2& m, float f);
00133   friend csMatrix2 operator* (float f, const csMatrix2& m);
00135   friend csMatrix2 operator/ (const csMatrix2& m, float f);
00136 };
00137 
00140 #endif // __CS_MATRIX2_H__
00141 

Generated for Crystal Space by doxygen 1.4.7