CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

matrix2.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 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_MATRIX2_H__
00021 #define __CS_MATRIX2_H__
00022 
00023 #include "csextern.h"
00024 
00025 #include "csgeom/vector2.h"
00026 
00036 class CS_CRYSTALSPACE_EXPORT csMatrix2
00037 {
00038 public:
00039   float m11, m12;
00040   float m21, m22;
00041 
00042 public:
00044   csMatrix2 ();
00045 
00047   csMatrix2 (float m11, float m12,
00048              float m21, float m22);
00049 
00051   inline csVector2 Row1() const { return csVector2 (m11,m12); }
00052 
00054   inline csVector2 Row2() const { return csVector2 (m21,m22); }
00055 
00057   inline csVector2 Col1() const { return csVector2 (m11,m21); }
00058 
00060   inline csVector2 Col2() const { return csVector2 (m12,m22); }
00061 
00063   inline void Set (float m11, float m12,
00064                    float m21, float m22)
00065   {
00066     csMatrix2::m11 = m11; csMatrix2::m12 = m12;
00067     csMatrix2::m21 = m21; csMatrix2::m22 = m22;
00068   }
00069 
00071   csMatrix2& operator+= (const csMatrix2& m);
00072 
00074   csMatrix2& operator-= (const csMatrix2& m);
00075 
00077   csMatrix2& operator*= (const csMatrix2& m);
00078 
00080   csMatrix2& operator*= (float s);
00081 
00083   csMatrix2& operator/= (float s);
00084 
00086   inline csMatrix2 operator+ () const { return *this; }
00088   inline csMatrix2 operator- () const
00089   {
00090     return csMatrix2(-m11,-m12, -m21,-m22);
00091   }
00092 
00094   void Transpose ();
00095 
00097   csMatrix2 GetTranspose () const;
00098 
00100   inline csMatrix2 GetInverse () const
00101   {
00102     float inv_det = 1 / (m11 * m22 - m12 * m21);
00103     return csMatrix2 (m22 * inv_det, -m12 * inv_det, -m21 * inv_det, m11 * inv_det);
00104   }
00105 
00107   void Invert () { *this = GetInverse (); }
00108 
00110   float Determinant () const;
00111 
00113   void Identity ();
00114 
00116   friend csMatrix2 operator+ (const csMatrix2& m1, const csMatrix2& m2);
00118   friend csMatrix2 operator- (const csMatrix2& m1, const csMatrix2& m2);
00120   friend csMatrix2 operator* (const csMatrix2& m1, const csMatrix2& m2);
00121 
00123   inline friend csVector2 operator* (const csMatrix2& m, const csVector2& v)
00124   {
00125     return csVector2 (m.m11*v.x + m.m12*v.y, m.m21*v.x + m.m22*v.y);
00126   }
00127 
00129   friend csMatrix2 operator* (const csMatrix2& m, float f);
00131   friend csMatrix2 operator* (float f, const csMatrix2& m);
00133   friend csMatrix2 operator/ (const csMatrix2& m, float f);
00134 };
00135 
00138 #endif // __CS_MATRIX2_H__
00139 

Generated for Crystal Space by doxygen 1.4.4