00001 #ifndef MATH_MATRIX4_H
00002 #define MATH_MATRIX4_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00150
00151 static void invertMatrixGeneral( const double *m, double *out );
00152 static void invertMatrix( const double *m, double *out );
00153
00154
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