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