summaryrefslogtreecommitdiffstats
path: root/Matrix.h
diff options
context:
space:
mode:
Diffstat (limited to 'Matrix.h')
-rw-r--r--Matrix.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/Matrix.h b/Matrix.h
new file mode 100644
index 0000000..f8c178f
--- /dev/null
+++ b/Matrix.h
@@ -0,0 +1,45 @@
+#ifndef _MATRIX_H_
+#define _MATRIX_H_
+
+#include "gl.h"
+#include "Vector.h"
+#include "Vertex.h"
+
+class Matrix
+{
+ public:
+ Matrix(GLenum pname = GL_MODELVIEW_MATRIX) {
+ store(pname);
+ }
+
+ Matrix(float in[16]) {
+ for(int i = 0; i < 16; ++i)
+ f[i] = in[i];
+ }
+
+ Vertex operator*(const Vertex &v) const {
+ Vector r(v.getX()*m[0][0] + v.getY()*m[1][0] + v.getZ()*m[2][0] + m[3][0],
+ v.getX()*m[0][1] + v.getY()*m[1][1] + v.getZ()*m[2][1] + m[3][1],
+ v.getX()*m[0][2] + v.getY()*m[1][2] + v.getZ()*m[2][2] + m[3][2]);
+ float w = v.getX()*m[0][3] + v.getY()*m[1][3] + v.getZ()*m[2][3] + m[3][3];
+
+ return r/w;
+ }
+
+ void load() {
+ glLoadMatrixf(f);
+ }
+
+ void store(GLenum pname = GL_MODELVIEW_MATRIX) {
+ glGetFloatv(pname, f);
+ }
+
+ private:
+ union {
+ float f[16];
+ float m[4][4];
+ };
+};
+
+#endif /*_MATRIX_H_*/
+