summaryrefslogtreecommitdiff
path: root/matrix.h
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2010-08-18 14:38:34 +0000
committerIan C <ianc@noddybox.co.uk>2010-08-18 14:38:34 +0000
commit19bbd5822593c7198dd54eb0f5d38fa1ed8d8fb7 (patch)
tree97f7f8849c3a8282ba571a64ff2a655cdf5d41aa /matrix.h
parent0d2f672482fee91a9642a7cb6eb01fcdded79159 (diff)
Reformatted code and altered the attraction rule to something a bit more
correct. Also added two tests to prove it works.
Diffstat (limited to 'matrix.h')
-rw-r--r--matrix.h74
1 files changed, 41 insertions, 33 deletions
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 Ty> 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<Ty>& m);
+ Matrix& operator*(Matrix<Ty>& m);
- private:
- Ty mat[4][4];
- };
+private:
+ Ty mat[4][4];
+};
#endif