To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / CollidoscopeApp / include / ParticleController.h @ 4:ab6db404403a

History | View | Annotate | Download (1.63 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 4:ab6db404403a f
        ci::vec2        mCloudCenter; // initial positin of the particle
14
        ci::vec2        mVel;         // velocity
15
        float       mCloudSize;   // how big is the area where particle float around. When a particle hits the
16
                                  //   border of the area it gets deflected
17 0:02467299402e f
18 4:ab6db404403a f
        int                        mAge;      // when mAge == mLifeSpan the particle is disposed
19
        int                        mLifespan; // how long a particle lives
20
        bool        mFlyOver;  // some particles last longer and fly over the screen and reach the other user
21 0:02467299402e f
22
    };
23
24
    static const int kMaxParticles = 150;
25
26
        std::vector<Particle> mParticles;
27
    std::vector< ci::vec2 > mParticlePositions;
28
29 3:7fb593d53361 f
    // current number of active particles
30 0:02467299402e f
    size_t mNumParticles;
31
32 4:ab6db404403a f
    ci::gl::VboRef                        mParticleVbo;    // virtual buffer object
33 0:02467299402e f
    ci::gl::BatchRef                mParticleBatch;
34
35
 public:
36 3:7fb593d53361 f
    /**
37
     * Every time addParticles is run, up to kMaxParticleAdd are added at once
38
     */
39 0:02467299402e f
    static const int kMaxParticleAdd = 22;
40
41
    ParticleController();
42 3:7fb593d53361 f
43
    /**
44
     * Adds \a amount particles and places them in \a initialLocation.
45
     * \cloudSize determines how far the particles can go
46
     */
47 0:02467299402e f
        void addParticles(int amount, const ci::vec2 &initialLocation, const float cloudSize);
48
49 3:7fb593d53361 f
    /**
50
     * Updates position and age of the particles
51
     */
52 0:02467299402e f
    void updateParticles();
53
54 3:7fb593d53361 f
    /**
55
     * Draws all the particles
56
     */
57 0:02467299402e f
    inline void draw()
58
    {
59
        mParticleBatch->draw();
60
    }
61
62
};