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

FXMat3d.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *            D o u b 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,2009 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 * $Id: FXMat3d.h,v 1.26 2009/01/26 09:40:22 fox Exp $                           *
00022 ********************************************************************************/
00023 #ifndef FXMAT3D_H
00024 #define FXMAT3D_H
00025 
00026 
00027 namespace FX {
00028 
00029 
00030 class FXQuatd;
00031 class FXMat4d;
00032 
00033 
00034 /// Double-precision 3x3 matrix
00035 class FXAPI FXMat3d {
00036 protected:
00037   FXVec3d m[3];
00038 public:
00039 
00040   /// Default constructor; value is not initialized
00041   FXMat3d(){}
00042 
00043   /// Initialize matrix from another matrix
00044   FXMat3d(const FXMat3d& other);
00045 
00046   /// Initialize from rotation and scaling part of 4x4 matrix
00047   FXMat3d(const FXMat4d& other);
00048 
00049   /// Initialize matrix from scalar
00050   FXMat3d(FXdouble w);
00051 
00052   /// Initialize diagonal matrix
00053   FXMat3d(FXdouble a,FXdouble b,FXdouble c);
00054 
00055   /// Initialize matrix from components
00056   FXMat3d(FXdouble a00,FXdouble a01,FXdouble a02,
00057           FXdouble a10,FXdouble a11,FXdouble a12,
00058           FXdouble a20,FXdouble a21,FXdouble a22);
00059 
00060   /// Initialize matrix from three vectors
00061   FXMat3d(const FXVec3d& a,const FXVec3d& b,const FXVec3d& c);
00062 
00063   /// Initialize matrix from quaternion
00064   FXMat3d(const FXQuatd& quat);
00065 
00066   /// Assignment
00067   FXMat3d& operator=(const FXMat3d& other);
00068   FXMat3d& operator=(const FXMat4d& other);
00069   FXMat3d& operator=(FXdouble w);
00070 
00071   /// Set value from another matrix
00072   FXMat3d& set(const FXMat3d& other);
00073 
00074   /// Set from rotation and scaling part of 4x4 matrix
00075   FXMat3d& set(const FXMat4d& q);
00076 
00077   /// Set value from scalar
00078   FXMat3d& set(FXdouble w);
00079 
00080   /// Set diagonal matrix
00081   FXMat3d& set(FXdouble a,FXdouble b,FXdouble c);
00082 
00083   /// Set value from components
00084   FXMat3d& set(FXdouble a00,FXdouble a01,FXdouble a02,
00085                FXdouble a10,FXdouble a11,FXdouble a12,
00086                FXdouble a20,FXdouble a21,FXdouble a22);
00087 
00088   /// Set value from three vectors
00089   FXMat3d& set(const FXVec3d& a,const FXVec3d& b,const FXVec3d& c);
00090 
00091   /// Set value from quaternion
00092   FXMat3d& set(const FXQuatd& quat);
00093 
00094   /// Assignment operators
00095   FXMat3d& operator+=(const FXMat3d& w);
00096   FXMat3d& operator-=(const FXMat3d& w);
00097   FXMat3d& operator*=(const FXMat3d& w);
00098   FXMat3d& operator*=(FXdouble w);
00099   FXMat3d& operator/=(FXdouble w);
00100 
00101   /// Indexing
00102   FXVec3d& operator[](FXint i){return m[i];}
00103   const FXVec3d& operator[](FXint i) const {return m[i];}
00104 
00105   /// Conversion
00106   operator FXdouble*(){return m[0];}
00107   operator const FXdouble*() const {return m[0];}
00108 
00109   /// Unary minus
00110   FXMat3d operator-() const;
00111 
00112   /// Matrix and matrix
00113   FXMat3d operator+(const FXMat3d& w) const;
00114   FXMat3d operator-(const FXMat3d& w) const;
00115   FXMat3d operator*(const FXMat3d& w) const;
00116 
00117   /// Multiply matrix and vector
00118   FXVec3d operator*(const FXVec3d& v) const;
00119   FXVec2d operator*(const FXVec2d& v) const;
00120 
00121   /// Equality tests
00122   FXbool operator==(const FXMat3d& a) const;
00123   FXbool operator!=(const FXMat3d& a) const;
00124 
00125   friend FXAPI FXbool operator==(const FXMat3d& a,FXdouble n);
00126   friend FXAPI FXbool operator==(FXdouble n,const FXMat3d& a);
00127 
00128   friend FXAPI FXbool operator!=(const FXMat3d& a,FXdouble n);
00129   friend FXAPI FXbool operator!=(FXdouble n,const FXMat3d& a);
00130 
00131   /// Matrix and scalar
00132   friend FXAPI FXMat3d operator*(FXdouble x,const FXMat3d& a);
00133   friend FXAPI FXMat3d operator*(const FXMat3d& a,FXdouble x);
00134   friend FXAPI FXMat3d operator/(const FXMat3d& a,FXdouble x);
00135   friend FXAPI FXMat3d operator/(FXdouble x,const FXMat3d& a);
00136 
00137   /// Set to identity matrix
00138   FXMat3d& identity();
00139 
00140   /// Return true if identity matrix
00141   FXbool isIdentity() const;
00142 
00143   /// Multiply by rotation of phi
00144   FXMat3d& rot(FXdouble c,FXdouble s);
00145   FXMat3d& rot(FXdouble phi);
00146 
00147   /// Multiply by translation
00148   FXMat3d& trans(FXdouble tx,FXdouble ty);
00149 
00150   /// Multiply by scaling
00151   FXMat3d& scale(FXdouble sx,FXdouble sy);
00152   FXMat3d& scale(FXdouble s);
00153 
00154   /// Determinant
00155   FXdouble det() const;
00156 
00157   /// Transpose
00158   FXMat3d transpose() const;
00159 
00160   /// Invert
00161   FXMat3d invert() const;
00162 
00163   /// Save to a stream
00164   friend FXAPI FXStream& operator<<(FXStream& store,const FXMat3d& m);
00165 
00166   /// Load from a stream
00167   friend FXAPI FXStream& operator>>(FXStream& store,FXMat3d& m);
00168   };
00169 
00170 extern FXAPI FXMat3d operator*(FXdouble x,const FXMat3d& a);
00171 extern FXAPI FXMat3d operator*(const FXMat3d& a,FXdouble x);
00172 
00173 extern FXAPI FXMat3d operator/(const FXMat3d& a,FXdouble x);
00174 extern FXAPI FXMat3d operator/(FXdouble x,const FXMat3d& a);
00175 
00176 extern FXAPI FXbool operator==(const FXMat3d& a,FXdouble n);
00177 extern FXAPI FXbool operator==(FXdouble n,const FXMat3d& a);
00178 
00179 extern FXAPI FXbool operator!=(const FXMat3d& a,FXdouble n);
00180 extern FXAPI FXbool operator!=(FXdouble n,const FXMat3d& a);
00181 
00182 extern FXAPI FXStream& operator<<(FXStream& store,const FXMat3d& m);
00183 extern FXAPI FXStream& operator>>(FXStream& store,FXMat3d& m);
00184 
00185 }
00186 
00187 #endif

Copyright © 1997-2009 Jeroen van der Zijp