-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwarm.cpp
50 lines (43 loc) · 1.15 KB
/
Swarm.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
/*
* Particle simulation program using the SDL library
* Based on examples by John Purcell's (from Cave of Programming)
*
* @author J. Alvarez
*/
#include <iostream>
#include "Swarm.hpp"
#include "Particle.hpp"
#include "RectangularParticle.hpp"
#include "PolarParticle.hpp"
namespace ParticleSimulation {
Swarm::Swarm(int type, int mode): m_type(type), m_lastUpdate(0) {
switch (m_type) {
case TYPE::RECT:
m_particles = new Particle * [N_PARTICLES];
for (int i = 0; i < N_PARTICLES; i++)
m_particles[i] = new RectangularParticle(mode);
break;
case TYPE::POLAR:
m_particles = new Particle * [N_PARTICLES];
for (int i = 0; i < N_PARTICLES; i++)
m_particles[i] = new PolarParticle(mode);
break;
default:
std::cout << "Swarm type not implemented!!!" << std::endl;
break;
}
}
Swarm::~Swarm() {
for (int i = 0; i < N_PARTICLES; i++)
delete m_particles[i];
delete [] m_particles;
}
Particle * * Swarm::getParticles() {
return m_particles;
}
void Swarm::update(int elapsed) {
for (int i = 0; i < N_PARTICLES; i++)
m_particles[i]->update(elapsed - m_lastUpdate);
m_lastUpdate = elapsed;
}
} // namespace ParticleSimulation