Changeset 13041 for OpenSceneGraph/trunk/include/osgParticle/ParticleSystem
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgParticle/ParticleSystem
r12056 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 54 54 class OSGPARTICLE_EXPORT ParticleSystem: public osg::Drawable { 55 55 public: 56 56 57 57 enum Alignment { 58 58 BILLBOARD, … … 64 64 65 65 META_Object(osgParticle, ParticleSystem); 66 66 67 67 /// Get the alignment type of particles. 68 68 inline Alignment getParticleAlignment() const; 69 69 70 70 /// Set the alignment type of particles. 71 71 inline void setParticleAlignment(Alignment a); 72 72 73 73 /// Get the X-axis alignment vector. 74 74 inline const osg::Vec3& getAlignVectorX() const; 75 75 76 76 /// Set the X-axis alignment vector. 77 77 inline void setAlignVectorX(const osg::Vec3& v); … … 79 79 /// Get the Y-axis alignment vector. 80 80 inline const osg::Vec3& getAlignVectorY() const; 81 81 82 82 /// Set the Y-axis alignment vector. 83 83 inline void setAlignVectorY(const osg::Vec3& v); 84 84 85 85 /// Set the alignment vectors. 86 86 inline void setAlignVectors(const osg::Vec3& X, const osg::Vec3& Y); … … 103 103 104 104 /// Get the default bounding box 105 inline const osg::BoundingBox& getDefaultBoundingBox() const; 106 105 inline const osg::BoundingBox& getDefaultBoundingBox() const; 106 107 107 /** Set the default bounding box. 108 108 The default bounding box is used when a real bounding box cannot be computed, for example … … 113 113 /// Return true if we use vertex arrays for rendering particles. 114 114 bool getUseVertexArray() const { return _useVertexArray; } 115 115 116 116 /** Set to use vertex arrays for rendering particles. 117 117 Lots of variables will be omitted: particles' shape, alive or not, visibility distance, and so on, … … 121 121 */ 122 122 void setUseVertexArray(bool v) { _useVertexArray = v; } 123 123 124 124 /// Return true if shaders are required. 125 125 bool getUseShaders() const { return _useShaders; } 126 126 127 127 /** Set to use GLSL shaders for rendering particles. 128 128 Particles' parameters will be used as shader attribute arrays, and necessary variables, including … … 130 130 */ 131 131 void setUseShaders(bool v) { _useShaders = v; _dirty_uniforms = true; } 132 132 133 133 /// Get the double pass rendering flag. 134 134 inline bool getDoublePassRendering() const; 135 135 136 136 /** Set the double pass rendering flag. 137 137 Double pass rendering avoids overdraw problems between particle systems … … 142 142 */ 143 143 inline void setDoublePassRendering(bool v); 144 144 145 145 /// Return true if the particle system is frozen. 146 146 bool getFrozen() const { return _frozen; } 147 147 inline bool isFrozen() const; 148 148 149 149 /** Set or reset the <I>frozen</I> state. 150 150 When the particle system is frozen, emitters and programs won't do anything on it. … … 154 154 /// Get the number of allocated particles (alive + dead). 155 155 inline int numParticles() const; 156 156 157 157 /// Get the number of dead particles. 158 158 inline int numDeadParticles() const; 159 159 160 /// Get whether all particles are dead 160 /// Get whether all particles are dead 161 161 inline bool areAllParticlesDead() const { return numDeadParticles()==numParticles(); } 162 162 163 163 /// Get a pointer to the i-th particle. 164 164 inline Particle* getParticle(int i); 165 165 166 166 /// Get a const pointer to the i-th particle. 167 167 inline const Particle* getParticle(int i) const; 168 168 169 169 /// Create a new particle from the specified template (or the default one if <CODE>ptemplate</CODE> is null). 170 170 inline virtual Particle* createParticle(const Particle* ptemplate); 171 171 172 172 /// Destroy the i-th particle. 173 173 inline virtual void destroyParticle(int i); 174 174 175 175 /// Reuse the i-th particle. 176 176 inline virtual void reuseParticle(int i) { _deadparts.push(&(_particles[i])); } … … 178 178 /// Get the last frame number. 179 179 inline unsigned int getLastFrameNumber() const; 180 180 181 181 /// Get the unique delta time for emitters and updaters to use 182 182 inline double& getDeltaTime( double currentTime ); … … 184 184 /// Get a reference to the default particle template. 185 185 inline Particle& getDefaultParticleTemplate(); 186 186 187 187 /// Get a const reference to the default particle template. 188 188 inline const Particle& getDefaultParticleTemplate() const; … … 190 190 /// Set the default particle template (particle is copied). 191 191 inline void setDefaultParticleTemplate(const Particle& p); 192 192 193 193 /// Get whether the particle system can freeze when culled 194 194 inline bool getFreezeOnCull() const; 195 195 196 196 /// Set whether the particle system can freeze when culled (default is true) 197 197 inline void setFreezeOnCull(bool v); 198 198 199 199 /** A useful method to set the most common <CODE>StateAttribute</CODE>'s in one call. 200 200 If <CODE>texturefile</CODE> is empty, then texturing is turned off. 201 201 */ 202 202 void setDefaultAttributes(const std::string& texturefile = "", bool emissive_particles = true, bool lighting = false, int texture_unit = 0); 203 203 204 204 /** A useful method to set the most common <CODE>StateAttribute</CODE> and use GLSL shaders to draw particles. 205 205 At present, when enabling shaders in the particle system, user-defined shapes will not be usable. … … 207 207 */ 208 208 void setDefaultAttributesUsingShaders(const std::string& texturefile = "", bool emissive_particles = true, int texture_unit = 0); 209 209 210 210 /// (<B>EXPERIMENTAL</B>) Get the level of detail. 211 211 inline int getLevelOfDetail() const; 212 212 213 213 /** (<B>EXPERIMENTAL</B>) Set the level of detail. The total number of particles is divided by the detail value to 214 214 get the actual number of particles to be drawn. This value must be greater than zero. 215 215 */ 216 216 inline void setLevelOfDetail(int v); 217 217 218 218 enum SortMode 219 219 { … … 222 222 SORT_BACK_TO_FRONT 223 223 }; 224 224 225 225 /// Get the sort mode. 226 226 inline SortMode getSortMode() const; 227 227 228 228 /** Set the sort mode. It will force resorting the particle list by the Z direction of the view coordinates. 229 229 This can be used for the purpose of transparent rendering or <CODE>setVisibilityDistance()</CODE>. 230 230 */ 231 231 inline void setSortMode(SortMode mode); 232 232 233 233 /// Get the visibility distance. 234 234 inline double getVisibilityDistance() const; 235 235 236 236 /** Set the visibility distance which allows the particles to be rendered only when depth is inside the distance. 237 237 When using shaders, it can work well directly; otherwise the sort mode should also be set to pre-compute depth. … … 245 245 246 246 virtual osg::BoundingBox computeBound() const; 247 247 248 248 #ifdef OSGPARTICLE_USE_ReadWriteMutex 249 249 typedef OpenThreads::ReadWriteMutex ReadWriterMutex; … … 273 273 Particle_vector _particles; 274 274 Death_stack _deadparts; 275 275 276 276 osg::BoundingBox _def_bbox; 277 277 278 278 Alignment _alignment; 279 279 osg::Vec3 _align_X_axis; 280 280 osg::Vec3 _align_Y_axis; 281 281 ParticleScaleReferenceFrame _particleScaleReferenceFrame; 282 282 283 283 bool _useVertexArray; 284 284 bool _useShaders; 285 285 bool _dirty_uniforms; 286 286 287 287 bool _doublepass; 288 288 bool _frozen; … … 298 298 mutable bool _dirty_dt; 299 299 bool _freeze_on_cull; 300 300 301 301 double _t0; 302 302 double _dt; 303 303 304 304 int _detail; 305 305 SortMode _sortMode; 306 306 double _visibilityDistance; 307 307 308 308 mutable int _draw_count; 309 309 310 310 mutable ReadWriterMutex _readWriteMutex; 311 311 }; 312 312 313 313 // INLINE FUNCTIONS 314 314 315 315 inline ParticleSystem::Alignment ParticleSystem::getParticleAlignment() const 316 316 { 317 317 return _alignment; 318 318 } 319 319 320 320 inline void ParticleSystem::setParticleAlignment(Alignment a) 321 321 { 322 322 _alignment = a; 323 323 } 324 324 325 325 inline const osg::Vec3& ParticleSystem::getAlignVectorX() const 326 326 { 327 327 return _align_X_axis; 328 328 } 329 329 330 330 inline void ParticleSystem::setAlignVectorX(const osg::Vec3& v) 331 331 { … … 337 337 return _align_Y_axis; 338 338 } 339 339 340 340 inline void ParticleSystem::setAlignVectorY(const osg::Vec3& v) 341 341 { 342 342 _align_Y_axis = v; 343 343 } 344 344 345 345 inline void ParticleSystem::setAlignVectors(const osg::Vec3& X, const osg::Vec3& Y) 346 346 { … … 353 353 return _frozen; 354 354 } 355 355 356 356 inline void ParticleSystem::setFrozen(bool v) 357 357 { 358 358 _frozen = v; 359 359 } 360 360 361 361 inline const osg::BoundingBox& ParticleSystem::getDefaultBoundingBox() const 362 362 { 363 363 return _def_bbox; 364 364 } 365 365 366 366 inline void ParticleSystem::setDefaultBoundingBox(const osg::BoundingBox& bbox) 367 367 { … … 403 403 _particles[i].kill(); 404 404 } 405 405 406 406 inline unsigned int ParticleSystem::getLastFrameNumber() const 407 407 { 408 408 return _last_frame; 409 409 } 410 410 411 411 inline double& ParticleSystem::getDeltaTime( double currentTime ) 412 412 { … … 415 415 _dt = currentTime - _t0; 416 416 if ( _dt<0.0 ) _dt = 0.0; 417 417 418 418 _t0 = currentTime; 419 419 _dirty_dt = false; … … 436 436 if (p.z() + r > _bmax.z()) _bmax.z() = p.z() + r; 437 437 } 438 if (!_bounds_computed) 438 if (!_bounds_computed) 439 439 _bounds_computed = true; 440 440 } … … 454 454 _def_ptemp = p; 455 455 } 456 456 457 457 inline bool ParticleSystem::getFreezeOnCull() const 458 458 { 459 459 return _freeze_on_cull; 460 460 } 461 461 462 462 inline void ParticleSystem::setFreezeOnCull(bool v) 463 463 { 464 464 _freeze_on_cull = v; 465 465 } 466 466 467 467 inline int ParticleSystem::getLevelOfDetail() const 468 468 { 469 469 return _detail; 470 470 } 471 471 472 472 inline void ParticleSystem::setLevelOfDetail(int v) 473 473 { … … 475 475 _detail = v; 476 476 } 477 477 478 478 inline ParticleSystem::SortMode ParticleSystem::getSortMode() const 479 479 { 480 480 return _sortMode; 481 481 } 482 482 483 483 inline void ParticleSystem::setSortMode(SortMode mode) 484 484 { 485 485 _sortMode = mode; 486 486 } 487 487 488 488 inline double ParticleSystem::getVisibilityDistance() const 489 489 { 490 490 return _visibilityDistance; 491 491 } 492 492 493 493 inline void ParticleSystem::setVisibilityDistance(double distance) 494 494 { … … 496 496 if (_useShaders) _dirty_uniforms = true; 497 497 } 498 499 // I'm not sure this function should be inlined... 500 498 499 // I'm not sure this function should be inlined... 500 501 501 inline Particle* ParticleSystem::createParticle(const Particle* ptemplate) 502 502 {
