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