summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bulletpattern.cpp42
-rw-r--r--bulletpattern.h14
-rw-r--r--main.cpp24
3 files changed, 70 insertions, 10 deletions
diff --git a/bulletpattern.cpp b/bulletpattern.cpp
new file mode 100644
index 0000000..1e8da5e
--- /dev/null
+++ b/bulletpattern.cpp
@@ -0,0 +1,42 @@
+#ifndef __APPLE__
+#include <GL/gl.h>
+#else
+#include <OpenGL/gl.h>
+#endif
+#include <cmath>
+#include "bulletpattern.h"
+
+BulletPattern::BulletPattern() {
+ num_bullets = 0;
+ bullets = new float[2048];
+
+ int k = 0;
+
+ for(float i = 0; i < M_PI * 16; i += 0.1) {
+ bullets[k++] = 50.0 + cosf(i) * 5;
+ bullets[k++] = 50.0 + sinf(i) * 5;
+ bullets[k++] = cosf(i) / 100.0;
+ bullets[k++] = sinf(i) / 100.0;
+ }
+}
+
+void BulletPattern::update(unsigned int time, unsigned int step) {
+ if(num_bullets < 503 && num_bullets * 4 < time) {
+ num_bullets += time / 4 - num_bullets;
+ }
+ for(int i = 0; i < num_bullets; i++) {
+ bullets[i*4] += bullets[i*4 + 2] * step;
+ bullets[i*4 + 1] += bullets[i*4 + 3] * step;
+ }
+}
+
+void BulletPattern::draw() {
+ glEnableClientState(GL_VERTEX_ARRAY);
+
+ glVertexPointer(4, GL_FLOAT, 4 * sizeof(float), bullets);
+
+ glDrawArrays(GL_POINTS, 0, num_bullets);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+
+} \ No newline at end of file
diff --git a/bulletpattern.h b/bulletpattern.h
new file mode 100644
index 0000000..50d5844
--- /dev/null
+++ b/bulletpattern.h
@@ -0,0 +1,14 @@
+#ifndef BULLETPATTERN_H
+#define BULLETPATTERN_H
+
+class BulletPattern {
+ protected:
+ float* bullets;
+ int num_bullets;
+ public:
+ BulletPattern();
+ void update(unsigned int time, unsigned int step);
+ void draw();
+};
+
+#endif
diff --git a/main.cpp b/main.cpp
index 65a3b9e..7cba083 100644
--- a/main.cpp
+++ b/main.cpp
@@ -18,6 +18,7 @@
#include "shader.h"
#include "vector.h"
#include "bullet.h"
+#include "bulletpattern.h"
class BulletAdder {
public:
@@ -57,14 +58,7 @@ void create_pattern1(unsigned int base) {
}
void create_pattern2(unsigned int base) {
- for(float i = 0; i < M_PI * 16; i += 0.1) {
- bullets_queue.push(BulletAdder(base + (unsigned int)(i*40),
- Bullet(
- Vector3(50.0 + cosf(i) * 5,
- 50.0 + sinf(i) * 5, 0),
- Vector3(cosf(i) / 100.0, sinf(i) / 100.0, 0),
- 5)));
- }
+
}
void create_pattern2_2(unsigned int base) {
@@ -131,6 +125,8 @@ int main(int, char**) {
glShadeModel(GL_SMOOTH);
create_bullets();
+
+ BulletPattern* pattern = new BulletPattern();
TextureSDL texture1("foo.png");
TextureSDL texture2("foo4.png");
@@ -195,7 +191,9 @@ int main(int, char**) {
bullets_queue.pop();
bullets.push_back(bullet);
}
+ pattern->update(elapsed, step);
}
+
gluLookAt(
5 * sinf(f), 1, 5 * cosf(f),
0, 0, 0,
@@ -228,6 +226,13 @@ int main(int, char**) {
glPointSize(16.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture2.tex());
+
+ glColor4f(1, 0, 0, 1);
+
+ pattern->draw();
+
+ glColor4f(0, 1, 0, 1);
+
glBegin(GL_POINTS);
for(it = bullets.begin(); it != bullets.end();) {
Bullet& b = (*it);
@@ -238,9 +243,8 @@ int main(int, char**) {
b.pos.z += b.direction.z * step;
}
- glColor4f(0, 1, 0, 1);
-
glVertex4f(b.pos.x, b.pos.y, b.direction.x, b.direction.y);
+
//glColor3f(b.color.r, b.color.g, b.color.b);
/*glTexCoord2f(0, 0);
glVertex3f(b.pos.x-1, b.pos.y-1, b.pos.z);