From 5c21b67a04bd847d7f04042a0ddc0bc4629d20e7 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 24 May 2010 16:17:06 +0200 Subject: Added matrix-matrix and matrix-constant multiplication. --- engine/bulletpattern.cpp | 9 +++++---- engine/matrix.cpp | 16 ++++++++++++++++ engine/matrix.h | 4 ++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/engine/bulletpattern.cpp b/engine/bulletpattern.cpp index 6ed4322..39f6742 100644 --- a/engine/bulletpattern.cpp +++ b/engine/bulletpattern.cpp @@ -99,8 +99,8 @@ BulletPattern4::BulletPattern4(const Vector2& initpos) { for(int j = 0; j < 24; j++) { for(float i = 0; i < 2 * M_PI; i += 0.4, k++) { bullets[k].pos = initpos; - bullets[k].dir.x = cosf(i) / 40; - bullets[k].dir.y = sinf(i) / 40; + bullets[k].dir.x = cosf(i) * 0.002; + bullets[k].dir.y = sinf(i) * 0.002; bullets[k].data.a = j * 10; bullets[k].data.b = i; } @@ -112,9 +112,10 @@ void BulletPattern4::update() { while(num_bullets < 384 && (unsigned int)(bullets[num_bullets].data.a) < steps) { num_bullets++; } + + Matrix2 m = rotation_matrix(cos(steps * 0.010) * 0.005); + for(int i = 0; i < num_bullets; i++) { - float l = log1pf((steps - bullets[i].data.a)); - Matrix2 m = rotation_matrix(l); bullets[i].dir = m * bullets[i].dir; bullets[i].pos += bullets[i].dir; } diff --git a/engine/matrix.cpp b/engine/matrix.cpp index 96c539c..5970123 100644 --- a/engine/matrix.cpp +++ b/engine/matrix.cpp @@ -14,6 +14,22 @@ Matrix2::Matrix2(float m00, float m01, float m10, float m11) { m[1][1] = m11; } +Matrix2 Matrix2::operator*(const Matrix2& mat) { + return Matrix2( + m[0][0] * mat.m[0][0] + m[0][1] * mat.m[1][0], + m[0][0] * mat.m[0][1] + m[0][1] * mat.m[1][1], + m[1][0] * mat.m[0][0] + m[1][1] * mat.m[1][0], + m[1][0] * mat.m[0][1] + m[1][1] * mat.m[1][1]); +} + +Matrix2 Matrix2::operator*(float f) { + return Matrix2( + m[0][0] * f, + m[0][1] * f, + m[1][0] * f, + m[1][1] * f); +} + Vector2 Matrix2::operator*(const Vector2& v) { return Vector2( m[0][0] * v.x + m[0][1] * v.y, diff --git a/engine/matrix.h b/engine/matrix.h index b6e4e3c..8be483a 100644 --- a/engine/matrix.h +++ b/engine/matrix.h @@ -14,6 +14,10 @@ class Matrix2 : Matrix<2, 2> { Matrix2(); Matrix2(float m00, float m01, float m10, float m11); + Matrix2 operator*(const Matrix2& mat); + + Matrix2 operator*(float f); + Vector2 operator*(const Vector2& v); }; -- cgit v1.2.3