Panda3D

particleSystem.I

00001 // Filename: particleSystem.I
00002 // Created by:  charles (14Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 ////////////////////////////////////////////////////////////////////
00016 //    Function : render
00017 //      Access : Public
00018 // Description : Populates an attached GeomNode structure with the
00019 //               particle geometry for rendering.  This is a
00020 //               wrapper for accessability.
00021 ////////////////////////////////////////////////////////////////////
00022 
00023 INLINE void ParticleSystem::
00024 render() {
00025   _renderer->render(_physics_objects, _living_particles);
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //    Function : induce_labor
00030 //      Access : Public
00031 // Description : Forces the birth of a particle litter this frame
00032 //               by resetting _tics_since_birth
00033 ////////////////////////////////////////////////////////////////////
00034 
00035 INLINE void ParticleSystem::
00036 induce_labor() {
00037   _tics_since_birth = _cur_birth_rate;
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //    Function : clear_to_initial
00042 //      Access : Public
00043 // Description : Resets the system to its start state by resizing to 0,
00044 //               then resizing back to current size.
00045 ////////////////////////////////////////////////////////////////////
00046 
00047 INLINE void ParticleSystem::
00048 clear_to_initial() {
00049   BaseParticle *bp;
00050   int i;
00051 
00052   for(i = 0; i < (int)_physics_objects.size(); i++) {
00053     bp = (BaseParticle *)_physics_objects[i].p();
00054     if(bp->get_alive()) {
00055       kill_particle(i);
00056     }
00057   }
00058   _tics_since_birth = 0.0f;
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //    Function : soft_start
00063 //      Access : Public
00064 // Description : Causes system to use birth rate set by set_birth_rate()
00065 ////////////////////////////////////////////////////////////////////
00066 
00067 INLINE void ParticleSystem::
00068 soft_start(PN_stdfloat br) {
00069   if (br > 0.0)
00070     set_birth_rate(br);
00071   _cur_birth_rate = _birth_rate;
00072   _tics_since_birth = 0.0f;
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //    Function : soft_stop
00077 //      Access : Public
00078 // Description : Causes system to use birth rate set by 
00079 //               set_soft_birth_rate()
00080 ////////////////////////////////////////////////////////////////////
00081 
00082 INLINE void ParticleSystem::
00083 soft_stop(PN_stdfloat br) {
00084   if (br > 0.0)
00085     set_soft_birth_rate(br);
00086   _cur_birth_rate = _soft_birth_rate;
00087   _tics_since_birth = 0.0f;
00088 }
00089 
00090 ////             ///////////////////////////////////////////////////////
00091 //// SET METHODS ///////////////////////////////////////////////////////
00092 ////             ///////////////////////////////////////////////////////
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //    Function : set_pool_size
00096 //      Access : Public
00097 ////////////////////////////////////////////////////////////////////
00098 
00099 INLINE void ParticleSystem::
00100 set_pool_size(int size) {
00101   resize_pool(size);
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //    Function : set_birth_rate
00106 //      Access : Public
00107 ////////////////////////////////////////////////////////////////////
00108 
00109 INLINE void ParticleSystem::
00110 set_birth_rate(PN_stdfloat new_br) {
00111   _birth_rate = new_br;
00112   _cur_birth_rate = _birth_rate;
00113   if(IS_NEARLY_ZERO(_birth_rate)) _birth_rate = NEARLY_ZERO(PN_stdfloat);
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //    Function : set_soft_birth_rate
00118 //      Access : Public
00119 ////////////////////////////////////////////////////////////////////
00120 
00121 INLINE void ParticleSystem::
00122 set_soft_birth_rate(PN_stdfloat new_br) {
00123   _soft_birth_rate = new_br;
00124   if(IS_NEARLY_ZERO(_soft_birth_rate)) _soft_birth_rate = NEARLY_ZERO(PN_stdfloat);
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //    Function : set_litter_size
00129 //      Access : Public
00130 ////////////////////////////////////////////////////////////////////
00131 
00132 INLINE void ParticleSystem::
00133 set_litter_size(int new_ls) {
00134   _litter_size = new_ls;
00135 }
00136 
00137 ////////////////////////////////////////////////////////////////////
00138 //    Function : set_litter_spread
00139 //      Access : Public
00140 ////////////////////////////////////////////////////////////////////
00141 INLINE void ParticleSystem::
00142 set_litter_spread(int new_ls) {
00143   _litter_spread = new_ls;
00144 }
00145 
00146 ////////////////////////////////////////////////////////////////////
00147 //    Function : set_renderer
00148 //      Access : Public
00149 ////////////////////////////////////////////////////////////////////
00150 INLINE void ParticleSystem::
00151 set_renderer(BaseParticleRenderer *r) {
00152   _renderer = r;
00153   _renderer->resize_pool(_particle_pool_size);
00154 
00155   _render_node_path.remove_node();
00156   _render_node_path = _renderer->get_render_node_path();
00157   _render_node_path.reparent_to(_render_parent);
00158 }
00159 
00160 ////////////////////////////////////////////////////////////////////
00161 //    Function : set_emitter
00162 //      Access : Public
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE void ParticleSystem::
00165 set_emitter(BaseParticleEmitter *e) {
00166   _emitter = e;
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //    Function : set_factory
00171 //      Access : Public
00172 ////////////////////////////////////////////////////////////////////
00173 INLINE void ParticleSystem::
00174 set_factory(BaseParticleFactory *f) {
00175   int pool_size = _particle_pool_size;
00176   set_pool_size(0);
00177   _factory = f;
00178   clear_physics_objects();
00179   set_pool_size(pool_size);
00180 }
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //    Function : set_floor_z
00184 //      Access : Public
00185 ////////////////////////////////////////////////////////////////////
00186 INLINE void ParticleSystem::
00187 set_floor_z(PN_stdfloat z) {
00188   _floor_z = z;
00189 }
00190 
00191 ////////////////////////////////////////////////////////////////////
00192 //    Function : set_active_state
00193 //      Access : public
00194 ////////////////////////////////////////////////////////////////////
00195 INLINE void ParticleSystem::
00196 set_active_system_flag(bool a) {
00197   _active_system_flag = a;
00198 }
00199 
00200 ////////////////////////////////////////////////////////////////////
00201 //    Function : set_local_velocity_flag
00202 //      Access : public
00203 ////////////////////////////////////////////////////////////////////
00204 INLINE void ParticleSystem::
00205 set_local_velocity_flag(bool lv) {
00206   _local_velocity_flag = lv;
00207 }
00208 
00209 ////////////////////////////////////////////////////////////////////
00210 //    Function : set_spawn_on_death_flag
00211 //      Access : public
00212 ////////////////////////////////////////////////////////////////////
00213 INLINE void ParticleSystem::
00214 set_spawn_on_death_flag(bool sod) {
00215   _spawn_on_death_flag = sod;
00216 }
00217 
00218 ////////////////////////////////////////////////////////////////////
00219 //    Function : set_system_grows_older_flag
00220 //      Access : public
00221 ////////////////////////////////////////////////////////////////////
00222 INLINE void ParticleSystem::
00223 set_system_grows_older_flag(bool sgo) {
00224   _system_grows_older_flag = sgo;
00225 }
00226 
00227 ////////////////////////////////////////////////////////////////////
00228 //    Function : set_system_lifespan
00229 //      Access : public
00230 ////////////////////////////////////////////////////////////////////
00231 
00232 INLINE void ParticleSystem::
00233 set_system_lifespan(PN_stdfloat sl) {
00234   _system_lifespan = sl;
00235 }
00236 
00237 ////////////////////////////////////////////////////////////////////
00238 //    Function : set_system_age
00239 //      Access : public
00240 ////////////////////////////////////////////////////////////////////
00241 
00242 INLINE void ParticleSystem::
00243 set_system_age(PN_stdfloat age) {
00244   _system_age = age;
00245 }
00246 
00247 ////////////////////////////////////////////////////////////////////
00248 //    Function : set_spawn_render_node
00249 //      Access : public
00250 ////////////////////////////////////////////////////////////////////
00251 INLINE void ParticleSystem::
00252 set_spawn_render_node(PandaNode *node) {
00253   set_spawn_render_node_path(NodePath(node));
00254 }
00255 
00256 ////////////////////////////////////////////////////////////////////
00257 //    Function : set_spawn_render_node_path
00258 //      Access : public
00259 ////////////////////////////////////////////////////////////////////
00260 INLINE void ParticleSystem::
00261 set_spawn_render_node_path(const NodePath &node) {
00262   _spawn_render_node_path = node;
00263 }
00264 
00265 ////////////////////////////////////////////////////////////////////
00266 //    Function : set_render_parent
00267 //      Access : public
00268 ////////////////////////////////////////////////////////////////////
00269 INLINE void ParticleSystem::
00270 set_render_parent(PandaNode *node) {
00271   set_render_parent(NodePath(node));
00272 }
00273 
00274 ////////////////////////////////////////////////////////////////////
00275 //    Function : set_render_parent
00276 //      Access : public
00277 ////////////////////////////////////////////////////////////////////
00278 INLINE void ParticleSystem::
00279 set_render_parent(const NodePath &node) {
00280   _render_node_path.remove_node();
00281 
00282   _render_parent = node;
00283   _render_node_path = _renderer->get_render_node_path();
00284   _render_node_path.reparent_to(_render_parent);
00285 }
00286 
00287 ////////////////////////////////////////////////////////////////////
00288 //    Function : set_template_system_flag
00289 //      Access : public
00290 ////////////////////////////////////////////////////////////////////
00291 
00292 INLINE void ParticleSystem::
00293 set_template_system_flag(bool tsf) {
00294   _template_system_flag = tsf;
00295 }
00296 
00297 ////////////////////////////////////////////////////////////////////
00298 //    Function : add_spawn_template
00299 //      Access : public
00300 ////////////////////////////////////////////////////////////////////
00301 INLINE void ParticleSystem::
00302 add_spawn_template(ParticleSystem *ps) {
00303   _spawn_templates.push_back(ps);
00304 }
00305 
00306 ////////////////////////////////////////////////////////////////////
00307 //    Function : clear_spawn_templates
00308 //      Access : public
00309 ////////////////////////////////////////////////////////////////////
00310 INLINE void ParticleSystem::
00311 clear_spawn_templates() {
00312   _spawn_templates.erase(_spawn_templates.begin(),
00313                          _spawn_templates.end());
00314 }
00315 
00316 ////////////////////////////////////////////////////////////////////
00317 //    Function : clear_floor_z
00318 //      Access : Public
00319 ////////////////////////////////////////////////////////////////////
00320 INLINE void ParticleSystem::
00321 clear_floor_z() {
00322   _floor_z = -HUGE_VAL;
00323 }
00324 
00325 ////             /////////////////////////////////////////////////////
00326 //// GET METHODS /////////////////////////////////////////////////////
00327 ////             /////////////////////////////////////////////////////
00328 
00329 ////////////////////////////////////////////////////////////////////
00330 //    Function : get_pool_size
00331 //      Access : Public
00332 ////////////////////////////////////////////////////////////////////
00333 INLINE int ParticleSystem::
00334 get_pool_size() const {
00335   return _particle_pool_size;
00336 }
00337 
00338 ////////////////////////////////////////////////////////////////////
00339 //    Function : get_birth_rate
00340 //      Access : Public
00341 ////////////////////////////////////////////////////////////////////
00342 INLINE PN_stdfloat ParticleSystem::
00343 get_birth_rate() const {
00344   return _birth_rate;
00345 }
00346 
00347 ////////////////////////////////////////////////////////////////////
00348 //    Function : get_soft_birth_rate
00349 //      Access : Public
00350 ////////////////////////////////////////////////////////////////////
00351 INLINE PN_stdfloat ParticleSystem::
00352 get_soft_birth_rate() const {
00353   return _soft_birth_rate;
00354 }
00355 
00356 ////////////////////////////////////////////////////////////////////
00357 //    Function : get_litter_size
00358 //      Access : Public
00359 ////////////////////////////////////////////////////////////////////
00360 INLINE int ParticleSystem::
00361 get_litter_size() const {
00362   return _litter_size;
00363 }
00364 
00365 ////////////////////////////////////////////////////////////////////
00366 //    Function : get_litter_spread
00367 //      Access : Public
00368 ////////////////////////////////////////////////////////////////////
00369 INLINE int ParticleSystem::
00370 get_litter_spread() const {
00371   return _litter_spread;
00372 }
00373 
00374 ////////////////////////////////////////////////////////////////////
00375 //    Function : get_renderer
00376 //      Access : Public
00377 ////////////////////////////////////////////////////////////////////
00378 INLINE BaseParticleRenderer *ParticleSystem::
00379 get_renderer() const {
00380   return _renderer;
00381 }
00382 
00383 ////////////////////////////////////////////////////////////////////
00384 //    Function : get_emitter
00385 //      Access : Public
00386 ////////////////////////////////////////////////////////////////////
00387 INLINE BaseParticleEmitter *ParticleSystem::
00388 get_emitter() const {
00389   return _emitter;
00390 }
00391 
00392 ////////////////////////////////////////////////////////////////////
00393 //    Function : get_factory
00394 //      Access : Public
00395 ////////////////////////////////////////////////////////////////////
00396 INLINE BaseParticleFactory *ParticleSystem::
00397 get_factory() const {
00398   return _factory;
00399 }
00400 
00401 ////////////////////////////////////////////////////////////////////
00402 //    Function : get_factory
00403 //      Access : Public
00404 ////////////////////////////////////////////////////////////////////
00405 INLINE PN_stdfloat ParticleSystem::
00406 get_floor_z() const {
00407   return _floor_z;
00408 }
00409 
00410 ////////////////////////////////////////////////////////////////////
00411 //    Function : get_living_particles
00412 //      Access : Public
00413 ////////////////////////////////////////////////////////////////////
00414 INLINE int ParticleSystem::
00415 get_living_particles() const {
00416   return _living_particles;
00417 }
00418 
00419 ////////////////////////////////////////////////////////////////////
00420 //    Function : get_active_state
00421 //      Access : public
00422 ////////////////////////////////////////////////////////////////////
00423 INLINE bool ParticleSystem::
00424 get_active_system_flag() const {
00425   return _active_system_flag;
00426 }
00427 
00428 ////////////////////////////////////////////////////////////////////
00429 //    Function : get_local_velocity_flag
00430 //      Access : public
00431 ////////////////////////////////////////////////////////////////////
00432 INLINE bool ParticleSystem::
00433 get_local_velocity_flag() const {
00434   return _local_velocity_flag;
00435 }
00436 
00437 ////////////////////////////////////////////////////////////////////
00438 //    Function : get_spawn_on_death_flag
00439 //      Access : public
00440 ////////////////////////////////////////////////////////////////////
00441 INLINE bool ParticleSystem::
00442 get_spawn_on_death_flag() const {
00443   return _spawn_on_death_flag;
00444 }
00445 
00446 ////////////////////////////////////////////////////////////////////
00447 //    Function : get_system_grows_older_flag
00448 //      Access : public
00449 ////////////////////////////////////////////////////////////////////
00450 INLINE bool ParticleSystem::
00451 get_system_grows_older_flag() const {
00452   return _system_grows_older_flag;
00453 }
00454 
00455 ////////////////////////////////////////////////////////////////////
00456 //    Function : get_system_lifespan
00457 //      Access : public
00458 ////////////////////////////////////////////////////////////////////
00459 INLINE PN_stdfloat ParticleSystem::
00460 get_system_lifespan() const {
00461   return _system_lifespan;
00462 }
00463 
00464 ////////////////////////////////////////////////////////////////////
00465 //    Function : get_system_age
00466 //      Access : public
00467 ////////////////////////////////////////////////////////////////////
00468 INLINE PN_stdfloat ParticleSystem::
00469 get_system_age() const {
00470   return _system_age;
00471 }
00472 
00473 ////////////////////////////////////////////////////////////////////
00474 //    Function : get_i_was_spawned_flag
00475 //      Access : public
00476 ////////////////////////////////////////////////////////////////////
00477 INLINE bool ParticleSystem::
00478 get_i_was_spawned_flag() const {
00479   return _i_was_spawned_flag;
00480 }
00481 
00482 ////////////////////////////////////////////////////////////////////
00483 //    Function : get_spawn_render_node
00484 //      Access : public
00485 ////////////////////////////////////////////////////////////////////
00486 INLINE PandaNode *ParticleSystem::
00487 get_spawn_render_node() const {
00488   return _spawn_render_node_path.node();
00489 }
00490 
00491 ////////////////////////////////////////////////////////////////////
00492 //    Function : get_spawn_render_node_path
00493 //      Access : public
00494 ////////////////////////////////////////////////////////////////////
00495 INLINE NodePath ParticleSystem::
00496 get_spawn_render_node_path() const {
00497   return _spawn_render_node_path;
00498 }
00499 
00500 ////////////////////////////////////////////////////////////////////
00501 //    Function : get_render_parent
00502 //      Access : public
00503 ////////////////////////////////////////////////////////////////////
00504 INLINE NodePath ParticleSystem::
00505 get_render_parent() const {
00506   return _render_parent;
00507 }
 All Classes Functions Variables Enumerations