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 @ 3:7fb593d53361
History | View | Annotate | Download (1.23 KB)
| 1 | 0:02467299402e | f | #pragma once
|
|---|---|---|---|
| 2 | |||
| 3 | #include "cinder/gl/gl.h" |
||
| 4 | #include <vector> |
||
| 5 | |||
| 6 | 3:7fb593d53361 | f | /**
|
| 7 | * The ParticleController creates/updates/draws and destroys particles
|
||
| 8 | */
|
||
| 9 | 0:02467299402e | f | class ParticleController {
|
| 10 | |||
| 11 | struct Particle {
|
||
| 12 | |||
| 13 | ci::vec2 mCloudCenter; |
||
| 14 | ci::vec2 mVel; |
||
| 15 | float mCloudSize;
|
||
| 16 | |||
| 17 | int mAge;
|
||
| 18 | int mLifespan;
|
||
| 19 | bool mFlyOver;
|
||
| 20 | |||
| 21 | }; |
||
| 22 | |||
| 23 | static const int kMaxParticles = 150; |
||
| 24 | |||
| 25 | std::vector<Particle> mParticles; |
||
| 26 | std::vector< ci::vec2 > mParticlePositions; |
||
| 27 | |||
| 28 | 3:7fb593d53361 | f | // current number of active particles
|
| 29 | 0:02467299402e | f | size_t mNumParticles; |
| 30 | |||
| 31 | ci::gl::VboRef mParticleVbo; |
||
| 32 | ci::gl::BatchRef mParticleBatch; |
||
| 33 | |||
| 34 | public:
|
||
| 35 | 3:7fb593d53361 | f | /**
|
| 36 | * Every time addParticles is run, up to kMaxParticleAdd are added at once
|
||
| 37 | */
|
||
| 38 | 0:02467299402e | f | static const int kMaxParticleAdd = 22; |
| 39 | |||
| 40 | ParticleController(); |
||
| 41 | 3:7fb593d53361 | f | |
| 42 | /**
|
||
| 43 | * Adds \a amount particles and places them in \a initialLocation.
|
||
| 44 | * \cloudSize determines how far the particles can go
|
||
| 45 | */
|
||
| 46 | 0:02467299402e | f | void addParticles(int amount, const ci::vec2 &initialLocation, const float cloudSize); |
| 47 | |||
| 48 | 3:7fb593d53361 | f | /**
|
| 49 | * Updates position and age of the particles
|
||
| 50 | */
|
||
| 51 | 0:02467299402e | f | void updateParticles();
|
| 52 | |||
| 53 | 3:7fb593d53361 | f | /**
|
| 54 | * Draws all the particles
|
||
| 55 | */
|
||
| 56 | 0:02467299402e | f | inline void draw() |
| 57 | {
|
||
| 58 | mParticleBatch->draw(); |
||
| 59 | } |
||
| 60 | |||
| 61 | }; |