Panda3D

particleSystem.I
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file particleSystem.I
10 * @author charles
11 * @date 2000-06-14
12 */
13
14 /**
15 * Populates an attached GeomNode structure with the particle geometry for
16 * rendering. This is a wrapper for accessability.
17 */
18 INLINE void ParticleSystem::
19 render() {
20 _renderer->render(_physics_objects, _living_particles);
21 }
22
23 /**
24 * Forces the birth of a particle litter this frame by resetting
25 * _tics_since_birth
26 */
27 INLINE void ParticleSystem::
28 induce_labor() {
29 _tics_since_birth = _cur_birth_rate;
30 }
31
32 /**
33 * Resets the system to its start state by resizing to 0, then resizing back
34 * to current size.
35 */
36 INLINE void ParticleSystem::
37 clear_to_initial() {
38 BaseParticle *bp;
39 int i;
40
41 for(i = 0; i < (int)_physics_objects.size(); i++) {
42 bp = (BaseParticle *)_physics_objects[i].p();
43 if(bp->get_alive()) {
44 kill_particle(i);
45 }
46 }
47 _tics_since_birth = 0.0f;
48 }
49
50 /**
51 * Causes system to use birth rate set by set_birth_rate()
52 */
53 INLINE void ParticleSystem::
54 soft_start(PN_stdfloat br) {
55 if (br > 0.0)
56 set_birth_rate(br);
57 _cur_birth_rate = _birth_rate;
58 _tics_since_birth = 0.0f;
59 }
60
61 /**
62 * Causes system to use birth rate set by set_birth_rate(), with the system's
63 * first birth being delayed by the value of first_birth_delay. Note that a
64 * negative delay is perfectly valid, causing the first birth to happen
65 * sooner rather than later.
66 */
67 INLINE void ParticleSystem::
68 soft_start(PN_stdfloat br, PN_stdfloat first_birth_delay) {
69 soft_start(br);
70 _tics_since_birth = -first_birth_delay;
71 }
72
73 /**
74 * Causes system to use birth rate set by set_soft_birth_rate()
75 */
76 INLINE void ParticleSystem::
77 soft_stop(PN_stdfloat br) {
78 if (br > 0.0)
79 set_soft_birth_rate(br);
80 _cur_birth_rate = _soft_birth_rate;
81 _tics_since_birth = 0.0f;
82 }
83
84 /**
85
86 */
87 INLINE void ParticleSystem::
88 set_pool_size(int size) {
89 resize_pool(size);
90 }
91
92 /**
93
94 */
95 INLINE void ParticleSystem::
96 set_birth_rate(PN_stdfloat new_br) {
97 _birth_rate = new_br;
98 _cur_birth_rate = _birth_rate;
99 if(IS_NEARLY_ZERO(_birth_rate)) _birth_rate = NEARLY_ZERO(PN_stdfloat);
100 }
101
102 /**
103
104 */
105 INLINE void ParticleSystem::
106 set_soft_birth_rate(PN_stdfloat new_br) {
107 _soft_birth_rate = new_br;
108 if(IS_NEARLY_ZERO(_soft_birth_rate)) _soft_birth_rate = NEARLY_ZERO(PN_stdfloat);
109 }
110
111 /**
112
113 */
114 INLINE void ParticleSystem::
115 set_litter_size(int new_ls) {
116 _litter_size = new_ls;
117 }
118
119 /**
120
121 */
122 INLINE void ParticleSystem::
123 set_litter_spread(int new_ls) {
124 _litter_spread = new_ls;
125 }
126
127 /**
128
129 */
130 INLINE void ParticleSystem::
131 set_renderer(BaseParticleRenderer *r) {
132 _renderer = r;
133 _renderer->resize_pool(_particle_pool_size);
134
135 _render_node_path.remove_node();
136 _render_node_path = _renderer->get_render_node_path();
137 _render_node_path.reparent_to(_render_parent);
138 }
139
140 /**
141
142 */
143 INLINE void ParticleSystem::
144 set_emitter(BaseParticleEmitter *e) {
145 _emitter = e;
146 }
147
148 /**
149
150 */
151 INLINE void ParticleSystem::
152 set_factory(BaseParticleFactory *f) {
153 int pool_size = _particle_pool_size;
154 set_pool_size(0);
155 _factory = f;
156 clear_physics_objects();
157 set_pool_size(pool_size);
158 }
159
160 /**
161
162 */
163 INLINE void ParticleSystem::
164 set_floor_z(PN_stdfloat z) {
165 _floor_z = z;
166 }
167
168 /**
169
170 */
171 INLINE void ParticleSystem::
172 set_active_system_flag(bool a) {
173 _active_system_flag = a;
174 }
175
176 /**
177
178 */
179 INLINE void ParticleSystem::
180 set_local_velocity_flag(bool lv) {
181 _local_velocity_flag = lv;
182 }
183
184 /**
185
186 */
187 INLINE void ParticleSystem::
188 set_spawn_on_death_flag(bool sod) {
189 _spawn_on_death_flag = sod;
190 }
191
192 /**
193
194 */
195 INLINE void ParticleSystem::
196 set_system_grows_older_flag(bool sgo) {
197 _system_grows_older_flag = sgo;
198 }
199
200 /**
201
202 */
203 INLINE void ParticleSystem::
204 set_system_lifespan(PN_stdfloat sl) {
205 _system_lifespan = sl;
206 }
207
208 /**
209
210 */
211 INLINE void ParticleSystem::
212 set_system_age(PN_stdfloat age) {
213 _system_age = age;
214 }
215
216 /**
217
218 */
219 INLINE void ParticleSystem::
220 set_spawn_render_node(PandaNode *node) {
221 set_spawn_render_node_path(NodePath(node));
222 }
223
224 /**
225
226 */
227 INLINE void ParticleSystem::
228 set_spawn_render_node_path(const NodePath &node) {
229 _spawn_render_node_path = node;
230 }
231
232 /**
233
234 */
235 INLINE void ParticleSystem::
236 set_render_parent(PandaNode *node) {
237 set_render_parent(NodePath(node));
238 }
239
240 /**
241
242 */
243 INLINE void ParticleSystem::
244 set_render_parent(const NodePath &node) {
245 _render_node_path.remove_node();
246
247 _render_parent = node;
248 _render_node_path = _renderer->get_render_node_path();
249 _render_node_path.reparent_to(_render_parent);
250 }
251
252 /**
253
254 */
255 INLINE void ParticleSystem::
256 set_template_system_flag(bool tsf) {
257 _template_system_flag = tsf;
258 }
259
260 /**
261
262 */
263 INLINE void ParticleSystem::
264 add_spawn_template(ParticleSystem *ps) {
265 _spawn_templates.push_back(ps);
266 }
267
268 /**
269
270 */
271 INLINE void ParticleSystem::
272 clear_spawn_templates() {
273 _spawn_templates.erase(_spawn_templates.begin(),
274 _spawn_templates.end());
275 }
276
277 /**
278
279 */
280 INLINE void ParticleSystem::
281 clear_floor_z() {
282 _floor_z = -HUGE_VAL;
283 }
284
285 /**
286
287 */
288 INLINE int ParticleSystem::
289 get_pool_size() const {
290 return _particle_pool_size;
291 }
292
293 /**
294
295 */
296 INLINE PN_stdfloat ParticleSystem::
297 get_birth_rate() const {
298 return _birth_rate;
299 }
300
301 /**
302
303 */
304 INLINE PN_stdfloat ParticleSystem::
305 get_soft_birth_rate() const {
306 return _soft_birth_rate;
307 }
308
309 /**
310
311 */
312 INLINE int ParticleSystem::
313 get_litter_size() const {
314 return _litter_size;
315 }
316
317 /**
318
319 */
320 INLINE int ParticleSystem::
321 get_litter_spread() const {
322 return _litter_spread;
323 }
324
325 /**
326
327 */
328 INLINE BaseParticleRenderer *ParticleSystem::
329 get_renderer() const {
330 return _renderer;
331 }
332
333 /**
334
335 */
336 INLINE BaseParticleEmitter *ParticleSystem::
337 get_emitter() const {
338 return _emitter;
339 }
340
341 /**
342
343 */
344 INLINE BaseParticleFactory *ParticleSystem::
345 get_factory() const {
346 return _factory;
347 }
348
349 /**
350
351 */
352 INLINE PN_stdfloat ParticleSystem::
353 get_floor_z() const {
354 return _floor_z;
355 }
356
357 /**
358
359 */
360 INLINE PN_stdfloat ParticleSystem::
361 get_tics_since_birth() const {
362 return _tics_since_birth;
363 }
364
365 /**
366
367 */
368 INLINE int ParticleSystem::
369 get_living_particles() const {
370 return _living_particles;
371 }
372
373 /**
374
375 */
376 INLINE bool ParticleSystem::
377 get_active_system_flag() const {
378 return _active_system_flag;
379 }
380
381 /**
382
383 */
384 INLINE bool ParticleSystem::
385 get_local_velocity_flag() const {
386 return _local_velocity_flag;
387 }
388
389 /**
390
391 */
392 INLINE bool ParticleSystem::
393 get_spawn_on_death_flag() const {
394 return _spawn_on_death_flag;
395 }
396
397 /**
398
399 */
400 INLINE bool ParticleSystem::
401 get_system_grows_older_flag() const {
402 return _system_grows_older_flag;
403 }
404
405 /**
406
407 */
408 INLINE PN_stdfloat ParticleSystem::
409 get_system_lifespan() const {
410 return _system_lifespan;
411 }
412
413 /**
414
415 */
416 INLINE PN_stdfloat ParticleSystem::
417 get_system_age() const {
418 return _system_age;
419 }
420
421 /**
422
423 */
424 INLINE bool ParticleSystem::
425 get_i_was_spawned_flag() const {
426 return _i_was_spawned_flag;
427 }
428
429 /**
430
431 */
432 INLINE PandaNode *ParticleSystem::
433 get_spawn_render_node() const {
434 return _spawn_render_node_path.node();
435 }
436
437 /**
438
439 */
440 INLINE NodePath ParticleSystem::
441 get_spawn_render_node_path() const {
442 return _spawn_render_node_path;
443 }
444
445 /**
446
447 */
448 INLINE NodePath ParticleSystem::
449 get_render_parent() const {
450 return _render_parent;
451 }
BaseParticleEmitter
Definition: baseParticleEmitter.h:25
BaseParticleFactory
Pure Virtual base class for creating particles.
Definition: baseParticleFactory.h:28
BaseParticleRenderer
Pure virtual particle renderer base class.
Definition: baseParticleRenderer.h:32
BaseParticle
An individual, physically-modelable particle abstract base class.
Definition: baseParticle.h:23
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
NodePath::remove_node
void remove_node(Thread *current_thread=Thread::get_current_thread())
Disconnects the referenced node from the scene graph.
Definition: nodePath.cxx:624
NodePath::node
PandaNode * node() const
Returns the referenced node of the path.
Definition: nodePath.I:227
NodePath::reparent_to
void reparent_to(const NodePath &other, int sort=0, Thread *current_thread=Thread::get_current_thread())
Removes the referenced node of the NodePath from its current parent and attaches it to the referenced...
Definition: nodePath.cxx:391
PandaNode
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
ParticleSystem
Contains and manages a particle system.
Definition: particleSystem.h:34
ParticleSystem::soft_start
void soft_start(PN_stdfloat br=0.0)
Causes system to use birth rate set by set_birth_rate()
Definition: particleSystem.I:54
ParticleSystem::induce_labor
void induce_labor()
Forces the birth of a particle litter this frame by resetting _tics_since_birth.
Definition: particleSystem.I:28
ParticleSystem::clear_to_initial
void clear_to_initial()
Resets the system to its start state by resizing to 0, then resizing back to current size.
Definition: particleSystem.I:37
ParticleSystem::soft_stop
void soft_stop(PN_stdfloat br=0.0)
Causes system to use birth rate set by set_soft_birth_rate()
Definition: particleSystem.I:77
ParticleSystem::render
void render()
Populates an attached GeomNode structure with the particle geometry for rendering.
Definition: particleSystem.I:19
Physical::clear_physics_objects
void clear_physics_objects()
Erases the object list.
Definition: physical.I:38