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.9 2002/01/18 22:42:53 jeroen Exp $                          *
00023 ********************************************************************************/
00024 #ifndef FXHMAT_H
00025 #define FXHMAT_H
00026 
00027 
00028 /// Homogeneous matrix (single-precision version)
00029 class FXAPI FXHMat {
00030 protected:
00031   FXHVec m[4];
00032 public:
00033   /// Constructors
00034   FXHMat(){}
00035   FXHMat(FXfloat w);
00036   FXHMat(FXfloat a00,FXfloat a01,FXfloat a02,FXfloat a03,
00037          FXfloat a10,FXfloat a11,FXfloat a12,FXfloat a13,
00038          FXfloat a20,FXfloat a21,FXfloat a22,FXfloat a23,
00039          FXfloat a30,FXfloat a31,FXfloat a32,FXfloat a33);
00040   FXHMat(const FXHVec& a,const FXHVec& b,const FXHVec& c,const FXHVec& d);
00041   FXHMat(const FXHMat& other);
00042 
00043   /// Assignment operators
00044   FXHMat& operator=(const FXHMat& other);
00045   FXHMat& operator=(FXfloat w);
00046   FXHMat& operator+=(const FXHMat& w);
00047   FXHMat& operator-=(const FXHMat& w);
00048   FXHMat& operator*=(FXfloat w);
00049   FXHMat& operator*=(const FXHMat& w);
00050   FXHMat& operator/=(FXfloat w);
00051 
00052   /// Indexing
00053   FXHVec& operator[](FXint i){return m[i];}
00054   const FXHVec& operator[](FXint i) const {return m[i];}
00055 
00056   /// Conversion
00057   operator FXfloat*(){return m[0];}
00058   operator const FXfloat*() const {return m[0];}
00059 
00060   /// Other operators
00061   friend FXAPI FXHMat operator+(const FXHMat& a,const FXHMat& b);
00062   friend FXAPI FXHMat operator-(const FXHMat& a,const FXHMat& b);
00063   friend FXAPI FXHMat operator-(const FXHMat& a);
00064   friend FXAPI FXHMat operator*(const FXHMat& a,const FXHMat& b);
00065   friend FXAPI FXHMat operator*(FXfloat x,const FXHMat& a);
00066   friend FXAPI FXHMat operator*(const FXHMat& a,FXfloat x);
00067   friend FXAPI FXHMat operator/(const FXHMat& a,FXfloat x);
00068   friend FXAPI FXHMat operator/(FXfloat x,const FXHMat& a);
00069 
00070   /// Multiply matrix and vector
00071   friend FXAPI FXHVec operator*(const FXHVec& v,const FXHMat& m);
00072   friend FXAPI FXHVec operator*(const FXHMat& a,const FXHVec& v);
00073 
00074   /// Mutiply matrix and vector, for non-projective matrix
00075   friend FXAPI FXVec operator*(const FXVec& v,const FXHMat& m);
00076   friend FXAPI FXVec operator*(const FXHMat& a,const FXVec& v);
00077 
00078   /// Set identity matrix
00079   FXHMat& eye();
00080 
00081   /// Orthographic projection
00082   FXHMat& ortho(FXfloat left,FXfloat right,FXfloat bottom,FXfloat top,FXfloat hither,FXfloat yon);
00083 
00084   /// Perspective projection
00085   FXHMat& frustum(FXfloat left,FXfloat right,FXfloat bottom,FXfloat top,FXfloat hither,FXfloat yon);
00086 
00087   /// Multiply by left-hand matrix
00088   FXHMat& left();
00089 
00090   /// Multiply by rotation about unit-quaternion
00091   FXHMat& rot(const FXQuat& q);
00092 
00093   /// Multiply by rotation c,s about axis
00094   FXHMat& rot(const FXVec& v,FXfloat c,FXfloat s);
00095 
00096   /// Multiply by rotation of phi about axis
00097   FXHMat& rot(const FXVec& v,FXfloat phi);
00098 
00099   /// Multiply by x-rotation
00100   FXHMat& xrot(FXfloat c,FXfloat s);
00101   FXHMat& xrot(FXfloat phi);
00102 
00103   /// Multiply by y-rotation
00104   FXHMat& yrot(FXfloat c,FXfloat s);
00105   FXHMat& yrot(FXfloat phi);
00106 
00107   /// Multiply by z-rotation
00108   FXHMat& zrot(FXfloat c,FXfloat s);
00109   FXHMat& zrot(FXfloat phi);
00110 
00111   /// Look at
00112   FXHMat& look(const FXVec& eye,const FXVec& cntr,const FXVec& vup);
00113 
00114   /// Multiply by translation
00115   FXHMat& trans(FXfloat tx,FXfloat ty,FXfloat tz);
00116   FXHMat& trans(const FXVec& v);
00117 
00118   /// Multiply by scaling
00119   FXHMat& scale(FXfloat sx,FXfloat sy,FXfloat sz);
00120   FXHMat& scale(FXfloat s);
00121   FXHMat& scale(const FXVec& v);
00122 
00123   /// Determinant
00124   friend FXAPI FXfloat det(const FXHMat& m);
00125 
00126   /// Transpose
00127   friend FXAPI FXHMat transpose(const FXHMat& m);
00128 
00129   /// Invert
00130   friend FXAPI FXHMat invert(const FXHMat& m);
00131 
00132   /// Save to a stream
00133   friend FXAPI FXStream& operator<<(FXStream& store,const FXHMat& m);
00134 
00135   /// Load from a stream
00136   friend FXAPI FXStream& operator>>(FXStream& store,FXHMat& m);
00137   };
00138 
00139 #endif