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

FXHMat.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *            H o m o g e n e o u s   M a t r i x   O p e r a t i o n s          *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1994,2002 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXHMat.h,v 1.11 2002/03/12 07:11:30 fox Exp $                            *
00023 ********************************************************************************/
00024 #ifndef FXHMAT_H
00025 #define FXHMAT_H
00026 
00027 namespace FX {
00028 
00029 /// Homogeneous matrix (single-precision version)
00030 class FXAPI FXHMat {
00031 protected:
00032   FXHVec m[4];
00033 public:
00034   /// Constructors
00035   FXHMat(){}
00036   FXHMat(FXfloat w);
00037   FXHMat(FXfloat a00,FXfloat a01,FXfloat a02,FXfloat a03,
00038          FXfloat a10,FXfloat a11,FXfloat a12,FXfloat a13,
00039          FXfloat a20,FXfloat a21,FXfloat a22,FXfloat a23,
00040          FXfloat a30,FXfloat a31,FXfloat a32,FXfloat a33);
00041   FXHMat(const FXHVec& a,const FXHVec& b,const FXHVec& c,const FXHVec& d);
00042   FXHMat(const FXHMat& other);
00043 
00044   /// Assignment operators
00045   FXHMat& operator=(const FXHMat& other);
00046   FXHMat& operator=(FXfloat w);
00047   FXHMat& operator+=(const FXHMat& w);
00048   FXHMat& operator-=(const FXHMat& w);
00049   FXHMat& operator*=(FXfloat w);
00050   FXHMat& operator*=(const FXHMat& w);
00051   FXHMat& operator/=(FXfloat w);
00052 
00053   /// Indexing
00054   FXHVec& operator[](FXint i){return m[i];}
00055   const FXHVec& operator[](FXint i) const {return m[i];}
00056 
00057   /// Conversion
00058   operator FXfloat*(){return m[0];}
00059   operator const FXfloat*() const {return m[0];}
00060 
00061   /// Other operators
00062   friend FXAPI FXHMat operator+(const FXHMat& a,const FXHMat& b);
00063   friend FXAPI FXHMat operator-(const FXHMat& a,const FXHMat& b);
00064   friend FXAPI FXHMat operator-(const FXHMat& a);
00065   friend FXAPI FXHMat operator*(const FXHMat& a,const FXHMat& b);
00066   friend FXAPI FXHMat operator*(FXfloat x,const FXHMat& a);
00067   friend FXAPI FXHMat operator*(const FXHMat& a,FXfloat x);
00068   friend FXAPI FXHMat operator/(const FXHMat& a,FXfloat x);
00069   friend FXAPI FXHMat operator/(FXfloat x,const FXHMat& a);
00070 
00071   /// Multiply matrix and vector
00072   friend FXAPI FXHVec operator*(const FXHVec& v,const FXHMat& m);
00073   friend FXAPI FXHVec operator*(const FXHMat& a,const FXHVec& v);
00074 
00075   /// Mutiply matrix and vector, for non-projective matrix
00076   friend FXAPI FXVec operator*(const FXVec& v,const FXHMat& m);
00077   friend FXAPI FXVec operator*(const FXHMat& a,const FXVec& v);
00078 
00079   /// Set identity matrix
00080   FXHMat& eye();
00081 
00082   /// Orthographic projection
00083   FXHMat& ortho(FXfloat left,FXfloat right,FXfloat bottom,FXfloat top,FXfloat hither,FXfloat yon);
00084 
00085   /// Perspective projection
00086   FXHMat& frustum(FXfloat left,FXfloat right,FXfloat bottom,FXfloat top,FXfloat hither,FXfloat yon);
00087 
00088   /// Multiply by left-hand matrix
00089   FXHMat& left();
00090 
00091   /// Multiply by rotation about unit-quaternion
00092   FXHMat& rot(const FXQuat& q);
00093 
00094   /// Multiply by rotation c,s about axis
00095   FXHMat& rot(const FXVec& v,FXfloat c,FXfloat s);
00096 
00097   /// Multiply by rotation of phi about axis
00098   FXHMat& rot(const FXVec& v,FXfloat phi);
00099 
00100   /// Multiply by x-rotation
00101   FXHMat& xrot(FXfloat c,FXfloat s);
00102   FXHMat& xrot(FXfloat phi);
00103 
00104   /// Multiply by y-rotation
00105   FXHMat& yrot(FXfloat c,FXfloat s);
00106   FXHMat& yrot(FXfloat phi);
00107 
00108   /// Multiply by z-rotation
00109   FXHMat& zrot(FXfloat c,FXfloat s);
00110   FXHMat& zrot(FXfloat phi);
00111 
00112   /// Look at
00113   FXHMat& look(const FXVec& eye,const FXVec& cntr,const FXVec& vup);
00114 
00115   /// Multiply by translation
00116   FXHMat& trans(FXfloat tx,FXfloat ty,FXfloat tz);
00117   FXHMat& trans(const FXVec& v);
00118 
00119   /// Multiply by scaling
00120   FXHMat& scale(FXfloat sx,FXfloat sy,FXfloat sz);
00121   FXHMat& scale(FXfloat s);
00122   FXHMat& scale(const FXVec& v);
00123 
00124   /// Determinant
00125   friend FXAPI FXfloat det(const FXHMat& m);
00126 
00127   /// Transpose
00128   friend FXAPI FXHMat transpose(const FXHMat& m);
00129 
00130   /// Invert
00131   friend FXAPI FXHMat invert(const FXHMat& m);
00132 
00133   /// Save to a stream
00134   friend FXAPI FXStream& operator<<(FXStream& store,const FXHMat& m);
00135 
00136   /// Load from a stream
00137   friend FXAPI FXStream& operator>>(FXStream& store,FXHMat& m);
00138   };
00139 
00140 }
00141 
00142 #endif