forked from ivansafrin/Polycode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolyParticleEmitter.h
More file actions
executable file
·359 lines (278 loc) · 9.88 KB
/
Copy pathPolyParticleEmitter.h
File metadata and controls
executable file
·359 lines (278 loc) · 9.88 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
Copyright (C) 2011 by Ivan Safrin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#include "PolyGlobals.h"
#include "PolyString.h"
#include "PolyVector3.h"
#include "PolyMatrix4.h"
#include "PolyBezierCurve.h"
#include "PolySceneEntity.h"
#include "PolyScreenEntity.h"
namespace Polycode {
class Entity;
class Material;
class Mesh;
class Particle;
class Perlin;
class Scene;
class SceneMesh;
class Screen;
class ScreenMesh;
class Texture;
class Timer;
/**
* Particle emitter base.
*/
class _PolyExport ParticleEmitter {
public:
ParticleEmitter(const String& imageFile, Mesh *particleMesh, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Vector3 emitterRadius);
virtual ~ParticleEmitter();
virtual void dispatchTriggerCompleteEvent();
void createParticles();
/**
* Sets the speed at which particles rotate
* @param speed New rotation speed.
*/
void setRotationSpeed(Number speed);
/**
* Sets the blending mode used for the particles. See documentation for the Entity for information on blending modes.
* @param mode New blending mode.
*/
void setParticleBlendingMode(int mode);
int getParticleBlendingMode() const;
/**
* Turns depth write on and off for particles.
*/
void setDepthWrite(bool val);
/**
* Turns depth test on and off for particles.
*/
void setDepthTest(bool val);
/**
* Turns alpha testing on and off for particles.
*/
void setAlphaTest(bool val);
/**
* Enables perlin noise movement for particles.
*/
void enablePerlin(bool val);
/**
* Sets visibility of all particles in the system
*/
void setParticleVisibility(bool val);
/**
* Enables perlin noise movement size.
*/
void setPerlinModSize(Number size);
/**
* Enables or disables billboard mode for particles.
*/
void setBillboardMode(bool mode);
/**
* Enables or disables the emitter
*/
void enableEmitter(bool val);
/**
* Returns true if the emitter is enabled, false otherwise.
*/
bool emitterEnabled();
/**
* Sets the emitter radius on all 3 axises.
*/
void setEmitterRadius(Vector3 rad);
/**
* If set to true, will release all particles at once.
*/
void setAllAtOnce(bool val);
unsigned int getNumParticles() const;
Particle *getParticleAtIndex(unsigned int index) const;
/**
* If emitter mode is TRIGGERED_EMITTER, calling this method will trigger particle emission.
*/
void resetAll();
void Trigger();
void resetParticle(Particle *particle);
/**
* Changes the particle count in the emitter.
*/
void setParticleCount(int count);
virtual Vector3 getParticleCompoundScale();
virtual void addParticleBody(Entity *particleBody);
virtual Matrix4 getBaseMatrix();
/**
* Particle movement speed multiplier
*/
Number particleSpeedMod;
/**
* Particle brightness deviation
*/
Number brightnessDeviation;
void updateEmitter();
/**
* Continuous emitter setting.
*/
static const int CONTINUOUS_EMITTER = 0;
/**
* Triggered emitter setting.
*/
static const int TRIGGERED_EMITTER = 1;
/**
* Particle direction deviation
*/
Vector3 deviation;
/**
* Particle direction and emission strength vector
*/
Vector3 dirVector;
/**
* Particle gravity strength vector
*/
Vector3 gravVector;
/**
* Lifespan of particles.
*/
Number lifespan;
/**
* If set to true, particles' rotation will follow their movement.
*/
bool rotationFollowsPath;
/**
* Bezier curve that controls the scale of the particles.
*/
BezierCurve scaleCurve;
/**
* Bezier curve that controls the red component of particles' color.
*/
BezierCurve colorCurveR;
/**
* Bezier curve that controls the green component of particles' color.
*/
BezierCurve colorCurveG;
/**
* Bezier curve that controls the blue component of particles' color.
*/
BezierCurve colorCurveB;
/**
* Bezier curve that controls the alpha component of particles' color.
*/
BezierCurve colorCurveA;
/**
* If set to true, will use the color curves to control particle color. False by default.
*/
bool useColorCurves;
/**
* If set to true, will use the scale curve to control particle scale. False by default.
*/
bool useScaleCurves;
Number particleSize;
Texture *getParticleTexture();
void setParticleTexture(Texture *texture);
Vector3 emitterRadius;
Number perlinModSize;
bool perlinEnabled;
Number rotationSpeed;
int emitterType;
protected:
int blendingMode;
bool isScreenEmitter;
Mesh *pMesh;
bool allAtOnce;
int particleType;
Material *particleMaterial;
Texture *particleTexture;
String textureFile;
bool isEmitterEnabled;
Perlin *motionPerlin;
Number numParticles;
std::vector<Particle*> particles;
Number emitSpeed;
Timer *timer;
};
/**
* 3D particle emitter.
*/
class _PolyExport SceneParticleEmitter : public SceneEntity, public ParticleEmitter {
public:
/**
* Constructor.
* @param materialName Name of the material to use for particles.
* @param particleParentScene Scene to create particles in.
* @param particleType Type of particles to create. Can be Particle::BILLBOARD_PARTICLE or Particle::MESH_PARTICLE
* @param emitterType Type of emitter to create. Can be ParticleEmitter::CONTINUOUS_EMITTER or ParticleEmitter::TRIGGERED_EMITTER
* @param lifespan Lifetime of particles in seconds.
* @param numParticles Total number of particles to create.
* @param direction Direction of the emitter, length of this vector controls emitter strength
* @param gravity Gravity direction and strength
* @param deviation Emitter deviation on each axis
* @param particleMesh If particle type is Particle::MESH_PARTICLE, this must be set to the mesh to use for each particle
* @param emitter If this is specified, particles will be emitted from this meshe's vertices.
*/
SceneParticleEmitter(const String& materialName, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Vector3 emitterRadius, Mesh *particleMesh = NULL, SceneMesh *emitter = NULL);
virtual ~SceneParticleEmitter();
/**
* Returns the emitter (helper method for LUA).
*/
ParticleEmitter *getEmitter() { return this; }
void respawnSceneParticles();
void addParticleBody(Entity *particleBody);
Matrix4 getBaseMatrix();
void Update();
Vector3 getParticleCompoundScale();
void dispatchTriggerCompleteEvent();
/**
* Continuous emitter setting.
*/
static const int CONTINUOUS_EMITTER = 0;
/**
* Triggered emitter setting.
*/
static const int TRIGGERED_EMITTER = 1;
protected:
SceneMesh *emitterMesh;
};
/**
* 3D particle emitter.
*/
class _PolyExport ScreenParticleEmitter : public ScreenEntity, public ParticleEmitter {
public:
ScreenParticleEmitter(const String& imageFile, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Vector3 emitterRadius, Mesh *particleMesh = NULL, ScreenMesh *emitter = NULL);
virtual ~ScreenParticleEmitter();
virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
/**
* Returns the emitter (helper method for LUA).
*/
ParticleEmitter *getEmitter() { return this; }
void dispatchTriggerCompleteEvent();
void addParticleBody(Entity *particleBody);
Matrix4 getBaseMatrix();
void Update();
Vector3 getParticleCompoundScale();
/**
* Continuous emitter setting.
*/
static const int CONTINUOUS_EMITTER = 0;
/**
* Triggered emitter setting.
*/
static const int TRIGGERED_EMITTER = 1;
protected:
ScreenMesh *emitterMesh;
};
}