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