H3D API  2.4.1
ParticleSystem.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __PARTICLESYSTEM_H__
30 #define __PARTICLESYSTEM_H__
31 
32 #include <H3D/X3DShapeNode.h>
35 #include <H3D/TextureCoordinate.h>
36 #include <H3D/X3DColorNode.h>
37 #include <H3D/SFInt32.h>
38 #include <H3D/SFString.h>
39 #include <H3D/MFFloat.h>
40 #include <H3D/SFVec2f.h>
41 
42 // stl includes
43 #include <list>
44 
45 namespace H3D {
183  class H3DAPI_API ParticleSystem :
184  public X3DShapeNode {
185  public:
186 
191 
193  ParticleSystem( Inst< SFAppearanceNode > _appearance = 0,
194  Inst< SFGeometryNode > _geometry = 0,
195  Inst< SFHapticGeometry > _hapticGeometry = 0,
196  Inst< SFNode > _metadata = 0,
197  Inst< SFBound > _bound = 0,
198  Inst< SFVec3f > _bboxCenter = 0,
199  Inst< SFVec3f > _bboxSize = 0,
200  Inst< DisplayList > _displayList = 0,
201  Inst< SFBool > _createParticles = 0,
202  Inst< SFBool > _enabled = 0,
203  Inst< SFFloat > _lifetimeVariation = 0,
204  Inst< SFInt32 > _maxParticles = 0,
205  Inst< SFFloat > _particleLifetime = 0,
206  Inst< SFVec2f > _particleSize = 0,
207  Inst< SFBool > _isActive = 0,
208  Inst< SFColorNode > _colorRamp = 0,
209  Inst< MFFloat > _colorKey = 0,
210  Inst< SFEmitterNode > _emitter = 0,
211  Inst< SFString > _geometryType = 0,
212  Inst< MFPhysicsModelNode > _physics = 0,
213  Inst< SFTextureCoordinate> _texCoordRamp = 0,
214  Inst< MFFloat > _texCoordKey = 0
215  );
216  virtual void initialize();
217 
219  virtual void render();
220 
222  virtual void traverseSG( TraverseInfo &ti );
223 
226  X3DParticleEmitterNode::Particle::ParticleType getCurrentParticleType();
227 
229  static H3DFloat getVariationValue( H3DFloat main_value, H3DFloat variation );
230 
232  static H3DFloat getRandomValue( H3DFloat min, H3DFloat max );
233 
235  static Vec3f getRandomPointOnUnitSphere();
236 
248  H3DUniquePtr< SFBool > createParticles;
249 
264  H3DUniquePtr< SFBool > enabled;
265 
276  H3DUniquePtr< SFFloat > lifetimeVariation;
277 
284  H3DUniquePtr< SFInt32 > maxParticles;
285 
294  H3DUniquePtr< SFFloat > particleLifetime;
295 
307  H3DUniquePtr< SFVec2f > particleSize;
308 
315  H3DUniquePtr< SFBool > isActive;
316 
328  H3DUniquePtr< SFColorNode > colorRamp;
329 
336  H3DUniquePtr< MFFloat > colorKey;
337 
346  H3DUniquePtr< SFEmitterNode > emitter;
347 
359  H3DUniquePtr< SFString > geometryType;
360 
368  H3DUniquePtr< MFPhysicsModelNode > physics;
369 
376  H3DUniquePtr< SFTextureCoordinate > texCoordRamp;
377 
384  H3DUniquePtr< MFFloat > texCoordKey;
385 
388 
389  typedef std::list< X3DParticleEmitterNode::Particle > Particles;
390 
391  typedef list< ParticleSystem * > ParticleSystemList;
392 
394  static const ParticleSystemList &getAllParticleSystems() {
395  return particlesystems;
396  }
397 
398  protected:
399  H3DTime particle_system_time;
400  H3DTime last_time;
401  Particles particles;
402  bool update_bound;
403  static ParticleSystemList particlesystems;
404  };
405 }
406 
407 #endif
Contains the MFFloat field class.
Contains the SFInt32 field class.
Contains the SFString field class.
Contains the SFVec2f field class.
Header file for TextureCoordinate, X3D scene-graph node.
Header file for X3DColorNode, X3D scene-graph node.
Header file for X3DParticleEmitterNode, X3D scene-graph node.
Header file for X3DParticlePhysicsModelNode, X3D scene-graph node.
Header file for X3DShapeNode, X3D scene-graph node.
The ParticleSystem node specifies a complete particle system.
Definition: ParticleSystem.h:184
H3DUniquePtr< SFColorNode > colorRamp
The colorRamp field holds a series of colour values to be used at the given colorKey points in time f...
Definition: ParticleSystem.h:328
H3DUniquePtr< MFFloat > texCoordKey
The colorKey field represents the time of the particle in seconds and are the keys to use for the tex...
Definition: ParticleSystem.h:384
static const ParticleSystemList & getAllParticleSystems()
Returns a list of all current ParticleSystem instances.
Definition: ParticleSystem.h:394
H3DUniquePtr< SFBool > isActive
The isActive field indicates whether the particle system is currently running, based on the setup of ...
Definition: ParticleSystem.h:315
H3DUniquePtr< SFString > geometryType
The geometryType field specifies the type of geometry that should be used to represent individual par...
Definition: ParticleSystem.h:359
H3DUniquePtr< SFVec2f > particleSize
The particleSize field describes the dimensions in metres of the width and height of each particle.
Definition: ParticleSystem.h:307
H3DUniquePtr< SFFloat > lifetimeVariation
The lifetimeVariation field controls the variation in a particles lifetime.
Definition: ParticleSystem.h:276
H3DUniquePtr< SFInt32 > maxParticles
The maximum number of particles to be generated.
Definition: ParticleSystem.h:284
H3DUniquePtr< MFPhysicsModelNode > physics
The physics field contains the physics models that should affect the particles after they have been c...
Definition: ParticleSystem.h:368
H3DUniquePtr< SFTextureCoordinate > texCoordRamp
The texCoordRamp fields control the texture coordinates of the provided texture(s) in the Appearance ...
Definition: ParticleSystem.h:376
H3DUniquePtr< SFFloat > particleLifetime
The particleLifetime field controls the lifetime of a particle i.e.
Definition: ParticleSystem.h:294
H3DUniquePtr< SFBool > createParticles
The createParticles field is used to control whether any further new particles should be created.
Definition: ParticleSystem.h:248
H3DUniquePtr< MFFloat > colorKey
The colorKey field represents the time of the particle in seconds and are the keys to use for the col...
Definition: ParticleSystem.h:336
H3DUniquePtr< SFBool > enabled
The enabled field controls whether this ParticleSystem is currently active and rendering particles th...
Definition: ParticleSystem.h:264
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: ParticleSystem.h:387
H3DUniquePtr< SFEmitterNode > emitter
The emitter field specifies the type of emitter geometry and properties that the particles are given ...
Definition: ParticleSystem.h:346
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
Template to make sure that the Nodes that are added to a MFNode are of a specified Node type.
Definition: MFNode.h:221
Template to make sure that the Node that is set in a SFNode is of a specified Node type.
Definition: SFNode.h:97
This is the base node type for all Shape nodes.
Definition: X3DShapeNode.h:50
float H3DFloat
double H3DTime
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194