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

FXMat3f.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *            S i n g l e - P r e c i s i o n   3 x 3   M a t r i x              *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2003,2010 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXMAT3F_H
00022 #define FXMAT3F_H
00023 
00024 
00025 namespace FX {
00026 
00027 
00028 class FXQuatf;
00029 class FXMat4f;
00030 
00031 
00032 /// Single-precision 3x3 matrix
00033 class FXAPI FXMat3f {
00034 protected:
00035   FXVec3f m[3];
00036 public:
00037 
00038   /// Default constructor; value is not initialized
00039   FXMat3f(){}
00040 
00041   /// Initialize matrix from scalar
00042   FXMat3f(FXfloat s);
00043 
00044   /// Initialize matrix from another matrix
00045   FXMat3f(const FXMat3f& s);
00046 
00047   /// Initialize from rotation and scaling part of 4x4 matrix
00048   FXMat3f(const FXMat4f& s);
00049 
00050   /// Initialize matrix from array
00051   FXMat3f(const FXfloat s[]);
00052 
00053   /// Initialize diagonal matrix
00054   FXMat3f(FXfloat a,FXfloat b,FXfloat c);
00055 
00056   /// Initialize matrix from components
00057   FXMat3f(FXfloat a00,FXfloat a01,FXfloat a02,
00058           FXfloat a10,FXfloat a11,FXfloat a12,
00059           FXfloat a20,FXfloat a21,FXfloat a22);
00060 
00061   /// Initialize matrix from three vectors
00062   FXMat3f(const FXVec3f& a,const FXVec3f& b,const FXVec3f& c);
00063 
00064   /// Initialize matrix from quaternion
00065   FXMat3f(const FXQuatf& quat);
00066 
00067   /// Assignment from scalar
00068   FXMat3f& operator=(FXfloat s);
00069 
00070   /// Assignment
00071   FXMat3f& operator=(const FXMat3f& s);
00072   FXMat3f& operator=(const FXMat4f& s);
00073 
00074   /// Assignment from array
00075   FXMat3f& operator=(const FXfloat s[]);
00076 
00077   /// Set value from scalar
00078   FXMat3f& set(FXfloat s);
00079 
00080   /// Set value from another matrix
00081   FXMat3f& set(const FXMat3f& s);
00082 
00083   /// Set from rotation and scaling part of 4x4 matrix
00084   FXMat3f& set(const FXMat4f& s);
00085 
00086   /// Set value from array
00087   FXMat3f& set(const FXfloat s[]);
00088 
00089   /// Set diagonal matrix
00090   FXMat3f& set(FXfloat a,FXfloat b,FXfloat c);
00091 
00092   /// Set value from components
00093   FXMat3f& set(FXfloat a00,FXfloat a01,FXfloat a02,
00094                FXfloat a10,FXfloat a11,FXfloat a12,
00095                FXfloat a20,FXfloat a21,FXfloat a22);
00096 
00097   /// Set value from three vectors
00098   FXMat3f& set(const FXVec3f& a,const FXVec3f& b,const FXVec3f& c);
00099 
00100   /// Set value from quaternion
00101   FXMat3f& set(const FXQuatf& quat);
00102 
00103   /// Assignment operators
00104   FXMat3f& operator+=(const FXMat3f& w);
00105   FXMat3f& operator-=(const FXMat3f& w);
00106   FXMat3f& operator*=(const FXMat3f& w);
00107   FXMat3f& operator*=(FXfloat w);
00108   FXMat3f& operator/=(FXfloat w);
00109 
00110   /// Indexing
00111   FXVec3f& operator[](FXint i){return m[i];}
00112   const FXVec3f& operator[](FXint i) const {return m[i];}
00113 
00114   /// Conversion
00115   operator FXfloat*(){return m[0];}
00116   operator const FXfloat*() const {return m[0];}
00117 
00118   /// Unary minus
00119   FXMat3f operator-() const;
00120 
00121   /// Set to identity matrix
00122   FXMat3f& identity();
00123 
00124   /// Return true if identity matrix
00125   FXbool isIdentity() const;
00126 
00127   /// Multiply by rotation of phi
00128   FXMat3f& rot(FXfloat c,FXfloat s);
00129   FXMat3f& rot(FXfloat phi);
00130 
00131   /// Multiply by translation
00132   FXMat3f& trans(FXfloat tx,FXfloat ty);
00133 
00134   /// Multiply by scaling
00135   FXMat3f& scale(FXfloat sx,FXfloat sy);
00136   FXMat3f& scale(FXfloat s);
00137 
00138   /// Determinant
00139   FXfloat det() const;
00140 
00141   /// Transpose
00142   FXMat3f transpose() const;
00143 
00144   /// Invert
00145   FXMat3f invert() const;
00146   };
00147 
00148 
00149 /// Matrix times vector
00150 extern FXAPI FXVec2f operator*(const FXMat3f& m,const FXVec2f& v);
00151 extern FXAPI FXVec3f operator*(const FXMat3f& m,const FXVec3f& v);
00152 
00153 /// Vector times matrix
00154 extern FXAPI FXVec2f operator*(const FXVec2f& v,const FXMat3f& m);
00155 extern FXAPI FXVec3f operator*(const FXVec3f& v,const FXMat3f& m);
00156 
00157 /// Matrix and matrix addition
00158 extern FXAPI FXMat3f operator+(const FXMat3f& a,const FXMat3f& b);
00159 extern FXAPI FXMat3f operator-(const FXMat3f& a,const FXMat3f& b);
00160 
00161 /// Matrix and matrix multiply
00162 extern FXAPI FXMat3f operator*(const FXMat3f& a,const FXMat3f& b);
00163 
00164 /// Scaling
00165 extern FXAPI FXMat3f operator*(FXfloat x,const FXMat3f& a);
00166 extern FXAPI FXMat3f operator*(const FXMat3f& a,FXfloat x);
00167 extern FXAPI FXMat3f operator/(const FXMat3f& a,FXfloat x);
00168 extern FXAPI FXMat3f operator/(FXfloat x,const FXMat3f& a);
00169 
00170 /// Equality tests
00171 extern FXAPI FXbool operator==(const FXMat3f& a,const FXMat3f& b);
00172 extern FXAPI FXbool operator!=(const FXMat3f& a,const FXMat3f& b);
00173 extern FXAPI FXbool operator==(const FXMat3f& a,FXfloat n);
00174 extern FXAPI FXbool operator!=(const FXMat3f& a,FXfloat n);
00175 extern FXAPI FXbool operator==(FXfloat n,const FXMat3f& a);
00176 extern FXAPI FXbool operator!=(FXfloat n,const FXMat3f& a);
00177 
00178 /// Save matrix to a stream
00179 extern FXAPI FXStream& operator<<(FXStream& store,const FXMat3f& m);
00180 
00181 /// Load matrix from a stream
00182 extern FXAPI FXStream& operator>>(FXStream& store,FXMat3f& m);
00183 
00184 }
00185 
00186 #endif

Copyright © 1997-2010 Jeroen van der Zijp