00001
00006 #include <GL/gl.h>
00007
00008 #ifndef MATRIX_HH
00009 #define MATRIX_HH
00010
00016 template <unsigned int r, unsigned int c>
00017 class Matrix {
00018 public:
00020 Matrix();
00021
00023 bool isSquare() const { return r == c; }
00024
00029 void setIdentity();
00030
00035 void glMultiply() const { assert (r == c == 4); glMultMatrixd (me); }
00036
00038 double operator() (unsigned int i, unsigned int j) const
00039 { assert (i < r); assert (j < c); return data[i + r*j]; }
00040
00042 double& operator() (unsigned int i, unsigned int j)
00043 { assert (i < r); assert (j < c); return data[i + r*j]; }
00044
00046 const Matrix<r,c>& operator+= (const Matrix<r,c> &m);
00047
00049 const Matrix<r,c>& operator-= (const Matrix<r,c> &m);
00050
00052 const Matrix<r,c>& operator*= (double);
00053
00055 const Matrix<r,c>& operator/= (double);
00056
00057 private:
00063 double data[r*c];
00064 };
00065
00070 template <unsigned int a, unsigned int b, unsigned int c>
00071 Matrix<a,c> operator* (const Matrix<a,b>&, const Matrix<b,c>&);
00072
00077 template <unsigned int a, unsigned int b, unsigned int c>
00078 Matrix<a,c> operator/ (const Matrix<a,b>&, const Matrix<b,c>&);
00079
00080 #include "matrix.impl"
00081
00082 #endif