00001 // Filename: particleSystem.I 00002 // Created by: charles (14Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function : render 00021 // Access : Public 00022 // Description : Populates an attached GeomNode structure with the 00023 // particle geometry for rendering. This is a 00024 // wrapper for accessability. 00025 //////////////////////////////////////////////////////////////////// 00026 00027 INLINE void ParticleSystem:: 00028 render(void) { 00029 _renderer->render(_physics_objects, _living_particles); 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function : induce_labor 00034 // Access : Public 00035 // Description : Forces the birth of a particle litter this frame 00036 // by resetting _tics_since_birth 00037 //////////////////////////////////////////////////////////////////// 00038 00039 INLINE void ParticleSystem:: 00040 induce_labor(void) { 00041 _tics_since_birth = _birth_rate; 00042 } 00043 00044 //// /////////////////////////////////////////////////////// 00045 //// SET METHODS /////////////////////////////////////////////////////// 00046 //// /////////////////////////////////////////////////////// 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function : set_pool_size 00050 // Access : Public 00051 //////////////////////////////////////////////////////////////////// 00052 00053 INLINE void ParticleSystem:: 00054 set_pool_size(int size) { 00055 resize_pool(size); 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function : set_birth_rate 00060 // Access : Public 00061 //////////////////////////////////////////////////////////////////// 00062 00063 INLINE void ParticleSystem:: 00064 set_birth_rate(float new_br) { 00065 _birth_rate = new_br; 00066 if(IS_NEARLY_ZERO(_birth_rate)) _birth_rate = NEARLY_ZERO(float); 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function : set_litter_size 00071 // Access : Public 00072 //////////////////////////////////////////////////////////////////// 00073 00074 INLINE void ParticleSystem:: 00075 set_litter_size(int new_ls) { 00076 _litter_size = new_ls; 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function : set_litter_spread 00081 // Access : Public 00082 //////////////////////////////////////////////////////////////////// 00083 00084 INLINE void ParticleSystem:: 00085 set_litter_spread(int new_ls) { 00086 _litter_spread = new_ls; 00087 } 00088 00089 //////////////////////////////////////////////////////////////////// 00090 // Function : set_renderer 00091 // Access : Public 00092 //////////////////////////////////////////////////////////////////// 00093 00094 INLINE void ParticleSystem:: 00095 set_renderer(BaseParticleRenderer *r) { 00096 _renderer = r; 00097 _renderer->resize_pool(_particle_pool_size); 00098 00099 if (!_render_node.is_null()) 00100 _render_parent->remove_child(_render_node); 00101 00102 _render_node = _renderer->get_render_node(); 00103 _render_parent->add_child(_render_node); 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function : set_emitter 00108 // Access : Public 00109 //////////////////////////////////////////////////////////////////// 00110 00111 INLINE void ParticleSystem:: 00112 set_emitter(BaseParticleEmitter *e) { 00113 _emitter = e; 00114 } 00115 00116 //////////////////////////////////////////////////////////////////// 00117 // Function : set_factory 00118 // Access : Public 00119 //////////////////////////////////////////////////////////////////// 00120 00121 INLINE void ParticleSystem:: 00122 set_factory(BaseParticleFactory *f) { 00123 int pool_size = _particle_pool_size; 00124 set_pool_size(0); 00125 _factory = f; 00126 clear_physics_objects(); 00127 set_pool_size(pool_size); 00128 } 00129 00130 //////////////////////////////////////////////////////////////////// 00131 // Function : set_active_state 00132 // Access : public 00133 //////////////////////////////////////////////////////////////////// 00134 00135 INLINE void ParticleSystem:: 00136 set_active_system_flag(bool a) { 00137 _active_system_flag = a; 00138 } 00139 00140 //////////////////////////////////////////////////////////////////// 00141 // Function : set_local_velocity_flag 00142 // Access : public 00143 //////////////////////////////////////////////////////////////////// 00144 00145 INLINE void ParticleSystem:: 00146 set_local_velocity_flag(bool lv) { 00147 _local_velocity_flag = lv; 00148 } 00149 00150 //////////////////////////////////////////////////////////////////// 00151 // Function : set_spawn_on_death_flag 00152 // Access : public 00153 //////////////////////////////////////////////////////////////////// 00154 00155 INLINE void ParticleSystem:: 00156 set_spawn_on_death_flag(bool sod) { 00157 _spawn_on_death_flag = sod; 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function : set_system_grows_older_flag 00162 // Access : public 00163 //////////////////////////////////////////////////////////////////// 00164 00165 INLINE void ParticleSystem:: 00166 set_system_grows_older_flag(bool sgo) { 00167 _system_grows_older_flag = sgo; 00168 } 00169 00170 //////////////////////////////////////////////////////////////////// 00171 // Function : set_system_lifespan 00172 // Access : public 00173 //////////////////////////////////////////////////////////////////// 00174 00175 INLINE void ParticleSystem:: 00176 set_system_lifespan(float sl) { 00177 _system_lifespan = sl; 00178 } 00179 00180 //////////////////////////////////////////////////////////////////// 00181 // Function : set_system_age 00182 // Access : public 00183 //////////////////////////////////////////////////////////////////// 00184 00185 INLINE void ParticleSystem:: 00186 set_system_age(float age) { 00187 _system_age = age; 00188 } 00189 00190 //////////////////////////////////////////////////////////////////// 00191 // Function : set_spawn_render_node 00192 // Access : public 00193 //////////////////////////////////////////////////////////////////// 00194 00195 INLINE void ParticleSystem:: 00196 set_spawn_render_node(PandaNode *node) { 00197 _spawn_render_node = node; 00198 } 00199 00200 //////////////////////////////////////////////////////////////////// 00201 // Function : set_render_parent 00202 // Access : public 00203 //////////////////////////////////////////////////////////////////// 00204 00205 INLINE void ParticleSystem:: 00206 set_render_parent(PandaNode *node) { 00207 if (!_render_node.is_null()) 00208 _render_parent->remove_child(_render_node); 00209 00210 _render_parent = node; 00211 _render_node = _renderer->get_render_node(); 00212 _render_parent->add_child(_render_node); 00213 } 00214 00215 //////////////////////////////////////////////////////////////////// 00216 // Function : set_template_system_flag 00217 // Access : public 00218 //////////////////////////////////////////////////////////////////// 00219 00220 INLINE void ParticleSystem:: 00221 set_template_system_flag(bool tsf) { 00222 _template_system_flag = tsf; 00223 } 00224 00225 //////////////////////////////////////////////////////////////////// 00226 // Function : add_spawn_template 00227 // Access : public 00228 //////////////////////////////////////////////////////////////////// 00229 INLINE void ParticleSystem:: 00230 add_spawn_template(ParticleSystem *ps) { 00231 _spawn_templates.push_back(ps); 00232 } 00233 00234 //////////////////////////////////////////////////////////////////// 00235 // Function : clear_spawn_templates 00236 // Access : public 00237 //////////////////////////////////////////////////////////////////// 00238 INLINE void ParticleSystem:: 00239 clear_spawn_templates(void) { 00240 _spawn_templates.erase(_spawn_templates.begin(), 00241 _spawn_templates.end()); 00242 } 00243 00244 //// ///////////////////////////////////////////////////// 00245 //// GET METHODS ///////////////////////////////////////////////////// 00246 //// ///////////////////////////////////////////////////// 00247 00248 //////////////////////////////////////////////////////////////////// 00249 // Function : get_pool_size 00250 // Access : Public 00251 //////////////////////////////////////////////////////////////////// 00252 INLINE int ParticleSystem:: 00253 get_pool_size(void) const { 00254 return _particle_pool_size; 00255 } 00256 00257 //////////////////////////////////////////////////////////////////// 00258 // Function : get_birth_rate 00259 // Access : Public 00260 //////////////////////////////////////////////////////////////////// 00261 INLINE float ParticleSystem:: 00262 get_birth_rate(void) const { 00263 return _birth_rate; 00264 } 00265 00266 //////////////////////////////////////////////////////////////////// 00267 // Function : get_litter_size 00268 // Access : Public 00269 //////////////////////////////////////////////////////////////////// 00270 INLINE int ParticleSystem:: 00271 get_litter_size(void) const { 00272 return _litter_size; 00273 } 00274 00275 //////////////////////////////////////////////////////////////////// 00276 // Function : get_litter_spread 00277 // Access : Public 00278 //////////////////////////////////////////////////////////////////// 00279 INLINE int ParticleSystem:: 00280 get_litter_spread(void) const { 00281 return _litter_spread; 00282 } 00283 00284 //////////////////////////////////////////////////////////////////// 00285 // Function : get_renderer 00286 // Access : Public 00287 //////////////////////////////////////////////////////////////////// 00288 INLINE BaseParticleRenderer *ParticleSystem:: 00289 get_renderer(void) const { 00290 return _renderer; 00291 } 00292 00293 //////////////////////////////////////////////////////////////////// 00294 // Function : get_emitter 00295 // Access : Public 00296 //////////////////////////////////////////////////////////////////// 00297 INLINE BaseParticleEmitter *ParticleSystem:: 00298 get_emitter(void) const { 00299 return _emitter; 00300 } 00301 00302 //////////////////////////////////////////////////////////////////// 00303 // Function : get_factory 00304 // Access : Public 00305 //////////////////////////////////////////////////////////////////// 00306 INLINE BaseParticleFactory *ParticleSystem:: 00307 get_factory(void) const { 00308 return _factory; 00309 } 00310 00311 //////////////////////////////////////////////////////////////////// 00312 // Function : get_living_particles 00313 // Access : Public 00314 //////////////////////////////////////////////////////////////////// 00315 INLINE int ParticleSystem:: 00316 get_living_particles(void) const { 00317 return _living_particles; 00318 } 00319 00320 //////////////////////////////////////////////////////////////////// 00321 // Function : get_active_state 00322 // Access : public 00323 //////////////////////////////////////////////////////////////////// 00324 INLINE bool ParticleSystem:: 00325 get_active_system_flag(void) const { 00326 return _active_system_flag; 00327 } 00328 00329 //////////////////////////////////////////////////////////////////// 00330 // Function : get_local_velocity_flag 00331 // Access : public 00332 //////////////////////////////////////////////////////////////////// 00333 INLINE bool ParticleSystem:: 00334 get_local_velocity_flag(void) const { 00335 return _local_velocity_flag; 00336 } 00337 00338 //////////////////////////////////////////////////////////////////// 00339 // Function : get_spawn_on_death_flag 00340 // Access : public 00341 //////////////////////////////////////////////////////////////////// 00342 INLINE bool ParticleSystem:: 00343 get_spawn_on_death_flag(void) const { 00344 return _spawn_on_death_flag; 00345 } 00346 00347 //////////////////////////////////////////////////////////////////// 00348 // Function : get_system_grows_older_flag 00349 // Access : public 00350 //////////////////////////////////////////////////////////////////// 00351 INLINE bool ParticleSystem:: 00352 get_system_grows_older_flag(void) const { 00353 return _system_grows_older_flag; 00354 } 00355 00356 //////////////////////////////////////////////////////////////////// 00357 // Function : get_system_lifespan 00358 // Access : public 00359 //////////////////////////////////////////////////////////////////// 00360 INLINE float ParticleSystem:: 00361 get_system_lifespan(void) const { 00362 return _system_lifespan; 00363 } 00364 00365 //////////////////////////////////////////////////////////////////// 00366 // Function : get_system_age 00367 // Access : public 00368 //////////////////////////////////////////////////////////////////// 00369 INLINE float ParticleSystem:: 00370 get_system_age(void) const { 00371 return _system_age; 00372 } 00373 00374 //////////////////////////////////////////////////////////////////// 00375 // Function : get_i_was_spawned_flag 00376 // Access : public 00377 //////////////////////////////////////////////////////////////////// 00378 INLINE bool ParticleSystem:: 00379 get_i_was_spawned_flag(void) const { 00380 return _i_was_spawned_flag; 00381 } 00382 00383 //////////////////////////////////////////////////////////////////// 00384 // Function : get_spawn_render_node 00385 // Access : public 00386 //////////////////////////////////////////////////////////////////// 00387 INLINE PandaNode *ParticleSystem:: 00388 get_spawn_render_node(void) const { 00389 return _spawn_render_node; 00390 } 00391 00392 //////////////////////////////////////////////////////////////////// 00393 // Function : get_render_parent 00394 // Access : public 00395 //////////////////////////////////////////////////////////////////// 00396 INLINE PandaNode *ParticleSystem:: 00397 get_render_parent(void) const { 00398 return _render_parent; 00399 }