Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

math/matrix4.h

Go to the documentation of this file.
00001 #ifndef MATH_MATRIX4_H
00002 #define MATH_MATRIX4_H
00003 
00004 /*
00005 
00006   GLT OpenGL C++ Toolkit (LGPL)
00007   Copyright (C) 2000-2002 Nigel Stewart  
00008 
00009   Email: nigels.com@gmail.com   
00010   WWW:   http://www.nigels.com/glt/
00011 
00012   This library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU Lesser General Public
00014   License as published by the Free Software Foundation; either
00015   version 2.1 of the License, or (at your option) any later version.
00016 
00017   This library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020   Lesser General Public License for more details.
00021 
00022   You should have received a copy of the GNU Lesser General Public
00023   License along with this library; if not, write to the Free Software
00024   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 */
00027 
00033 #include <iosfwd>
00034 
00035 #include <math/real.h>
00036 #include <math/vector3.h>
00037 
00039 
00047 class UnMatrix;
00048 
00049 class Matrix
00050 {
00051     friend Matrix matrixScale(const double sf);
00052     friend Matrix matrixScale(const Vector sf);
00053     friend Matrix matrixTranslate(const Vector trans);
00054     friend Matrix matrixTranslate(const real x,const real y,const real z);
00055     friend Matrix matrixRotate(const Vector axis,const double angle);
00056     friend Matrix matrixRotate(const double azimuth,const double elevation);
00057     friend Matrix matrixOrient(const Vector &x,const Vector &y,const Vector &z);
00058     friend Matrix matrixOrient(const Vector &direction,const Vector &up);
00059 
00060     friend std::ostream &operator<<(std::ostream &os,const Matrix &m);
00061     friend std::istream &operator>>(std::istream &is,      Matrix &m);
00062 
00063 public:
00064 
00066     Matrix();
00068     Matrix(const Matrix &matrix);
00070     Matrix(const float *matrix);
00072     Matrix(const double *matrix);
00074     Matrix(const unsigned int glMatrix);
00076     Matrix(const std::string &str);
00077 
00079     Matrix &operator=(const Matrix &);
00080 
00082     Matrix  operator*(const Matrix &) const;
00084     Matrix &operator*=(const Matrix &);
00085 
00087     Vector operator*(const Vector &) const;
00088 
00090     void reset();
00092     void identity();
00093 
00095     bool isIdentity() const;
00096 
00098           double &operator[](const int i);
00100     const double &operator[](const int i) const;
00101 
00103     operator double * ();
00105     operator const double * () const;
00106 
00108     bool operator==(const Matrix &) const;
00110     bool operator!=(const Matrix &) const;
00111 
00113     Matrix inverse() const;
00115     Matrix transpose() const;
00117     UnMatrix unmatrix() const;
00119     double det() const;
00120 
00122     void glMultMatrix() const;
00124     void glLoadMatrix() const;
00125 
00127     std::ostream &writePov(std::ostream &os) const;
00128 
00129 private:
00130 
00131     double _matrix[16];
00132     static double _identity[16];
00133 
00134     inline void set(const int col,const int row,const double val) 
00135     { 
00136         _matrix[col*4+row] = val;
00137     }
00138 
00139     inline double get(const int col,const int row) const
00140     {
00141         return _matrix[col*4+row];
00142     }
00143 
00144     inline double &element(const int col,const int row) 
00145     {
00146         return _matrix[col*4+row];
00147     }
00148 
00149     // From Mesa-2.2\src\glu\project.c
00150 
00151     static void invertMatrixGeneral( const double *m, double *out );
00152     static void invertMatrix( const double *m, double *out );
00153 
00154     // From Graphics Gems GEMSI\MATINV.C
00155 
00156     double 
00157     det3x3
00158     ( 
00159         const double a1, 
00160         const double a2, 
00161         const double a3, 
00162         const double b1, 
00163         const double b2, 
00164         const double b3, 
00165         const double c1, 
00166         const double c2, 
00167         const double c3 
00168     ) const;
00169 
00170     double
00171     det2x2
00172     ( 
00173         const double a, 
00174         const double b, 
00175         const double c, 
00176         const double d
00177     ) const;
00178 };
00179 
00180 #endif

Generated on Tue Nov 5 11:11:04 2002 for GLT by doxygen1.2.18