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::
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::
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_soft_birth_rate()
63  */
64 INLINE void ParticleSystem::
65 soft_stop(PN_stdfloat br) {
66  if (br > 0.0)
67  set_soft_birth_rate(br);
68  _cur_birth_rate = _soft_birth_rate;
69  _tics_since_birth = 0.0f;
70 }
71 
72 /**
73 
74  */
75 INLINE void ParticleSystem::
76 set_pool_size(int size) {
77  resize_pool(size);
78 }
79 
80 /**
81 
82  */
83 INLINE void ParticleSystem::
84 set_birth_rate(PN_stdfloat new_br) {
85  _birth_rate = new_br;
86  _cur_birth_rate = _birth_rate;
87  if(IS_NEARLY_ZERO(_birth_rate)) _birth_rate = NEARLY_ZERO(PN_stdfloat);
88 }
89 
90 /**
91 
92  */
93 INLINE void ParticleSystem::
94 set_soft_birth_rate(PN_stdfloat new_br) {
95  _soft_birth_rate = new_br;
96  if(IS_NEARLY_ZERO(_soft_birth_rate)) _soft_birth_rate = NEARLY_ZERO(PN_stdfloat);
97 }
98 
99 /**
100 
101  */
102 INLINE void ParticleSystem::
103 set_litter_size(int new_ls) {
104  _litter_size = new_ls;
105 }
106 
107 /**
108 
109  */
110 INLINE void ParticleSystem::
111 set_litter_spread(int new_ls) {
112  _litter_spread = new_ls;
113 }
114 
115 /**
116 
117  */
118 INLINE void ParticleSystem::
119 set_renderer(BaseParticleRenderer *r) {
120  _renderer = r;
121  _renderer->resize_pool(_particle_pool_size);
122 
123  _render_node_path.remove_node();
124  _render_node_path = _renderer->get_render_node_path();
125  _render_node_path.reparent_to(_render_parent);
126 }
127 
128 /**
129 
130  */
131 INLINE void ParticleSystem::
132 set_emitter(BaseParticleEmitter *e) {
133  _emitter = e;
134 }
135 
136 /**
137 
138  */
139 INLINE void ParticleSystem::
140 set_factory(BaseParticleFactory *f) {
141  int pool_size = _particle_pool_size;
142  set_pool_size(0);
143  _factory = f;
145  set_pool_size(pool_size);
146 }
147 
148 /**
149 
150  */
151 INLINE void ParticleSystem::
152 set_floor_z(PN_stdfloat z) {
153  _floor_z = z;
154 }
155 
156 /**
157 
158  */
159 INLINE void ParticleSystem::
160 set_active_system_flag(bool a) {
161  _active_system_flag = a;
162 }
163 
164 /**
165 
166  */
167 INLINE void ParticleSystem::
168 set_local_velocity_flag(bool lv) {
169  _local_velocity_flag = lv;
170 }
171 
172 /**
173 
174  */
175 INLINE void ParticleSystem::
176 set_spawn_on_death_flag(bool sod) {
177  _spawn_on_death_flag = sod;
178 }
179 
180 /**
181 
182  */
183 INLINE void ParticleSystem::
184 set_system_grows_older_flag(bool sgo) {
185  _system_grows_older_flag = sgo;
186 }
187 
188 /**
189 
190  */
191 INLINE void ParticleSystem::
192 set_system_lifespan(PN_stdfloat sl) {
193  _system_lifespan = sl;
194 }
195 
196 /**
197 
198  */
199 INLINE void ParticleSystem::
200 set_system_age(PN_stdfloat age) {
201  _system_age = age;
202 }
203 
204 /**
205 
206  */
207 INLINE void ParticleSystem::
208 set_spawn_render_node(PandaNode *node) {
209  set_spawn_render_node_path(NodePath(node));
210 }
211 
212 /**
213 
214  */
215 INLINE void ParticleSystem::
216 set_spawn_render_node_path(const NodePath &node) {
217  _spawn_render_node_path = node;
218 }
219 
220 /**
221 
222  */
223 INLINE void ParticleSystem::
224 set_render_parent(PandaNode *node) {
225  set_render_parent(NodePath(node));
226 }
227 
228 /**
229 
230  */
231 INLINE void ParticleSystem::
232 set_render_parent(const NodePath &node) {
233  _render_node_path.remove_node();
234 
235  _render_parent = node;
236  _render_node_path = _renderer->get_render_node_path();
237  _render_node_path.reparent_to(_render_parent);
238 }
239 
240 /**
241 
242  */
243 INLINE void ParticleSystem::
244 set_template_system_flag(bool tsf) {
245  _template_system_flag = tsf;
246 }
247 
248 /**
249 
250  */
251 INLINE void ParticleSystem::
252 add_spawn_template(ParticleSystem *ps) {
253  _spawn_templates.push_back(ps);
254 }
255 
256 /**
257 
258  */
259 INLINE void ParticleSystem::
260 clear_spawn_templates() {
261  _spawn_templates.erase(_spawn_templates.begin(),
262  _spawn_templates.end());
263 }
264 
265 /**
266 
267  */
268 INLINE void ParticleSystem::
269 clear_floor_z() {
270  _floor_z = -HUGE_VAL;
271 }
272 
273 /**
274 
275  */
276 INLINE int ParticleSystem::
277 get_pool_size() const {
278  return _particle_pool_size;
279 }
280 
281 /**
282 
283  */
284 INLINE PN_stdfloat ParticleSystem::
285 get_birth_rate() const {
286  return _birth_rate;
287 }
288 
289 /**
290 
291  */
292 INLINE PN_stdfloat ParticleSystem::
293 get_soft_birth_rate() const {
294  return _soft_birth_rate;
295 }
296 
297 /**
298 
299  */
300 INLINE int ParticleSystem::
301 get_litter_size() const {
302  return _litter_size;
303 }
304 
305 /**
306 
307  */
308 INLINE int ParticleSystem::
309 get_litter_spread() const {
310  return _litter_spread;
311 }
312 
313 /**
314 
315  */
316 INLINE BaseParticleRenderer *ParticleSystem::
317 get_renderer() const {
318  return _renderer;
319 }
320 
321 /**
322 
323  */
324 INLINE BaseParticleEmitter *ParticleSystem::
325 get_emitter() const {
326  return _emitter;
327 }
328 
329 /**
330 
331  */
332 INLINE BaseParticleFactory *ParticleSystem::
333 get_factory() const {
334  return _factory;
335 }
336 
337 /**
338 
339  */
340 INLINE PN_stdfloat ParticleSystem::
341 get_floor_z() const {
342  return _floor_z;
343 }
344 
345 /**
346 
347  */
348 INLINE int ParticleSystem::
349 get_living_particles() const {
350  return _living_particles;
351 }
352 
353 /**
354 
355  */
356 INLINE bool ParticleSystem::
357 get_active_system_flag() const {
358  return _active_system_flag;
359 }
360 
361 /**
362 
363  */
364 INLINE bool ParticleSystem::
365 get_local_velocity_flag() const {
366  return _local_velocity_flag;
367 }
368 
369 /**
370 
371  */
372 INLINE bool ParticleSystem::
373 get_spawn_on_death_flag() const {
374  return _spawn_on_death_flag;
375 }
376 
377 /**
378 
379  */
380 INLINE bool ParticleSystem::
381 get_system_grows_older_flag() const {
382  return _system_grows_older_flag;
383 }
384 
385 /**
386 
387  */
388 INLINE PN_stdfloat ParticleSystem::
389 get_system_lifespan() const {
390  return _system_lifespan;
391 }
392 
393 /**
394 
395  */
396 INLINE PN_stdfloat ParticleSystem::
397 get_system_age() const {
398  return _system_age;
399 }
400 
401 /**
402 
403  */
404 INLINE bool ParticleSystem::
405 get_i_was_spawned_flag() const {
406  return _i_was_spawned_flag;
407 }
408 
409 /**
410 
411  */
412 INLINE PandaNode *ParticleSystem::
413 get_spawn_render_node() const {
414  return _spawn_render_node_path.node();
415 }
416 
417 /**
418 
419  */
420 INLINE NodePath ParticleSystem::
421 get_spawn_render_node_path() const {
422  return _spawn_render_node_path;
423 }
424 
425 /**
426 
427  */
428 INLINE NodePath ParticleSystem::
429 get_render_parent() const {
430  return _render_parent;
431 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
Pure Virtual base class for creating particles.
void induce_labor()
Forces the birth of a particle litter this frame by resetting _tics_since_birth.
void clear_physics_objects()
Erases the object list.
Definition: physical.I:38
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:391
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.
PandaNode * node() const
Returns the referenced node of the path.
Definition: nodePath.I:227
An individual, physically-modelable particle abstract base class.
Definition: baseParticle.h:23
void remove_node(Thread *current_thread=Thread::get_current_thread())
Disconnects the referenced node from the scene graph.
Definition: nodePath.cxx:591
void render()
Populates an attached GeomNode structure with the particle geometry for rendering.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161