-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParticleSystem.cpp
More file actions
185 lines (147 loc) · 4.59 KB
/
ParticleSystem.cpp
File metadata and controls
185 lines (147 loc) · 4.59 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "ParticleSystem.h"
ParticleSystem::ParticleSystem() {}
ParticleSystem::~ParticleSystem()
{
cout << "Deleting ParticleSystem! Removing " << particles.size() << " particles." << endl ;
for(std::vector<Particle*>::iterator it = particles.begin(); it != particles.end(); ++it)
{
delete *it ;
}
particles.clear() ;
}
void ParticleSystem::setPosition() {}
ofVec3f& ParticleSystem::getPosition()
{
return position ;
}
int ParticleSystem::numParticles()
{
return particles.size() ;
}
Emitter* ParticleSystem::addEmitter()
{
Emitter *newEmitter = new Emitter(particles);
return newEmitter ;
}
Emitter* ParticleSystem::addEmitter(std::string _name)
{
Emitter *newEmitter = new Emitter(_name, particles);
return newEmitter ;
}
Particle& ParticleSystem::getParticle(int num)
{
return *(particles.at(num)) ;
}
const std::vector<Particle *>& ParticleSystem::getAllParticles() const
{
return particles ;
}
void ParticleSystem::getAllParticlePosition(std::vector<ofVec3f> &posOfAll)
{
for(std::vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it)
{
posOfAll.push_back((*it)->getPosition()) ;
}
}
void ParticleSystem::addForce(const ofVec3f &force)
{
for(std::vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it)
{
(*it)->addForce(force) ;
}
}
void ParticleSystem::addForce(float x, float y, float z)
{
for(std::vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it)
{
(*it)->addForce(x, y, z) ;
}
}
void ParticleSystem::kill(Particle *particleToKill)
{
std::vector<Particle *>::iterator it = std::find(particles.begin(), particles.end(), particleToKill) ;
delete *it ;
particles.erase(it) ;
}
void ParticleSystem::update(float timeStep)
{
for(std::vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it)
{
(*it)->update(timeStep) ;
}
}
void ParticleSystem::update(float timeStep, float maxSpeed)
{
for(std::vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it)
{
(*it)->update(timeStep, maxSpeed) ;
}
}
void ParticleSystem::draw()
{
glBegin(GL_POINTS) ;
glPointSize(1) ;
for(std::vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it)
{
(*it)->draw() ;
}
glEnd() ;
}
//Ported over to BBox class..
//Idea is to make this into a generic BBox type.
// void ParticleSystem::getAABB(ofVec3f &min, ofVec3f &max)
// {
// //run only if the particles vector is not empty
// if(!particles.empty())
// {
// //unable to use numeric_limits in initialisation
// //need to get a way to use that instead of these
// //hardcoded numbers..
// min.set(1000000.f, 1000000.f, 1000000.f) ;
// max.set(-1000000.f, -1000000.f, -1000000.f) ;
// // min = ofVec3f(tmp_min, tmp_min, tmp_min) ;
// for(std::vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it)
// {
// //set min and max XPOS
// if( (*it)->getPosition().x < min.x )
// min.x = (*it)->getPosition().x ;
// if( (*it)->getPosition().x > max.x )
// max.x = (*it)->getPosition().x ;
// //set min and max YPOS
// if( (*it)->getPosition().y < min.y )
// min.y = (*it)->getPosition().y ;
// if( (*it)->getPosition().y > max.y )
// max.y = (*it)->getPosition().y ;
// //set min and max XPOS
// if( (*it)->getPosition().z < min.z )
// min.z = (*it)->getPosition().z ;
// if( (*it)->getPosition().z > max.z )
// max.z = (*it)->getPosition().z ;
// }
// // cout << "xmin:" << min.x << " xmax:" << max.x << endl ;
// }
// }
// void ParticleSystem::drawAABB(const ofVec3f &min, const ofVec3f &max)
// {
// //only need to draw 6 faces..
// //no need to draw common/shared edges for each face
// //draw MIN ZX plane
// ofLine(min.x, min.y, min.z, max.x, min.y, min.z) ;
// ofLine(min.x, min.y, max.z, max.x, min.y, max.z) ;
// ofLine(min.x, min.y, min.z, min.x, min.y, max.z) ;
// ofLine(max.x, min.y, min.z, max.x, min.y, max.z) ;
// //draw MAX ZX plane
// ofLine(min.x, max.y, min.z, max.x, max.y, min.z) ;
// ofLine(min.x, max.y, max.z, max.x, max.y, max.z) ;
// ofLine(min.x, max.y, min.z, min.x, max.y, max.z) ;
// ofLine(max.x, max.y, min.z, max.x, max.y, max.z) ;
// //draw xy plane
// //draw MIN YZ plane
// ofLine(min.x, min.y, min.z, min.x, max.y, min.z) ;
// ofLine(min.x, min.y, max.z, min.x, max.y, max.z) ;
// ofLine(min.x, min.y, min.z, min.x, max.y, min.z) ;
// //draw MIN YZ plane
// ofLine(max.x, min.y, min.z, max.x, max.y, min.z) ;
// ofLine(max.x, min.y, max.z, max.x, max.y, max.z) ;
// ofLine(min.x, min.y, min.z, min.x, max.y, min.z) ;
// }