f@5: /* f@5: f@5: Copyright (C) 2015 Fiore Martin f@5: Copyright (C) 2016 Queen Mary University of London f@5: Author: Fiore Martin f@5: f@5: This file is part of Collidoscope. f@5: f@5: Collidoscope is free software: you can redistribute it and/or modify f@5: it under the terms of the GNU General Public License as published by f@5: the Free Software Foundation, either version 3 of the License, or f@5: (at your option) any later version. f@5: f@5: This program is distributed in the hope that it will be useful, f@5: but WITHOUT ANY WARRANTY; without even the implied warranty of f@5: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@5: GNU General Public License for more details. f@5: f@5: You should have received a copy of the GNU General Public License f@5: along with this program. If not, see . f@5: f@5: */ f@5: f@0: #pragma once f@0: f@0: #include "cinder/gl/gl.h" f@0: #include f@0: f@3: /** f@3: * The ParticleController creates/updates/draws and destroys particles f@3: */ f@0: class ParticleController { f@0: f@0: struct Particle { f@0: f@4: ci::vec2 mCloudCenter; // initial positin of the particle f@4: ci::vec2 mVel; // velocity f@4: float mCloudSize; // how big is the area where particle float around. When a particle hits the f@16: // border of the area it gets deflected f@0: f@4: int mAge; // when mAge == mLifeSpan the particle is disposed f@4: int mLifespan; // how long a particle lives f@4: bool mFlyOver; // some particles last longer and fly over the screen and reach the other user f@0: f@0: }; f@0: f@0: static const int kMaxParticles = 150; f@0: f@0: std::vector mParticles; f@0: std::vector< ci::vec2 > mParticlePositions; f@0: f@3: // current number of active particles f@0: size_t mNumParticles; f@0: f@4: ci::gl::VboRef mParticleVbo; // virtual buffer object f@0: ci::gl::BatchRef mParticleBatch; f@0: f@0: public: f@3: /** f@3: * Every time addParticles is run, up to kMaxParticleAdd are added at once f@3: */ f@0: static const int kMaxParticleAdd = 22; f@0: f@0: ParticleController(); f@3: f@3: /** f@3: * Adds \a amount particles and places them in \a initialLocation. f@3: * \cloudSize determines how far the particles can go f@3: */ f@0: void addParticles(int amount, const ci::vec2 &initialLocation, const float cloudSize); f@0: f@3: /** f@3: * Updates position and age of the particles f@3: */ f@0: void updateParticles(); f@0: f@3: /** f@3: * Draws all the particles f@3: */ f@0: inline void draw() f@0: { f@0: mParticleBatch->draw(); f@0: } f@0: f@0: }; f@0: