#ifndef _MAT_H_ #define _MAT_H_ #include #include #include "vec.h" template class Vec; template class Mat; // some common vector classes (abbr. names) typedef Mat Mat2f; typedef Mat Mat3f; typedef Mat Mat4f; typedef Mat Mat2d; typedef Mat Mat3d; typedef Mat Mat4d; // template square matrix class for SIMPLE data types template class Mat { public: Mat () { for (unsigned int j=0; j () { // nothing to do here ... } Mat (const T aatData[SIZE][SIZE]) { for (unsigned int j=0; j (const T init_val,const T eye_val) { for (unsigned int j=0; j (const T init_val) { for (unsigned int j=0; j (const Mat &mat) { for (unsigned int j=0; j=SIZE) i = SIZE-1; if (j>=SIZE) j = SIZE-1; return m_aatData[i][j]; } T operator () (unsigned i, unsigned j) const { if (i>=SIZE) i = SIZE-1; if (j>=SIZE) j = SIZE-1; return m_aatData[i][j]; } Mat operator + (const T &scalar) { Mat buf; for (unsigned int i=0; i operator - (const T &scalar) { Mat buf; for (unsigned int i=0; i operator * (const T &scalar) { Mat buf; for (unsigned int i=0; i operator / (const T &scalar) { Mat buf; for (unsigned int i=0; i operator * (const Mat &mat) { Mat buf; for (unsigned int i=0; i &operator = (const T aatData[SIZE*SIZE]) { for (unsigned int i=0; i norm() { T buf; for (unsigned int i=0; i transpose() { Mat buf; for (unsigned int i=0; i inv() { T det = determinant(); if (det== 0) { return *this; } Mat thisTransposed = this->transpose(); thisTransposed/det; return thisTransposed; } private: T m_aatData[SIZE][SIZE]; }; template static std::ostream& operator<< (std::ostream& output,const Mat &mat) { output << "( "; for(unsigned int j =0; j< SIZE; ++j) { output << "( "; for(unsigned int i =0; i< SIZE; ++i) { output << mat(j,i); if (i<4-1) output << " , "; else output << " )"; } if (j getRotationMatrix(float x_angle,float y_angle, float z_angle) { Mat tempx,tempy,tempz; float temp_x[4][4] = { { 1, 0, 0, 0}, { 0, cos(x_angle), -sin(x_angle), 0}, { 0, sin(x_angle), cos(x_angle), 0}, { 0, 0, 0, 1} }; float temp_y[4][4] = { { cos(y_angle), 0, -sin(y_angle), 0}, { 0, 1, 0, 0}, { sin(y_angle), 0, cos(y_angle), 0}, { 0, 0, 0, 1} }; float temp_z[4][4] = { { cos(z_angle), -sin(z_angle), 0, 0}, { sin(z_angle), cos(z_angle), 0, 0}, { 0, 0, 1, 0}, { 0, 0, 0, 1} }; tempx=temp_x; tempy=temp_y; tempz=temp_z; return tempz*tempy*tempx; } #endif