From 19bbd5822593c7198dd54eb0f5d38fa1ed8d8fb7 Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 18 Aug 2010 14:38:34 +0000 Subject: Reformatted code and altered the attraction rule to something a bit more correct. Also added two tests to prove it works. --- matrix.h | 74 +++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 33 deletions(-) (limited to 'matrix.h') diff --git a/matrix.h b/matrix.h index d1f5db2..a63e36a 100644 --- a/matrix.h +++ b/matrix.h @@ -30,51 +30,59 @@ #include "global.h" template class Matrix +{ +public: + Matrix() { - public: - Matrix() - { - int a,b; - - for(a=0;a<3;a++) - for(b=0;b<3;b++) - mat[a][b]=0; - } + int a,b; - ~Matrix() + for(a=0;a<3;a++) { + for(b=0;b<3;b++) + { + mat[a][b]=0; + } } + } - void identity() - { - int a,b; + ~Matrix() + { + } - for(a=0;a<3;a++) - for(b=0;b<3;b++) - mat[a][b]=(a==b) ? 1:0; - } + void identity() + { + int a,b; - void set(Ty x, Ty y, Ty z) + for(a=0;a<3;a++) { - identity(); - mat[0][0]=x; - mat[1][1]=y; - mat[2][2]=z; - mat[3][3]=1; + for(b=0;b<3;b++) + { + mat[a][b]=(a==b) ? 1:0; + } } + } - void get(Ty& x, Ty& y, Ty& z) - { - x=mat[0][0]; - y=mat[1][1]; - z=mat[2][2]; - } + void set(Ty x, Ty y, Ty z) + { + identity(); + mat[0][0] = x; + mat[1][1] = y; + mat[2][2] = z; + mat[3][3] = 1; + } + + void get(Ty& x, Ty& y, Ty& z) + { + x = mat[0][0]; + y = mat[1][1]; + z = mat[2][2]; + } - Matrix& operator*(Matrix& m); + Matrix& operator*(Matrix& m); - private: - Ty mat[4][4]; - }; +private: + Ty mat[4][4]; +}; #endif -- cgit v1.2.3