-
Notifications
You must be signed in to change notification settings - Fork 2
/
particleSystem.cpp
123 lines (89 loc) · 3.18 KB
/
particleSystem.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "particleSystem.h"
#include "input.h"
#include "meshData.h"
ParticleSystem::ParticleSystem(){
name="ParticleSystem";
sceneShaderID="color";
textureID="NULL";
bTextured=false;
bUseShader=true;
drawType=DRAW_PARTICLES;
registerProperties();
}
void ParticleSystem::addParticles(int amount){
for (int i=0;i<amount; i++){
vertexData myVData;
myVData.birth=(0.0);
myVData.color=Vector4f(1,1,1,1);
myVData.secondaryColor=Vector3f(0.0,0.0,0.0);
myVData.normal=Vector3f(0,0,1);
myVData.texCoord=Vector3f(1,1,1);
renderer->vboList[vboMeshID]->vData.push_back(myVData);
}
}
void ParticleSystem::deleteParticle(int particleNumber){
//delete the particle
renderer->vboList[vboMeshID]->vData.erase(renderer->vboList[vboMeshID]->vData.begin()+particleNumber);
}
void ParticleSystem::addRandomParticles(int amount, float diameter){
for (int i=0;i<amount;i++){
vertexData myVData;
myVData.location.x=((double)rand()/(double)RAND_MAX) * diameter;
myVData.location.y=((double)rand()/(float)RAND_MAX) * diameter;
myVData.location.z=((double)rand()/(float)RAND_MAX) * diameter;
myVData.location.w=1.0; //scale!!!
myVData.normal.x=((double)rand()/(double)RAND_MAX) * diameter;
myVData.normal.y=((double)rand()/(float)RAND_MAX) * diameter;
myVData.normal.z=((double)rand()/(float)RAND_MAX) * diameter;
myVData.color=Vector4f((float)rand()/(float)RAND_MAX,(float)rand()/(float)RAND_MAX,(float)rand()/(float)RAND_MAX,1);
myVData.texCoord=Vector3f(myVData.color.r, myVData.color.g, myVData.color.b) ;
myVData.secondaryColor=Vector3f((float)rand()/(float)RAND_MAX,(float)rand()/(float)RAND_MAX,1);
myVData.birth=i;
renderer->vboList[vboMeshID]->vData.push_back(myVData);
}
}
void ParticleSystem::setup(){
Actor::setup();
}
void ParticleSystem::update(double deltaTime){
Actor::update(deltaTime);
elapsedTime+=deltaTime;
}
void ParticleSystem::updateShaders(){
Actor::updateShaders();
}
void ParticleSystem::create(){
renderer->addActor(this);
std::cout << "created a ParticleSystem! \n";
}
void ParticleSystem::load(TiXmlElement *myInfo){
Actor::load(myInfo);
}
/*
for (unsigned int i=0;i<segments.size();i++){
if (particleNumber<segments[i]){
mySegment=i;
break;
}
//or, if we are deleting from the last segment...
else{
cout << "deleting from the last segment!" << endl;
mySegment=segments.size()-1;
}
}
//make sure we draw one particle less in every segment above the one we delete from
for (unsigned int i=mySegment;i<segments.size();i++){
//dont delete from the last segment
if (mySegment<(int)segments.size()-1)
//segments[i]--;
//check for unnecessary segments
if (i>0)
if (segments[i]==segments[i-1])
{
segments.erase(segments.begin()+i-1);
i--;
}
}
particles.erase(particles.begin()+particleNumber);
//particles[particleNumber].color=Vector4f(1,0,0,1);
*/