summaryrefslogtreecommitdiff
path: root/engine/bulletpattern.cpp
blob: b4b5a31869ab018e739d6dec6329a192a53015b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef __APPLE__
#include <GL/gl.h>
#else
#include <OpenGL/gl.h>
#endif
#include <cmath>
#include "bulletpattern.h"

BulletPattern::BulletPattern() {
	num_bullets = stride = color_g = color_b = 0;
	color_r = 1;
	bullets = new float[2048];
	
	int k = 0;
	
	for(float i = 0; i < M_PI * 16; i += 0.1) {
		bullets[k++] = 0.5 + cosf(i) * 0.05;
		bullets[k++] = 0.5 + sinf(i) * 0.05;
		bullets[k++] = cosf(i) / 10000.0;
		bullets[k++] = sinf(i) / 10000.0;
	}
}

void BulletPattern::update(unsigned int time, unsigned int step) {
	while(num_bullets < 503 && num_bullets * 4 < time) {
		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) + stride, bullets);
	
	glDrawArrays(GL_POINTS, 0, num_bullets);
	
	glDisableClientState(GL_VERTEX_ARRAY);
	
}