summaryrefslogtreecommitdiff
path: root/particle.h
blob: 433b557dd0a77b11535a17db77dc2c510cfe1b83 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef PARTICLE_H
#define PARTICLE_H

#include "vector.h"

#include <list>

struct vec4f {
	float x, y, z, w;
};

class SelectionParticle {
	public:
		Vector3 pos;
		float alpha;
		float decay;
		static float t;
		float pt;
		float speed;
		Vector3 vel;

		SelectionParticle();
		SelectionParticle(const SelectionParticle& p);

		void init(float seed);
		void update(unsigned int steps, vec4f *v);
};

template<class T>
class ParticleGroup {
	public:
		T *particles;
		vec4f *vertices;
		unsigned int num;
		unsigned int count;
		Vector3 src;
		Vector3 dir;

		ParticleGroup(Vector3 src, Vector3 dir, unsigned int count) {
			srand(time(NULL));
			this->src = src;
			this->dir = dir;
			this->num = count;
			this->count = 0;
			T::t = 0;
			particles = new T[count];
			vertices = new vec4f[count];
		};
		~ParticleGroup() {
			delete[] particles;
			delete[] vertices;
		}

		void update(unsigned int steps) {
			if(count < num) {
				particles[count].init(T::t += 0.1);
				count++;
			}
			for(unsigned int i = 0; i < count; i++) {
				T *p = &particles[i];
				p->update(steps, &vertices[i]);
			}
		}
};

#endif