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

FXMat4d.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   4 x 4   M a t r i x              *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1994,2008 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: FXMat4d.h,v 1.28 2008/01/04 15:18:21 fox Exp $                           *
00022 ********************************************************************************/
00023 #ifndef FXMAT4D_H
00024 #define FXMAT4D_H
00025 
00026 
00027 namespace FX {
00028 
00029 
00030 class FXMat3d;
00031 
00032 
00033 /// Double-precision 4x4 matrix
00034 class FXAPI FXMat4d {
00035 protected:
00036   FXVec4d m[4];
00037 public:
00038 
00039   /// Default constructor
00040   FXMat4d(){}
00041 
00042   /// Initialize matrix from another matrix
00043   FXMat4d(const FXMat4d& other);
00044 
00045   /// Initialize with 3x3 rotation and scaling matrix
00046   FXMat4d(const FXMat3d& other);
00047 
00048   /// Initialize matrix from scalar
00049   FXMat4d(FXdouble w);
00050 
00051   /// Initialize diagonal matrix
00052   FXMat4d(FXdouble a,FXdouble b,FXdouble c,FXdouble d);
00053 
00054   /// Initialize matrix from components
00055   FXMat4d(FXdouble a00,FXdouble a01,FXdouble a02,FXdouble a03,
00056           FXdouble a10,FXdouble a11,FXdouble a12,FXdouble a13,
00057           FXdouble a20,FXdouble a21,FXdouble a22,FXdouble a23,
00058           FXdouble a30,FXdouble a31,FXdouble a32,FXdouble a33);
00059 
00060   /// Initialize matrix from four vectors
00061   FXMat4d(const FXVec4d& a,const FXVec4d& b,const FXVec4d& c,const FXVec4d& d);
00062 
00063   /// Assignment
00064   FXMat4d& operator=(const FXMat4d& other);
00065   FXMat4d& operator=(const FXMat3d& other);
00066   FXMat4d& operator=(FXdouble w);
00067 
00068   /// Set value from another matrix
00069   FXMat4d& set(const FXMat4d& other);
00070 
00071   /// Set value from 3x3 rotation and scaling matrix
00072   FXMat4d& set(const FXMat3d& other);
00073 
00074   /// Set value from scalar
00075   FXMat4d& set(FXdouble w);
00076 
00077   /// Set diagonal matrix
00078   FXMat4d& set(FXdouble a,FXdouble b,FXdouble c,FXdouble d);
00079 
00080   /// Set value from components
00081   FXMat4d& set(FXdouble a00,FXdouble a01,FXdouble a02,FXdouble a03,
00082                FXdouble a10,FXdouble a11,FXdouble a12,FXdouble a13,
00083                FXdouble a20,FXdouble a21,FXdouble a22,FXdouble a23,
00084                FXdouble a30,FXdouble a31,FXdouble a32,FXdouble a33);
00085 
00086   /// Set value from four vectors
00087   FXMat4d& set(const FXVec4d& a,const FXVec4d& b,const FXVec4d& c,const FXVec4d& d);
00088 
00089   /// Assignment operators
00090   FXMat4d& operator+=(const FXMat4d& w);
00091   FXMat4d& operator-=(const FXMat4d& w);
00092   FXMat4d& operator*=(const FXMat4d& w);
00093   FXMat4d& operator*=(FXdouble w);
00094   FXMat4d& operator/=(FXdouble w);
00095 
00096   /// Indexing
00097   FXVec4d& operator[](FXint i){return m[i];}
00098   const FXVec4d& operator[](FXint i) const {return m[i];}
00099 
00100   /// Conversion
00101   operator FXdouble*(){return m[0];}
00102   operator const FXdouble*() const {return m[0];}
00103 
00104   /// Unary minus
00105   FXMat4d operator-() const;
00106 
00107   /// Matrix and matrix
00108   FXMat4d operator+(const FXMat4d& w) const;
00109   FXMat4d operator-(const FXMat4d& w) const;
00110   FXMat4d operator*(const FXMat4d& w) const;
00111 
00112   /// Multiply matrix and vector
00113   FXVec4d operator*(const FXVec4d& v) const;
00114   FXVec3d operator*(const FXVec3d& v) const;
00115 
00116   /// Equality tests
00117   FXbool operator==(const FXMat4d& a) const;
00118   FXbool operator!=(const FXMat4d& a) const;
00119 
00120   friend FXAPI FXbool operator==(const FXMat4d& a,FXdouble n);
00121   friend FXAPI FXbool operator==(FXdouble n,const FXMat4d& a);
00122 
00123   friend FXAPI FXbool operator!=(const FXMat4d& a,FXdouble n);
00124   friend FXAPI FXbool operator!=(FXdouble n,const FXMat4d& a);
00125 
00126   /// Matrix and scalar
00127   friend FXAPI FXMat4d operator*(FXdouble x,const FXMat4d& a);
00128   friend FXAPI FXMat4d operator*(const FXMat4d& a,FXdouble x);
00129   friend FXAPI FXMat4d operator/(const FXMat4d& a,FXdouble x);
00130   friend FXAPI FXMat4d operator/(FXdouble x,const FXMat4d& a);
00131 
00132   /// Set to identity matrix
00133   FXMat4d& identity();
00134 
00135   /// Return true if identity matrix
00136   FXbool isIdentity() const;
00137 
00138   /// Set orthographic projection from view volume
00139   FXMat4d& setOrtho(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi,FXdouble zlo,FXdouble zhi);
00140 
00141   /// Get view volume from orthographic projection
00142   void getOrtho(FXdouble& xlo,FXdouble& xhi,FXdouble& ylo,FXdouble& yhi,FXdouble& zlo,FXdouble& zhi) const;
00143 
00144   /// Set to inverse orthographic projection
00145   FXMat4d& setInverseOrtho(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi,FXdouble zlo,FXdouble zhi);
00146 
00147   /// Set to perspective projection from view volume
00148   FXMat4d& setFrustum(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi,FXdouble zlo,FXdouble zhi);
00149 
00150   /// Get view volume from perspective projection
00151   void getFrustum(FXdouble& xlo,FXdouble& xhi,FXdouble& ylo,FXdouble& yhi,FXdouble& zlo,FXdouble& zhi) const;
00152 
00153   /// Set to inverse perspective projection from view volume
00154   FXMat4d& setInverseFrustum(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi,FXdouble zlo,FXdouble zhi);
00155 
00156   /// Multiply by left-hand matrix
00157   FXMat4d& left();
00158 
00159   /// Multiply by rotation matrix
00160   FXMat4d& rot(const FXMat3d& r);
00161 
00162   /// Multiply by rotation about unit-quaternion
00163   FXMat4d& rot(const FXQuatd& q);
00164 
00165   /// Multiply by rotation c,s about axis
00166   FXMat4d& rot(const FXVec3d& v,FXdouble c,FXdouble s);
00167 
00168   /// Multiply by rotation of phi about axis
00169   FXMat4d& rot(const FXVec3d& v,FXdouble phi);
00170 
00171   /// Multiply by x-rotation
00172   FXMat4d& xrot(FXdouble c,FXdouble s);
00173   FXMat4d& xrot(FXdouble phi);
00174 
00175   /// Multiply by y-rotation
00176   FXMat4d& yrot(FXdouble c,FXdouble s);
00177   FXMat4d& yrot(FXdouble phi);
00178 
00179   /// Multiply by z-rotation
00180   FXMat4d& zrot(FXdouble c,FXdouble s);
00181   FXMat4d& zrot(FXdouble phi);
00182 
00183   /// Look at
00184   FXMat4d& look(const FXVec3d& from,const FXVec3d& to,const FXVec3d& up);
00185 
00186   /// Multiply by translation
00187   FXMat4d& trans(FXdouble tx,FXdouble ty,FXdouble tz);
00188   FXMat4d& trans(const FXVec3d& v);
00189 
00190   /// Multiply by scaling
00191   FXMat4d& scale(FXdouble sx,FXdouble sy,FXdouble sz);
00192   FXMat4d& scale(FXdouble s);
00193   FXMat4d& scale(const FXVec3d& v);
00194 
00195   /// Determinant
00196   FXdouble det() const;
00197 
00198   /// Transpose
00199   FXMat4d transpose() const;
00200 
00201   /// Invert
00202   FXMat4d invert() const;
00203 
00204   /// Save to a stream
00205   friend FXAPI FXStream& operator<<(FXStream& store,const FXMat4d& m);
00206 
00207   /// Load from a stream
00208   friend FXAPI FXStream& operator>>(FXStream& store,FXMat4d& m);
00209   };
00210 
00211 extern FXAPI FXMat4d operator*(FXdouble x,const FXMat4d& a);
00212 extern FXAPI FXMat4d operator*(const FXMat4d& a,FXdouble x);
00213 
00214 extern FXAPI FXMat4d operator/(const FXMat4d& a,FXdouble x);
00215 extern FXAPI FXMat4d operator/(FXdouble x,const FXMat4d& a);
00216 
00217 extern FXAPI FXbool operator==(const FXMat4d& a,FXdouble n);
00218 extern FXAPI FXbool operator==(FXdouble n,const FXMat4d& a);
00219 
00220 extern FXAPI FXbool operator!=(const FXMat4d& a,FXdouble n);
00221 extern FXAPI FXbool operator!=(FXdouble n,const FXMat4d& a);
00222 
00223 extern FXAPI FXStream& operator<<(FXStream& store,const FXMat4d& m);
00224 extern FXAPI FXStream& operator>>(FXStream& store,FXMat4d& m);
00225 
00226 }
00227 
00228 #endif

Copyright © 1997-2007 Jeroen van der Zijp