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
|
/*
render/particles.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_PARTICLES_H__
#define __INCLUDED_RENDER_PARTICLES_H__
#include <deque>
#include "math/axis.h"
#include "math/color.h"
#include "math/vector3f.h"
#include "core/entity.h"
#include "model/tags.h"
namespace render
{
/* ---- class Particle --------------------------------------------- */
/// one particle
class Particle
{
public:
Particle(const math::Vector3f &location, float time);
Particle(const math::Vector3f &location, const math::Axis &axis, float time);
/// location of the particle, in world coordinates
inline math::Vector3f &location() {
return particle_location;
}
inline math::Axis &axis() {
return particle_axis;
}
inline const float time() const {
return particle_time;
}
protected:
math::Vector3f particle_location;
math::Axis particle_axis;
float particle_time;
};
/* ---- class ParticleScript --------------------------------------- */
/// class to hold particle scripts
class ParticleScript
{
public:
enum Type {Jet = 0, Trail = 1, Flame = 2, Spray = 3 };
inline const Type type() const {
return particlescript_type;
}
inline const std::string &label() const {
return particlescript_label;
}
inline const std::string &texture() const {
return particlescript_texture;
}
inline const math::Color &color() const {
return particlescript_color;
}
/// axis transformation relative to the ejector
inline const math::Axis &axis() const {
return particlescript_axis;
}
/// true if entity color is to be applied
inline bool engine() const {
return particlescript_engine;
}
/**
* @brief true if entity primary color is to be applied
* */
inline bool entity() const
{
return particlescript_entity;
}
/**
* @brief true if entity secondary color is to be applied
* */
inline bool entity_second() const
{
return particlescript_entity_second;
}
inline float radius() const {
return particlescript_radius;
}
inline float timeout() const {
return particlescript_timeout;
}
inline float eject() const {
return particlescript_eject;
}
inline float speed() const {
return particlescript_speed;
}
inline float alpha() const {
return particlescript_alpha;
}
inline float offset() const {
return particlescript_offset;
}
inline const model::Cull cull() const {
return particlescript_cull;
}
inline const ParticleScript *next() const {
return particlescript_next;
}
static ParticleScript *load(const std::string &label);
static void clear();
static void list();
private:
static ParticleScript *find(const std::string &label);
ParticleScript(const std::string & label);
~ParticleScript();
std::string particlescript_label;
std::string particlescript_texture;
Type particlescript_type;
math::Color particlescript_color;
math::Axis particlescript_axis;
bool particlescript_entity;
bool particlescript_entity_second;
bool particlescript_engine;
float particlescript_radius;
float particlescript_timeout;
float particlescript_eject;
float particlescript_speed;
float particlescript_alpha;
float particlescript_offset;
model::Cull particlescript_cull;
ParticleScript *particlescript_next;
typedef std::map<std::string, ParticleScript *> Registry;
static Registry particlescript_registry;
};
/* ---- class ParticleSystem --------------------------------------- */
/// abstract base class for a particle system attached to an entity
class ParticleSystem
{
public:
ParticleSystem(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass);
virtual ~ParticleSystem();
/// index of the texture to use
inline const size_t texture() const {
return particlesystem_texture;
}
/// location of the particle system within the entity
inline const math::Vector3f &location() const {
return particlesystem_location;
}
/// axis of the particle system within the entity
inline const math::Axis &axis() const {
return particlesystem_axis;
}
inline const model::Cull cull() const {
return particlesystem_cull;
}
/// color of the particles
inline const math::Color & color() const {
return particlesystem_color;
}
virtual void draw(const float elapsed);
void set_timeout(float timeout);
void set_eject(float eject);
/// clear all particles
void clear();
protected:
typedef std::deque<Particle *> Stream;
inline Stream & stream() {
return particlesystem_stream;
}
Stream particlesystem_stream;
math::Axis particlesystem_axis;
math::Vector3f particlesystem_location;
math::Vector3f ejector_location;
math::Color particlesystem_color;
model::Cull particlesystem_cull;
bool ejector_active;
float particlesystem_last_eject;
float particlesystem_radius;
float now;
size_t particlesystem_texture;
const model::Particles *particlesystem_modelclass;
const ParticleScript *particlesystem_script;
const core::Entity *particlesystem_entity;
};
/* ---- class Flame ------------------------------------------------ */
/// flame style particles, like engine flames
class Flame : public ParticleSystem
{
public:
Flame(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass);
virtual ~Flame();
virtual void draw(const float elapsed);
};
/* ---- class Jet -------------------------------------------------- */
/// jet style particles, like smoke
class Jet : public ParticleSystem
{
public:
Jet(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass);
virtual ~Jet();
virtual void draw(const float elapsed);
};
/* ---- class Trail ------------------------------------------------ */
/// trail style particles, like an engine trail
class Trail : public ParticleSystem
{
public:
Trail(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass);
virtual ~Trail();
virtual void draw(float elapsed);
};
/* ---- class Spray ----------------------------------------------- */
/**
* @brief spray style particles
* a spray is a sprite ejector
* */
class Spray : public ParticleSystem
{
public:
Spray(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass);
virtual ~Spray();
virtual void draw(const float elapsed);
};
} // namespace render
#endif // __INCLUDED_RENDER_PARTICLES_H__
|