-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.cpp
52 lines (38 loc) · 820 Bytes
/
Particle.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
/*
* Particle.cpp
*
* Created on: 13 Sep 2014
* Author: johnwpurcell
*/
#include "Particle.h"
#include <math.h>
#include <stdlib.h>
namespace caveofprogramming {
Particle::Particle() :
m_x(0), m_y(0) {
init();
}
void Particle::init() {
m_x = 0;
m_y = 0;
m_direction = (2 * M_PI * rand()) / RAND_MAX;
m_speed = (0.04 * rand()) / RAND_MAX;
m_speed *= m_speed;
}
Particle::~Particle() {
// TODO Auto-generated destructor stub
}
void Particle::update(int interval) {
m_direction += interval * 0.0003;
double xspeed = m_speed * cos(m_direction);
double yspeed = m_speed * sin(m_direction);
m_x += xspeed * interval;
m_y += yspeed * interval;
if (m_x < -1 || m_x > 1 || m_y < -1 || m_y > 1) {
init();
}
if(rand() < RAND_MAX/100) {
init();
}
}
} /* namespace caveofprogramming */