CrystalSpace

Public API Reference

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

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 "csgeom/vector2.h"
00024 
00034 class csMatrix2
00035 {
00036 public:
00037   float m11, m12;
00038   float m21, m22;
00039 
00040 public:
00042   csMatrix2 ();
00043 
00045   csMatrix2 (float m11, float m12,
00046              float m21, float m22);
00047 
00049   inline csVector2 Row1() const { return csVector2 (m11,m12); }
00050 
00052   inline csVector2 Row2() const { return csVector2 (m21,m22); }
00053 
00055   inline csVector2 Col1() const { return csVector2 (m11,m21); }
00056 
00058   inline csVector2 Col2() const { return csVector2 (m12,m22); }
00059 
00061   inline void Set (float m11, float m12,
00062                    float m21, float m22)
00063   {
00064     csMatrix2::m11 = m11; csMatrix2::m12 = m12;
00065     csMatrix2::m21 = m21; csMatrix2::m22 = m22;
00066   }
00067 
00069   csMatrix2& operator+= (const csMatrix2& m);
00070 
00072   csMatrix2& operator-= (const csMatrix2& m);
00073 
00075   csMatrix2& operator*= (const csMatrix2& m);
00076 
00078   csMatrix2& operator*= (float s);
00079 
00081   csMatrix2& operator/= (float s);
00082 
00084   inline csMatrix2 operator+ () const { return *this; }
00086   inline csMatrix2 operator- () const
00087   {
00088     return csMatrix2(-m11,-m12, -m21,-m22);
00089   }
00090 
00092   void Transpose ();
00093 
00095   csMatrix2 GetTranspose () const;
00096 
00098   inline csMatrix2 GetInverse () const
00099   {
00100     float inv_det = 1 / (m11 * m22 - m12 * m21);
00101     return csMatrix2 (m22 * inv_det, -m12 * inv_det, -m21 * inv_det, m11 * inv_det);
00102   }
00103 
00105   void Invert () { *this = GetInverse (); }
00106 
00108   float Determinant () const;
00109 
00111   void Identity ();
00112 
00114   friend csMatrix2 operator+ (const csMatrix2& m1, const csMatrix2& m2);
00116   friend csMatrix2 operator- (const csMatrix2& m1, const csMatrix2& m2);
00118   friend csMatrix2 operator* (const csMatrix2& m1, const csMatrix2& m2);
00119 
00121   inline friend csVector2 operator* (const csMatrix2& m, const csVector2& v)
00122   {
00123     return csVector2 (m.m11*v.x + m.m12*v.y, m.m21*v.x + m.m22*v.y);
00124   }
00125 
00127   friend csMatrix2 operator* (const csMatrix2& m, float f);
00129   friend csMatrix2 operator* (float f, const csMatrix2& m);
00131   friend csMatrix2 operator/ (const csMatrix2& m, float f);
00132 };
00133 
00136 #endif // __CS_MATRIX2_H__
00137 

Generated for Crystal Space by doxygen 1.2.14