f@0
|
1 #pragma once
|
f@0
|
2
|
f@0
|
3 #include "cinder/gl/gl.h"
|
f@0
|
4 #include <vector>
|
f@0
|
5
|
f@3
|
6 /**
|
f@3
|
7 * The ParticleController creates/updates/draws and destroys particles
|
f@3
|
8 */
|
f@0
|
9 class ParticleController {
|
f@0
|
10
|
f@0
|
11 struct Particle {
|
f@0
|
12
|
f@4
|
13 ci::vec2 mCloudCenter; // initial positin of the particle
|
f@4
|
14 ci::vec2 mVel; // velocity
|
f@4
|
15 float mCloudSize; // how big is the area where particle float around. When a particle hits the
|
f@4
|
16 // border of the area it gets deflected
|
f@0
|
17
|
f@4
|
18 int mAge; // when mAge == mLifeSpan the particle is disposed
|
f@4
|
19 int mLifespan; // how long a particle lives
|
f@4
|
20 bool mFlyOver; // some particles last longer and fly over the screen and reach the other user
|
f@0
|
21
|
f@0
|
22 };
|
f@0
|
23
|
f@0
|
24 static const int kMaxParticles = 150;
|
f@0
|
25
|
f@0
|
26 std::vector<Particle> mParticles;
|
f@0
|
27 std::vector< ci::vec2 > mParticlePositions;
|
f@0
|
28
|
f@3
|
29 // current number of active particles
|
f@0
|
30 size_t mNumParticles;
|
f@0
|
31
|
f@4
|
32 ci::gl::VboRef mParticleVbo; // virtual buffer object
|
f@0
|
33 ci::gl::BatchRef mParticleBatch;
|
f@0
|
34
|
f@0
|
35 public:
|
f@3
|
36 /**
|
f@3
|
37 * Every time addParticles is run, up to kMaxParticleAdd are added at once
|
f@3
|
38 */
|
f@0
|
39 static const int kMaxParticleAdd = 22;
|
f@0
|
40
|
f@0
|
41 ParticleController();
|
f@3
|
42
|
f@3
|
43 /**
|
f@3
|
44 * Adds \a amount particles and places them in \a initialLocation.
|
f@3
|
45 * \cloudSize determines how far the particles can go
|
f@3
|
46 */
|
f@0
|
47 void addParticles(int amount, const ci::vec2 &initialLocation, const float cloudSize);
|
f@0
|
48
|
f@3
|
49 /**
|
f@3
|
50 * Updates position and age of the particles
|
f@3
|
51 */
|
f@0
|
52 void updateParticles();
|
f@0
|
53
|
f@3
|
54 /**
|
f@3
|
55 * Draws all the particles
|
f@3
|
56 */
|
f@0
|
57 inline void draw()
|
f@0
|
58 {
|
f@0
|
59 mParticleBatch->draw();
|
f@0
|
60 }
|
f@0
|
61
|
f@0
|
62 };
|
f@0
|
63
|