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@4: // 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: