summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-05-17 16:34:05 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-05-17 16:34:05 +0200
commit3506d3df9f2e929def5b1662e08481d28643358f (patch)
tree88d79474f5a59941b568ddfd3170ee70cbfc0c35
parentcc150354fd91c05ef863137cdf53eb5a413d76b1 (diff)
Added stride and colors to BulletPattern.
-rw-r--r--bulletpattern.cpp7
-rw-r--r--bulletpattern.h3
-rw-r--r--main.cpp52
3 files changed, 54 insertions, 8 deletions
diff --git a/bulletpattern.cpp b/bulletpattern.cpp
index 1e8da5e..a2504f9 100644
--- a/bulletpattern.cpp
+++ b/bulletpattern.cpp
@@ -7,7 +7,8 @@
#include "bulletpattern.h"
BulletPattern::BulletPattern() {
- num_bullets = 0;
+ num_bullets = stride = color_g = color_b = 0;
+ color_r = 1;
bullets = new float[2048];
int k = 0;
@@ -33,10 +34,10 @@ void BulletPattern::update(unsigned int time, unsigned int step) {
void BulletPattern::draw() {
glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(4, GL_FLOAT, 4 * sizeof(float), bullets);
+ glVertexPointer(4, GL_FLOAT, 4 * sizeof(float) + stride, 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
index dffb928..092713e 100644
--- a/bulletpattern.h
+++ b/bulletpattern.h
@@ -5,7 +5,10 @@ class BulletPattern {
protected:
float* bullets;
int num_bullets;
+ int stride;
public:
+ float color_r, color_g, color_b;
+
BulletPattern();
virtual void update(unsigned int time, unsigned int step);
void draw();
diff --git a/main.cpp b/main.cpp
index 7248393..998adf0 100644
--- a/main.cpp
+++ b/main.cpp
@@ -20,11 +20,16 @@
#include "bullet.h"
#include "bulletpattern.h"
+const int width = 1280, height = 720;
+
class BulletPattern1 : public BulletPattern {
unsigned int base;
public:
BulletPattern1(bool reverse, unsigned int base) {
num_bullets = 0;
+ color_r = 1;
+ color_g = 0;
+ color_b = 1;
bullets = new float[128];
this->base = base;
@@ -39,6 +44,7 @@ class BulletPattern1 : public BulletPattern {
void update(unsigned int time, unsigned int step) {
if(num_bullets < 32 && base + num_bullets * 10 < time) {
num_bullets += time / 10 - num_bullets - base / 10;
+ if(num_bullets > 32) num_bullets = 32;
}
for(int i = 0; i < num_bullets; i++) {
bullets[i*4] += bullets[i*4 + 2] * step;
@@ -47,10 +53,41 @@ class BulletPattern1 : public BulletPattern {
}
};
+class BulletPattern2 : public BulletPattern {
+ public:
+ BulletPattern2(bool reverse, unsigned int base) {
+ num_bullets = 0;
+ color_r = 0;
+ color_g = 1;
+ color_b = 0;
+ stride = sizeof(float);
+ bullets = new float[32*5];
+
+ int j = 0;
+ for(float i = 0; i < M_PI; i += 0.1, j++) {
+ bullets[j*5] = 50.0 + sinf(!reverse ? M_PI_2 + i : M_PI - i + M_PI_2) * 9;
+ bullets[j*5 + 1] = 80 + cosf(M_PI_2 + i) * 10;
+ bullets[j*5 + 2] = sinf(!reverse ? M_PI_2 + i : M_PI - i + M_PI_2) / 150.0;
+ bullets[j*5 + 3] = -0.01;
+ bullets[j*5 + 4] = base + i * 100;
+ }
+
+ };
+ void update(unsigned int time, unsigned int step) {
+ while(num_bullets < 32 && (unsigned int)(bullets[num_bullets*5 + 4]) < time) {
+ num_bullets++;
+ }
+ for(int i = 0; i < num_bullets; i++) {
+ bullets[i*5] += bullets[i*5 + 2] * step;
+ bullets[i*5 + 1] += bullets[i*5 + 3] * step;
+ }
+ }
+};
+
bool fullscreen = false;
void toggle_fullscreen() {
fullscreen = !fullscreen;
- SDL_SetVideoMode(640, 480, 0, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE | SDL_HWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0));
+ SDL_SetVideoMode(width, height, 0, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE | SDL_HWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0));
}
int main(int, char**) {
@@ -59,7 +96,7 @@ int main(int, char**) {
return 1;
}
- SDL_Surface *surface = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE | SDL_HWSURFACE);
+ SDL_Surface *surface = SDL_SetVideoMode(width, height, 0, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE | SDL_HWSURFACE);
if(surface == NULL) {
fprintf(stderr, "Failed to set video mode: %s\n", SDL_GetError());
return 1;
@@ -92,7 +129,10 @@ int main(int, char**) {
patterns.push_back(new BulletPattern());
for(int i = 0; i < 8; i++) {
- patterns.push_back(new BulletPattern1(i % 2 == 1, i * 400));
+ patterns.push_back(new BulletPattern1(i % 2 == 1, 5000 + i * 400));
+ }
+ for(int i = 0; i < 8; i++) {
+ patterns.push_back(new BulletPattern2(i % 2 == 1, 9000 + i * 400));
}
TextureSDL texture1("foo.png");
@@ -143,7 +183,7 @@ int main(int, char**) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluPerspective(45, 640. / 480., 1, 100);
+ gluPerspective(45, (float)width / (float)height, 1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -196,7 +236,9 @@ int main(int, char**) {
glColor4f(1, 0, 0, 1);
for(std::vector<BulletPattern*>::iterator it = patterns.begin(); it < patterns.end(); it++) {
- (*it)->draw();
+ BulletPattern *bp = (*it);
+ glColor3f(bp->color_r, bp->color_g, bp->color_b);
+ bp->draw();
}
glDisable(GL_TEXTURE_2D);