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
History | View | Annotate | Download (2.39 KB)
| 1 |
/*
|
|---|---|
| 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 |
#pragma once
|
| 25 |
|
| 26 |
#include "cinder/gl/gl.h" |
| 27 |
#include <vector> |
| 28 |
|
| 29 |
/**
|
| 30 |
* The ParticleController creates/updates/draws and destroys particles
|
| 31 |
*/
|
| 32 |
class ParticleController {
|
| 33 |
|
| 34 |
struct Particle {
|
| 35 |
|
| 36 |
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 |
|
| 41 |
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 |
|
| 45 |
}; |
| 46 |
|
| 47 |
static const int kMaxParticles = 150; |
| 48 |
|
| 49 |
std::vector<Particle> mParticles; |
| 50 |
std::vector< ci::vec2 > mParticlePositions; |
| 51 |
|
| 52 |
// current number of active particles
|
| 53 |
size_t mNumParticles; |
| 54 |
|
| 55 |
ci::gl::VboRef mParticleVbo; // virtual buffer object
|
| 56 |
ci::gl::BatchRef mParticleBatch; |
| 57 |
|
| 58 |
public:
|
| 59 |
/**
|
| 60 |
* Every time addParticles is run, up to kMaxParticleAdd are added at once
|
| 61 |
*/
|
| 62 |
static const int kMaxParticleAdd = 22; |
| 63 |
|
| 64 |
ParticleController(); |
| 65 |
|
| 66 |
/**
|
| 67 |
* Adds \a amount particles and places them in \a initialLocation.
|
| 68 |
* \cloudSize determines how far the particles can go
|
| 69 |
*/
|
| 70 |
void addParticles(int amount, const ci::vec2 &initialLocation, const float cloudSize); |
| 71 |
|
| 72 |
/**
|
| 73 |
* Updates position and age of the particles
|
| 74 |
*/
|
| 75 |
void updateParticles();
|
| 76 |
|
| 77 |
/**
|
| 78 |
* Draws all the particles
|
| 79 |
*/
|
| 80 |
inline void draw() |
| 81 |
{
|
| 82 |
mParticleBatch->draw(); |
| 83 |
} |
| 84 |
|
| 85 |
}; |
| 86 |
|