-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticlesystem.h
79 lines (57 loc) · 1.76 KB
/
particlesystem.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef PARTICLESYSTEM_H
#define PARTICLESYSTEM_H
#include "geometry.h"
#include "sceneobject.h"
struct Particle
{
// These rendering related properties must be declared first in this order
vec3 position;
float rotation = 0; // in angle
float size = 1;
Color color = vec3(1.f, 1.f, 1.f);
float opacity = 1.f;
// Other properties
float life = 0;
float maxLife = 0;
bool active = true;
vec3 velocity;
float angularSpeed = 0;
};
typedef vector<Particle> Particles;
enum class RenderingOrder {
Default,
Reversed,
OldestFirst,
YoungestFirst,
};
class ParticleSystem : public SceneObject
{
public:
ParticleSystem();
virtual ~ParticleSystem();
virtual void renderGeometry(DrawContext &context) override;
virtual void update(float dt);
// to be overrided
virtual void spawnParticle(Particle *particle);
// to be overrided
virtual void updateParticle(Particle& particle, float dt);
void setParticleTexture(Texture* texture);
uint32_t emissionRate() const;
void setEmissionRate(int emissionRate);
uint32_t maxParticleCount() const;
void setMaxParticleCount(int maxParticleCount);
RenderingOrder renderingOrder() const;
void setRenderingOrder(RenderingOrder renderingOrder);
protected:
vector<Particle> particles_;
private:
// time elapsed since the particle system was created
float timeElapsed_ = 0;
// max number of particles allowed
uint32_t maxParticleCount_ = 0;
// number of particles per second
uint32_t emissionRate_ = 0;
float numParticlesToSpawn_ = 0;
RenderingOrder renderingOrder_ = RenderingOrder::Reversed;
};
#endif // PARTICLESYSTEM_H