-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticle.cpp
More file actions
45 lines (33 loc) · 859 Bytes
/
Particle.cpp
File metadata and controls
45 lines (33 loc) · 859 Bytes
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
//
// Created by Daniel Chen on 2020-02-27.
//
#include "Particle.h"
#include <math.h>
#include <stdlib.h>
namespace ParticleExplosionProject{
Particle::Particle() {
init();
}
Particle::~Particle() {
}
void Particle::update(int timeInterval) {
m_angle += timeInterval * 0.0004;
double x_speed = m_speed * cos(m_angle);
double y_speed = m_speed * sin(m_angle);
m_x += x_speed * timeInterval;
m_y += y_speed * timeInterval;
if (m_x < -1 || m_x > 1 || m_y < -1 || m_y > 1) {
init();
}
if (rand() < RAND_MAX / 100) {
init();
}
}
void Particle::init() {
m_x = 0;
m_y = 0;
m_angle = (2 * M_PI * rand()) / RAND_MAX;
m_speed = (0.02 * rand()) / RAND_MAX;
m_speed *= m_speed;
}
}