f@5
|
1 /*
|
f@5
|
2
|
f@5
|
3 Copyright (C) 2015 Fiore Martin
|
f@5
|
4 Copyright (C) 2016 Queen Mary University of London
|
f@5
|
5 Author: Fiore Martin
|
f@5
|
6
|
f@5
|
7 This file is part of Collidoscope.
|
f@5
|
8
|
f@5
|
9 Collidoscope is free software: you can redistribute it and/or modify
|
f@5
|
10 it under the terms of the GNU General Public License as published by
|
f@5
|
11 the Free Software Foundation, either version 3 of the License, or
|
f@5
|
12 (at your option) any later version.
|
f@5
|
13
|
f@5
|
14 This program is distributed in the hope that it will be useful,
|
f@5
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
f@5
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
f@5
|
17 GNU General Public License for more details.
|
f@5
|
18
|
f@5
|
19 You should have received a copy of the GNU General Public License
|
f@5
|
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
f@5
|
21
|
f@5
|
22 */
|
f@5
|
23
|
f@0
|
24 #pragma once
|
f@0
|
25
|
f@0
|
26 #include "cinder/gl/gl.h"
|
f@0
|
27 #include <vector>
|
f@0
|
28
|
f@3
|
29 /**
|
f@3
|
30 * The ParticleController creates/updates/draws and destroys particles
|
f@3
|
31 */
|
f@0
|
32 class ParticleController {
|
f@0
|
33
|
f@0
|
34 struct Particle {
|
f@0
|
35
|
f@4
|
36 ci::vec2 mCloudCenter; // initial positin of the particle
|
f@4
|
37 ci::vec2 mVel; // velocity
|
f@4
|
38 float mCloudSize; // how big is the area where particle float around. When a particle hits the
|
f@16
|
39 // border of the area it gets deflected
|
f@0
|
40
|
f@4
|
41 int mAge; // when mAge == mLifeSpan the particle is disposed
|
f@4
|
42 int mLifespan; // how long a particle lives
|
f@4
|
43 bool mFlyOver; // some particles last longer and fly over the screen and reach the other user
|
f@0
|
44
|
f@0
|
45 };
|
f@0
|
46
|
f@0
|
47 static const int kMaxParticles = 150;
|
f@0
|
48
|
f@0
|
49 std::vector<Particle> mParticles;
|
f@0
|
50 std::vector< ci::vec2 > mParticlePositions;
|
f@0
|
51
|
f@3
|
52 // current number of active particles
|
f@0
|
53 size_t mNumParticles;
|
f@0
|
54
|
f@4
|
55 ci::gl::VboRef mParticleVbo; // virtual buffer object
|
f@0
|
56 ci::gl::BatchRef mParticleBatch;
|
f@0
|
57
|
f@0
|
58 public:
|
f@3
|
59 /**
|
f@3
|
60 * Every time addParticles is run, up to kMaxParticleAdd are added at once
|
f@3
|
61 */
|
f@0
|
62 static const int kMaxParticleAdd = 22;
|
f@0
|
63
|
f@0
|
64 ParticleController();
|
f@3
|
65
|
f@3
|
66 /**
|
f@3
|
67 * Adds \a amount particles and places them in \a initialLocation.
|
f@3
|
68 * \cloudSize determines how far the particles can go
|
f@3
|
69 */
|
f@0
|
70 void addParticles(int amount, const ci::vec2 &initialLocation, const float cloudSize);
|
f@0
|
71
|
f@3
|
72 /**
|
f@3
|
73 * Updates position and age of the particles
|
f@3
|
74 */
|
f@0
|
75 void updateParticles();
|
f@0
|
76
|
f@3
|
77 /**
|
f@3
|
78 * Draws all the particles
|
f@3
|
79 */
|
f@0
|
80 inline void draw()
|
f@0
|
81 {
|
f@0
|
82 mParticleBatch->draw();
|
f@0
|
83 }
|
f@0
|
84
|
f@0
|
85 };
|
f@0
|
86
|