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