Gel2D - The free/open source game creation suite

gelMatrix.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D 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
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELMATRIX_H__
00017 #define __GELMATRIX_H__
00018 
00019 #include "gelVector.h"
00020 
00021 namespace gel
00022 {
00025 
00026 
00028         class Gel3x3Matrix
00029         {
00030                 public:
00031                         union
00032                         {
00033                                 float m[3][3];
00034                                 struct
00035                                 {
00036                                         float m11, m12, m13,
00037                                               m21, m22, m23,
00038                                               m31, m32, m33;
00039                                 };
00040                         };
00041 
00042                 public:
00044 
00045                         Gel3x3Matrix();
00046 
00048 
00049                         Gel3x3Matrix( const float matrix[16] );
00050 
00052                         void loadNull();
00053 
00055                         void loadIdentity();
00056 
00058 
00059                         void translate( Gel2dVec pos );
00060 
00062 
00063                         void rotate( float rot );
00064 
00066 
00067                         void rotateRad( float rot );
00068 
00070 
00071                         void scale( Gel2dVec scl );
00072 
00074 
00076                         void shear( float shx, float shy );
00077 
00079 
00080                         bool isIdentity() const;
00081 
00083 
00084                         bool isTranslation() const;
00085 
00087 
00088                         bool isRotation() const;
00089 
00091 
00092                         bool isScaling() const;
00093 
00095 
00096                         bool isShearing() const;
00097 
00099 
00100             void toOGLMatrix( float matrix[16] ) const;
00101 
00103                         void dump() const;
00104 
00105                         // Matrix operators
00106                         Gel3x3Matrix operator+( const Gel3x3Matrix &m ) const;
00107                         Gel3x3Matrix operator-( const Gel3x3Matrix &m ) const;
00108                         Gel3x3Matrix operator*( const Gel3x3Matrix &m ) const;
00109                         Gel3x3Matrix operator=( const Gel3x3Matrix &m );
00110 
00111                         Gel3x3Matrix operator+=( const Gel3x3Matrix &m );
00112                         Gel3x3Matrix operator-=( const Gel3x3Matrix &m );
00113                         Gel3x3Matrix operator*=( const Gel3x3Matrix &m );
00114 
00115                         bool operator==( const Gel3x3Matrix &m ) const;
00116                         bool operator!=( const Gel3x3Matrix &m ) const;
00117 
00119                         Gel2dVec operator*( const Gel2dVec &v ) const;
00120         };
00121 
00123 
00127         class Gel4x4Matrix
00128         {
00129                 public:
00130                         union
00131                         {
00132                                 float m[4][4];
00133                                 float ms[16];
00134                                 struct
00135                                 {
00136                                         float m11, m12, m13, m14,
00137                                               m21, m22, m23, m24,
00138                                               m31, m32, m33, m34,
00139                                               m41, m42, m43, m44;
00140                                 };
00141                         };
00142 
00143                 public:
00145 
00146                         Gel4x4Matrix();
00147 
00149 
00150                         Gel4x4Matrix( const float matrix[16] );
00151 
00153                         void loadNull();
00154 
00156                         void loadIdentity();
00157 
00159 
00160                         void translate( Gel3dVec pos );
00161 
00163 
00164                         void rotateX( float rot );
00165 
00167 
00168                         void rotateY( float rot );
00169 
00171 
00172                         void rotateZ( float rot );
00173 
00175 
00176                         void scale( Gel3dVec scl );
00177 
00179 
00182                         void shear( Gel2dVec shx, Gel2dVec shy, Gel2dVec shz );
00183 
00185 
00186                         bool isIdentity() const;
00187 
00189 
00190                         bool isTranslation() const;
00191 
00193 
00194                         bool isRotation() const;
00195 
00197 
00198                         bool isScaling() const;
00199 
00201 
00202                         bool isShearing() const;
00203 
00205 
00206             void toOGLMatrix( float matrix[16] ) const;
00207 
00209                         void dump() const;
00210 
00211                         // Matrix operators
00212                         Gel4x4Matrix operator+( const Gel4x4Matrix &m ) const;
00213                         Gel4x4Matrix operator-( const Gel4x4Matrix &m ) const;
00214                         Gel4x4Matrix operator*( const Gel4x4Matrix &m ) const;
00215                         Gel4x4Matrix operator=( const Gel4x4Matrix &m );
00216 
00217                         Gel4x4Matrix operator+=( const Gel4x4Matrix &m );
00218                         Gel4x4Matrix operator-=( const Gel4x4Matrix &m );
00219                         Gel4x4Matrix operator*=( const Gel4x4Matrix &m );
00220 
00221                         bool operator==( const Gel4x4Matrix &m ) const;
00222                         bool operator!=( const Gel4x4Matrix &m ) const;
00223 
00225                         Gel3dVec operator*( const Gel3dVec &v ) const;
00226                 };
00228 }
00229 
00230 #endif // __GELMATRIX_H__