-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEmitter.cpp
More file actions
161 lines (135 loc) · 4.72 KB
/
Emitter.cpp
File metadata and controls
161 lines (135 loc) · 4.72 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
#include "Emitter.h"
Emitter::Emitter() : fillThis(NULL), isActive(false)
{
cout << "Default Emitter" << endl ;
}
Emitter::Emitter(std::vector<Particle*> &emitInThis) : fillThis(&emitInThis), isActive(false) { }
Emitter::Emitter(std::string _name, std::vector<Particle*> &emitInThis) :
name(_name), fillThis(&emitInThis), isActive(false) { }
Emitter::~Emitter() {}
void Emitter::emit(bool activate, int num)
{
isActive = activate ;
if(isActive)
{
for(int i= 0 ; i< num ; i++ )
{
Particle *newParticle = new Particle() ;
//newParticle->setPtnum(i) ;
fillThis->push_back(newParticle) ;
}
cout << "Finished emitting " << num << " particles" ;
if(name != "")
cout <<" from " << name << endl ;
else cout << endl ;
}
//set it to false after one cycle..
//activate parameter will be used to
//set isActive again in next cycle
isActive = false ;
}
void Emitter::emit(bool activate, int num, const ofVec3f &pos, const ofVec3f &vel,
float xvelVar, float yvelVar, float zvelVar, float mass, float massVar, const ofColor &color)
{
isActive = activate ;
if(isActive)
{
for(int i= 0 ; i< num ; i++ )
{
//using SIZE() of the vector to set ptnum..
// Particle *newParticle = new Particle(fillThis->size(), jitterPos, jitterVel, mass) ;
Particle *newParticle = new Particle(fillThis->size(), pos, vel, xvelVar, yvelVar, zvelVar, mass, massVar) ;
newParticle->setColor(color) ;
//newParticle->setPtnum(i) ;
fillThis->push_back(newParticle) ;
}
cout << "Finished emitting " << num << " particles and set initial position and velocity" ;
if(name != "")
cout <<" from " << name << endl ;
else cout << endl ;
}
//set it to false after one cycle..
//activate parameter will be used to
//set isActive again in next cycle
isActive = false ;
}
void Emitter::emit(bool activate, int num, float xpos, float ypos, float zpos, float xvel, float yvel, float zvel,
float xvelVar, float yvelVar, float zvelVar, float mass, float massVar, const ofColor& color)
{
isActive = activate ;
if(isActive)
{
for(int i= 0 ; i< num ; i++ )
{
Particle *newParticle = new Particle(fillThis->size(), xpos, ypos, zpos, xvel, yvel, zvel, xvelVar, yvelVar, zvelVar, mass, massVar) ;
newParticle->setColor(color) ;
//newParticle->setPtnum(i) ;
fillThis->push_back(newParticle) ;
}
cout << "Finished emitting " << num << " particles and set initial position and velocity" ;
if(name != "")
cout <<" from " << name << endl ;
else cout << endl ;
}
//set it to false after one cycle..
//activate parameter will be used to
//set isActive again in next cycle
isActive = false ;
}
//--------------------IMPLEMENTATION FOR EMISSION FROM OFMESH---------------------------
// void Emitter::emit(bool activate, const ofMesh& mesh, int num, float mass, float jitterScale) {}
void Emitter::emit(bool activate, ofMesh &mesh, float mass, float massVar)
{
isActive = activate ;
if(isActive)
{
// std::vector<ofVec3f> verticesInGeo = mesh.getVertices() ;
// static int ctr = 0;
// if(mesh.hasColors())
// {
// std::vector<ofColor> colorsInMesh = mesh.getColors() ;
// }
// for(std::vector<ofVec3f>::const_iterator it = verticesInGeo.begin(); it != verticesInGeo.end(); ++it)
// {
// // // float xpos = xpos + Utility::of_Randomf(ctr) * jitterScale ;
// // // float ypos = ypos + Utility::of_Randomf(22 * ctr) * jitterScale ;
// // // float zpos = zpos + Utility::of_Randomf(33 * ctr) * jitterScale ;
// // // ofVec3f jitterPos = ofVec3f(xpos, ypos, zpos) ;
// float mass = _mass + Utility::of_Randomf(ctr*5) * jitterScale ;
// // // Particle *newParticle = new Particle(ctr, jitterPos, ofVec3f(0.f, 0.f, 0.f), mass) ;
// Particle *newParticle = new Particle(ctr, *it , ofVec3f(0.f, 0.f, 0.f), mass) ;
// fillThis->push_back(newParticle) ;
// ctr++ ;
// }
for(int i = 0; i < mesh.getNumIndices(); i+=3)
{
ofVec3f curVertex = mesh.getVertex(mesh.getIndex(i)) ;
Particle *newParticle = new Particle(fillThis->size(), curVertex , ofVec3f(0.f, 0.f, 0.f), 0.f,0.f,0.f, mass, massVar) ;
//if mesh has colors, particles will inherit those
if(mesh.hasColors())
{
ofColor curVertexColor = mesh.getColor(mesh.getIndex(i)) ;
newParticle->setColor(curVertexColor) ;
}
fillThis->push_back(newParticle) ;
}
cout << "Finished emitting " << mesh.getNumIndices() << " particles and set initial position and velocity" ;
if(name != "")
cout <<" from MESH " << name << endl ;
else cout << endl ;
}
isActive = false ;
}
////////////////////////////////////////////////////////////////////////////////////////////
void Emitter::setName(std::string _name)
{
name = _name ;
}
std::string Emitter::getName()
{
return name ;
}
bool Emitter::isEmitterActive()
{
return isActive ;
}