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