summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-05-24 03:12:17 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-05-24 03:12:17 +0200
commit8e92b0c5aa0cc57e8729069dad4cb635845f51d8 (patch)
tree544a434113ce7e82d636497c46048e81986fc8cb /engine
parent4ada43585c11eabd6aa94dcd7ab6d62952796a26 (diff)
Added Matrix-class.
Diffstat (limited to 'engine')
-rw-r--r--engine/matrix.cpp29
-rw-r--r--engine/matrix.h22
2 files changed, 51 insertions, 0 deletions
diff --git a/engine/matrix.cpp b/engine/matrix.cpp
new file mode 100644
index 0000000..96c539c
--- /dev/null
+++ b/engine/matrix.cpp
@@ -0,0 +1,29 @@
+#include "matrix.h"
+
+#include <cmath>
+
+Matrix2::Matrix2() {
+ m[0][0] = m[0][1] =
+ m[1][0] = m[1][1] = 0;
+}
+
+Matrix2::Matrix2(float m00, float m01, float m10, float m11) {
+ m[0][0] = m00;
+ m[0][1] = m01;
+ m[1][0] = m10;
+ m[1][1] = m11;
+}
+
+Vector2 Matrix2::operator*(const Vector2& v) {
+ return Vector2(
+ m[0][0] * v.x + m[0][1] * v.y,
+ m[1][0] * v.x + m[1][1] * v.y);
+}
+
+Matrix2 rotation_matrix(float rot) {
+ float s = sinf(rot);
+ float c = cosf(rot);
+ return Matrix2(
+ c, -s,
+ s, c);
+} \ No newline at end of file
diff --git a/engine/matrix.h b/engine/matrix.h
new file mode 100644
index 0000000..b6e4e3c
--- /dev/null
+++ b/engine/matrix.h
@@ -0,0 +1,22 @@
+#ifndef MATRIX_H
+#define MATRIX_H
+
+#include "vector.h"
+
+template<int M, int N>
+class Matrix {
+ public:
+ float m[M][N];
+};
+
+class Matrix2 : Matrix<2, 2> {
+ public:
+ Matrix2();
+ Matrix2(float m00, float m01, float m10, float m11);
+
+ Vector2 operator*(const Vector2& v);
+};
+
+Matrix2 rotation_matrix(float rot);
+
+#endif