Repository navigation
Expand file tree
/
Copy pathParticleEffect.cpp
More file actions
65 lines (57 loc) · 1.7 KB
/
Copy pathParticleEffect.cpp
File metadata and controls
65 lines (57 loc) · 1.7 KB
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
63
64
65
#include "ParticleEffect.h"
#include "Sphere.h"
ParticleEffect::ParticleEffect(Vector3 pos){
srand(time(0));
speed = 0.00095;
count = 600;
particles = new vector<Particle*>();
for (int i = 0; i < count; i++){
Particle *current = new Particle;
current->delay = rand() % 4;
double x = double(2*(rand()%2)-1)*(double)(rand() % 1000) * speed / 1000.0;
double y = double(2 * (rand() % 2) - 1)*(double)(rand() % 1000) * speed / 1000.0;
double z = double(2 * (rand() % 2) - 1)*(double)(rand() % 1000) * speed / 1000.0;
current->dir = Vector3(x, y, z);
current->pos = pos;
current->duration = 120 + rand() % 300;
particles->push_back(current);
}
}
void ParticleEffect::draw(Matrix4 matrix){
double s = 0.0010;
Matrix4 scale;
scale.makeScale(s,s,s);
vector<Particle*>::iterator it;
int active = 0;
for (it = particles->begin(); it != particles->end(); it++){
Particle *current = *it;
if (current->delay <= 0){
if (current->duration > 0){
//cout << "Particle effect!!!" << endl;
current->duration = current->duration - 1;
current->pos = current->pos + current->dir;
Sphere *sphere = new Sphere();
sphere->r = (double)(rand() % 100) / 100.0;
sphere->g = (double)(rand() % 100) / 100.0;
sphere->b = (double)(rand() % 100) / 100.0;
Matrix4 translate;
translate.makeTranslate(current->pos.m[0], current->pos.m[1], current->pos.m[2]);
sphere->draw(matrix * translate * scale);
active++;
delete sphere;
}
}
else{
current->delay--;
}
}
//printf("active = %d\n", active);
if (active == 0) {
particles->clear();
alive = false;
}
}
void ParticleEffect::update(Matrix4 matrix){
}
void ParticleEffect::drawBoundingSpheres(Matrix4 worldMatrix){
}