I am starting to get familiar with the basics of OpenGL and decided that it is a good time to make a matrix class.
The following classes works as expected for transformations.
What else do I need to add to make it sufficient and generic enough for most future projects I'd do ?
(Keep in mind that the Matrix is in column major form.)
Code:template<typename T> class vector3 { public: T raw[3]; vector3(T x,T y,T z){raw[0]=x;raw[1]=y;raw[2]=z;} vector3(T* t){raw[0]=t[0];raw[1]=t[1];raw[2]=t[2];} vector3(std::initializer_list<T> t) { auto it = t.begin(); raw[0]=*(it++); raw[1]=*(it++); raw[2]=(*it++); }; const T& operator[](int n){return raw[n];} }; /*Reference: * [0][4][08][12] * [1][5][09][13] * [2][6][10][14] * [3][7][11][15] */ template<typename T> class matrix { public: T* raw; matrix(T unity)//Allocates an identity matrix { raw = new T[16];//May change this to allocate from a Allocator maintained pool raw[0]=raw[5]=raw[10]=raw[15]=unity; } matrix(){}; void translate(T x,T y,T z){raw[12]=x;raw[13]=y;raw[14]=z;} void transform(vector3<double> x,vector3<double> y, vector3<double> z) { //Only rotation and scaling raw[0]=x[0];raw[1]=x[1];raw [2]=x[2]; raw[4]=y[0];raw[5]=y[1];raw [6]=y[2]; raw[8]=z[0];raw[9]=z[1];raw[10]=z[2]; } };



LinkBack URL
About LinkBacks




