-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicParticlesApp.cpp
62 lines (50 loc) · 1.78 KB
/
BasicParticlesApp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
//INCLUDE THE PARTICLE HEADER FILE AND PORTION
#include "Particle.hpp"
#include "cinder/Rand.h"
//THIS IS A GLOBAL VARIABLE THAT DETERMINES HOW MANY PARTICLES WILL BE IN THE SYSTEM, THE const KEYWORD SIMPLY MEANS THAT THE VALUE WILL REMAIN CONSTANT AND CAN'T BE CHANGED ONCES THE CODE HAS COMPILED.
const int NUM_PARTICLES = 200;
using namespace ci;
using namespace ci::app;
using namespace std;
class BasicParticlesApp : public App {
public:
void setup() override;
void mouseDown( MouseEvent event ) override;
void update() override;
void draw() override;
//DECLARE A CONTAINER CALLED mParticles THAT WILL HOLD ALL THE PARTICLES
vector<Particle> mParticles;
};
void BasicParticlesApp::setup()
{
//DEFINE mParticles AS BEING A VECTOR THAT STORES Particle OBJECTS
mParticles = vector<Particle>();
//FOR EVERY PARTICLE WE WANT IN THE SYSTEM, DEFINED BY NUM_PARTICLES, CREATE A RANDOM VALUE FOR THE X AND Y POSITIONS OF THE PARTICLE, AND PASS THESE AS A VEC2 TO THE PARTICLE'S CONSTRUCTOR, THEN ADD THE PARTICLE TO THE mParticles CONTAINER
for (int i = 0; i < NUM_PARTICLES; i++)
{
vec2 rand = randVec2();
rand.x *= getWindowWidth();
rand.y *= getWindowHeight();
mParticles.push_back( Particle( rand ));
}
}
void BasicParticlesApp::mouseDown( MouseEvent event )
{
}
void BasicParticlesApp::update()
{
}
void BasicParticlesApp::draw()
{
//CLEAR THE WINDOW WITH A BLACK FILL
gl::clear( Color::black() );
//FOR EVERY PARTICLE IN THE CONTAINER, EXECUTE THE run() MEMBER FUNCTION USING THE '.' OPERATOR
for (int i = 0; i < mParticles.size(); i++)
{
mParticles[i].run();
}
}
CINDER_APP( BasicParticlesApp, RendererGl )