OgreParticleSystem.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __ParticleSystem_H__
29 #define __ParticleSystem_H__
30 
31 #include "OgrePrerequisites.h"
32 
33 #include "OgreVector3.h"
34 #include "OgreString.h"
35 #include "OgreParticleIterator.h"
36 #include "OgreStringInterface.h"
37 #include "OgreMovableObject.h"
38 #include "OgreRadixSort.h"
39 #include "OgreController.h"
41 #include "OgreHeaderPrefix.h"
42 
43 
44 namespace Ogre {
45 
68  {
69  public:
70 
73  {
74  public:
75  String doGet(const void* target) const;
76  void doSet(void* target, const String& val);
77  };
80  {
81  public:
82  String doGet(const void* target) const;
83  void doSet(void* target, const String& val);
84  };
87  {
88  public:
89  String doGet(const void* target) const;
90  void doSet(void* target, const String& val);
91  };
94  {
95  public:
96  String doGet(const void* target) const;
97  void doSet(void* target, const String& val);
98  };
101  {
102  public:
103  String doGet(const void* target) const;
104  void doSet(void* target, const String& val);
105  };
108  {
109  public:
110  String doGet(const void* target) const;
111  void doSet(void* target, const String& val);
112  };
115  {
116  public:
117  String doGet(const void* target) const;
118  void doSet(void* target, const String& val);
119  };
121  class CmdSorted : public ParamCommand
122  {
123  public:
124  String doGet(const void* target) const;
125  void doSet(void* target, const String& val);
126  };
129  {
130  public:
131  String doGet(const void* target) const;
132  void doSet(void* target, const String& val);
133  };
136  {
137  public:
138  String doGet(const void* target) const;
139  void doSet(void* target, const String& val);
140  };
143  {
144  public:
145  String doGet(const void* target) const;
146  void doSet(void* target, const String& val);
147  };
148 
156  ParticleSystem(const String& name, const String& resourceGroupName);
157 
158  virtual ~ParticleSystem();
159 
169  void setRenderer(const String& typeName);
170 
174  const String& getRendererName(void) const;
175 
185  ParticleEmitter* addEmitter(const String& emitterType);
186 
196  ParticleEmitter* getEmitter(unsigned short index) const;
197 
199  unsigned short getNumEmitters(void) const;
200 
209  void removeEmitter(unsigned short index);
210 
212  void removeAllEmitters(void);
213 
214 
224  ParticleAffector* addAffector(const String& affectorType);
225 
235  ParticleAffector* getAffector(unsigned short index) const;
236 
238  unsigned short getNumAffectors(void) const;
239 
248  void removeAffector(unsigned short index);
249 
251  void removeAllAffectors(void);
252 
255  void clear();
256 
264  size_t getNumParticles(void) const;
265 
278 
288  Particle* createEmitterParticle(const String& emitterName);
289 
296  Particle* getParticle(size_t index);
297 
302  size_t getParticleQuota(void) const;
303 
315  void setParticleQuota(size_t quota);
316 
321  size_t getEmittedEmitterQuota(void) const;
322 
328  void setEmittedEmitterQuota(size_t quota);
329 
336 
343  void _update(Real timeElapsed);
344 
352 
358 
362  virtual const String& getMaterialName(void) const;
363 
368  virtual void _notifyCurrentCamera(Camera* cam);
369 
374  void _notifyAttached(Node* parent, bool isTagPoint = false);
375 
380  virtual const AxisAlignedBox& getBoundingBox(void) const { return mAABB; }
381 
386  virtual Real getBoundingRadius(void) const { return mBoundingRadius; }
387 
392  virtual void _updateRenderQueue(RenderQueue* queue);
393 
396  bool debugRenderables = false);
397 
410  void fastForward(Real time, Real interval = 0.1);
411 
420  void setSpeedFactor(Real speedFactor) { mSpeedFactor = speedFactor; }
421 
424  Real getSpeedFactor(void) const { return mSpeedFactor; }
425 
441  void setIterationInterval(Real iterationInterval);
442 
445  Real getIterationInterval(void) const { return mIterationInterval; }
446 
449  static void setDefaultIterationInterval(Real iterationInterval) { msDefaultIterationInterval = iterationInterval; }
450 
453  static Real getDefaultIterationInterval(void) { return msDefaultIterationInterval; }
454 
473  Real getNonVisibleUpdateTimeout(void) const { return mNonvisibleTimeout; }
474 
478  { msDefaultNonvisibleTimeout = timeout; }
479 
482  static Real getDefaultNonVisibleUpdateTimeout(void) { return msDefaultNonvisibleTimeout; }
483 
485  const String& getMovableType(void) const;
486 
489  virtual void _notifyParticleResized(void);
490 
493  virtual void _notifyParticleRotated(void);
494 
505  virtual void setDefaultDimensions(Real width, Real height);
506 
508  virtual void setDefaultWidth(Real width);
510  virtual Real getDefaultWidth(void) const;
512  virtual void setDefaultHeight(Real height);
514  virtual Real getDefaultHeight(void) const;
516  virtual bool getCullIndividually(void) const;
537  virtual void setCullIndividually(bool cullIndividual);
539  virtual const String& getResourceGroupName(void) const { return mResourceGroupName; }
546  const String& getOrigin(void) const { return mOrigin; }
548  void _notifyOrigin(const String& origin) { mOrigin = origin; }
549 
551  void setRenderQueueGroup(uint8 queueID);
553  void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority);
554 
561  void setSortingEnabled(bool enabled) { mSorted = enabled; }
563  bool getSortingEnabled(void) const { return mSorted; }
564 
574  void setBounds(const AxisAlignedBox& aabb);
575 
592  void setBoundsAutoUpdated(bool autoUpdate, Real stopIn = 0.0f);
593 
603  void setKeepParticlesInLocalSpace(bool keepLocal);
604 
608  bool getKeepParticlesInLocalSpace(void) const { return mLocalSpace; }
609 
623  void _updateBounds(void);
624 
634  void setEmitting(bool v);
635 
641  bool getEmitting() const;
642 
644  uint32 getTypeFlags(void) const;
645  protected:
646 
659 
660 
666 
669 
689  bool mSorted;
699  unsigned long mLastVisibleFrame;
706 
710 
713  {
716 
718  float operator()(Particle* p) const;
719  };
720 
723  {
726 
728  float operator()(Particle* p) const;
729  };
730 
732 
743 
754 
760 
766 
776 
782 
789 
792 
797 
800 
803 
806 
808  size_t mPoolSize;
809 
812 
815 
820 
822  void _expire(Real timeElapsed);
823 
825  void _triggerEmitters(Real timeElapsed);
826 
829  void _executeTriggerEmitters(ParticleEmitter* emitter, unsigned requested, Real timeElapsed);
830 
832  void _applyMotion(Real timeElapsed);
833 
835  void _triggerAffectors(Real timeElapsed);
836 
838  void _sortParticles(Camera* cam);
839 
841  void increasePool(size_t size);
842 
850  void increaseEmittedEmitterPool(size_t size);
851 
853  void initParameters(void);
854 
856  void configureRenderer(void);
857 
859  void createVisualParticles(size_t poolstart, size_t poolend);
861  void destroyVisualParticles(size_t poolstart, size_t poolend);
862 
869 
874 
877 
880 
885 
892 
898 
908  };
912 }
913 
914 #include "OgreHeaderSuffix.h"
915 
916 #endif
#define _OgreExport
Definition: OgrePlatform.h:257
#define _OgrePrivate
Definition: OgrePlatform.h:258
A 3D box aligned with the x/y/z axes.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:87
Abstract class defining a movable object in a scene.
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:65
Abstract class which is command object which gets/sets parameters.
Abstract class defining the interface to be implemented by particle affectors.
Abstract class defining the interface to be implemented by particle emitters.
Convenience class to make it easy to step through all particles in a ParticleSystem.
Abstract class defining the interface required to be implemented by classes which provide rendering c...
Command object for cull_each (see ParamCommand).
void doSet(void *target, const String &val)
String doGet(const void *target) const
Command object for emittedEmitterQuota (see ParamCommand).
void doSet(void *target, const String &val)
String doGet(const void *target) const
Command object for particle_height (see ParamCommand).
void doSet(void *target, const String &val)
String doGet(const void *target) const
Command object for iteration interval(see ParamCommand).
String doGet(const void *target) const
void doSet(void *target, const String &val)
Command object for local space (see ParamCommand).
String doGet(const void *target) const
void doSet(void *target, const String &val)
Command object for material (see ParamCommand).
String doGet(const void *target) const
void doSet(void *target, const String &val)
Command object for nonvisible timeout (see ParamCommand).
void doSet(void *target, const String &val)
String doGet(const void *target) const
Command object for quota (see ParamCommand).
void doSet(void *target, const String &val)
String doGet(const void *target) const
Command object for renderer (see ParamCommand).
String doGet(const void *target) const
void doSet(void *target, const String &val)
Command object for sorting (see ParamCommand).
void doSet(void *target, const String &val)
String doGet(const void *target) const
Command object for particle_width (see ParamCommand).
String doGet(const void *target) const
void doSet(void *target, const String &val)
Class defining particle system based special effects.
virtual bool getCullIndividually(void) const
Returns whether or not particles in this are tested individually for culling.
void initialiseEmittedEmitters(void)
Create a pool of emitted emitters and assign them to the free emitter list.
String mRendererType
The name of the type of renderer used to render this system.
size_t mEmittedEmitterPoolSize
The number of emitted emitters in the pool.
virtual Real getBoundingRadius(void) const
Overridden from MovableObject.
void increaseEmittedEmitterPool(size_t size)
Resize the internal pool of emitted emitters.
Real mDefaultWidth
Default width of each particle.
void increasePool(size_t size)
Resize the internal pool of particles.
void addFreeEmittedEmitters(void)
Add emitters from the pool to the free emitted emitter queue.
void setKeepParticlesInLocalSpace(bool keepLocal)
Sets whether particles (and any affector effects) remain relative to the node the particle system is ...
virtual ~ParticleSystem()
Real getIterationInterval(void) const
Gets a 'iteration interval' on this particle system.
ActiveEmittedEmitterList mActiveEmittedEmitters
Active emitted emitter list.
void _triggerAffectors(Real timeElapsed)
Applies the effects of affectors.
FreeParticleList mFreeParticles
Free particle queue.
ParticleSystemRenderer * getRenderer(void) const
Gets the ParticleRenderer to be used to render this particle system.
Particle * getParticle(size_t index)
Retrieve a particle from the system for manual tweaking.
unsigned short getNumEmitters(void) const
Returns the number of emitters for this particle system.
AxisAlignedBox mWorldAABB
World AABB, only used to compare world-space positions to calc bounds.
size_t getParticleQuota(void) const
Returns the maximum number of particles this system is allowed to have active at once.
String mOrigin
Optional origin of this particle system (eg script name)
void removeAllAffectors(void)
Removes all the affectors from this system.
void _sortParticles(Camera *cam)
Sort the particles in the system.
void removeAllEmittedEmitters(void)
Removes all emitted emitters from this system.
static CmdQuota msQuotaCmd
void removeFromActiveEmittedEmitters(ParticleEmitter *emitter)
Removes an emitter from the active emitted emitter list.
void destroyVisualParticles(size_t poolstart, size_t poolend)
Internal method for destroying ParticleVisualData instances for the pool.
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
void _notifyAttached(Node *parent, bool isTagPoint=false)
Overridden from MovableObject.
virtual void _notifyCurrentCamera(Camera *cam)
Overridden from MovableObject.
vector< Particle * >::type ParticlePool
ParticleEmitterList mEmitters
List of particle emitters, ie sources of particles.
void _update(Real timeElapsed)
Updates the particles in the system based on time elapsed.
Real getSpeedFactor(void) const
Gets the 'speed factor' on this particle system.
ParticlePool mParticlePool
Pool of particle instances for use and reuse in the active particle list.
Real getNonVisibleUpdateTimeout(void) const
Gets when the particle system should stop updating after it hasn't been visible for a while.
void removeAllEmitters(void)
Removes all the emitters from this system.
virtual Real getDefaultHeight(void) const
See setDefaultDimensions - this gets 1 component individually.
virtual void setCullIndividually(bool cullIndividual)
Sets whether culling tests particles in this individually as well as in a group.
ParticleSystemRenderer * mRenderer
The renderer used to render this particle system.
void setRenderer(const String &typeName)
Sets the ParticleRenderer to be used to render this particle system.
static Real msDefaultIterationInterval
Default iteration interval.
virtual const String & getResourceGroupName(void) const
Return the resource group to be used to load dependent resources.
static CmdNonvisibleTimeout msNonvisibleTimeoutCmd
list< Particle * >::type FreeParticleList
void _applyMotion(Real timeElapsed)
Updates existing particle based on their momentum.
virtual void setMaterialName(const String &name, const String &groupName=ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME)
Sets the name of the material to be used for this billboard set.
void setBoundsAutoUpdated(bool autoUpdate, Real stopIn=0.0f)
Sets whether the bounds will be automatically updated for the life of the particle system.
void fastForward(Real time, Real interval=0.1)
Fast-forwards this system by the required number of seconds.
Real mSpeedFactor
Speed factor.
EmittedEmitterPool mEmittedEmitterPool
Pool of emitted emitters for use and reuse in the active emitted emitter list.
ParticleAffectorList mAffectors
List of particle affectors, ie modifiers of particles.
const String & getMovableType(void) const
Overridden from MovableObject.
static CmdIterationInterval msIterationIntervalCmd
ParticleEmitter * addEmitter(const String &emitterType)
Adds an emitter to this particle system.
ParticleSystem & operator=(const ParticleSystem &rhs)
Assignment operator for copying.
ParticleAffector * getAffector(unsigned short index) const
Retrieves an affector by it's index (zero-based).
virtual void _notifyParticleResized(void)
Internal callback used by Particles to notify their parent that they have been resized.
void removeEmitter(unsigned short index)
Removes an emitter from the system.
unsigned long mLastVisibleFrame
Last frame in which known to be visible.
bool mIsRendererConfigured
Have we set the material etc on the renderer?
void clear()
Empties this set of all particles.
String mMaterialName
Name of the material to use.
Real mDefaultHeight
Default height of each particle.
void _executeTriggerEmitters(ParticleEmitter *emitter, unsigned requested, Real timeElapsed)
Helper function that actually performs the emission of particles.
bool mLocalSpace
Particles in local space?
ParticleIterator _getIterator(void)
Returns an iterator for stepping through all particles in this system.
bool mCullIndividual
Do we cull each particle individually?
bool getEmitting() const
Returns true if the particle system emitting flag is turned on.
void setRenderQueueGroup(uint8 queueID)
Sets the render queue group this entity will be rendered through.
ParticleAffector * addAffector(const String &affectorType)
Adds an affector to this particle system.
void addActiveEmittedEmittersToFreeList(void)
Moves all emitted emitters from the active list to the free list.
void setEmittedEmitterQuota(size_t quota)
Sets the maximum number of emitted emitters this system is allowed to have active at once.
void setBounds(const AxisAlignedBox &aabb)
Set the (initial) bounds of the particle system manually.
void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority)
Sets the render queue group and group priority this entity will be rendered through.
void removeAffector(unsigned short index)
Removes an affector from the system.
static CmdHeight msHeightCmd
static CmdWidth msWidthCmd
static Real msDefaultNonvisibleTimeout
Default nonvisible update timeout.
bool mEmittedEmitterPoolInitialised
Indication whether the emitted emitter pool (= pool with particle emitters that are emitted) is initi...
size_t getNumParticles(void) const
Gets the number of individual particles in the system right now.
virtual void setDefaultDimensions(Real width, Real height)
Sets the default dimensions of the particles in this set.
map< String, EmittedEmitterList >::type EmittedEmitterPool
static CmdMaterial msMaterialCmd
bool mSorted
Particles sorted according to camera?
ParticleSystem(const String &name, const String &resourceGroupName)
Creates a particle system with no emitters or affectors.
ParticleSystem()
Default constructor required for STL creation in manager.
static CmdEmittedEmitterQuota msEmittedEmitterQuotaCmd
bool mNonvisibleTimeoutSet
Update timeout when nonvisible set? Otherwise track default.
Real mIterationInterval
Iteration interval.
virtual const AxisAlignedBox & getBoundingBox(void) const
Overridden from MovableObject.
virtual void setDefaultHeight(Real height)
See setDefaultDimensions - this sets 1 component individually.
static Real getDefaultNonVisibleUpdateTimeout(void)
Get the default nonvisible timeout for all ParticleSystem instances.
virtual void _updateRenderQueue(RenderQueue *queue)
Overridden from MovableObject.
Real mTimeSinceLastVisible
Amount of time non-visible so far.
uint32 getTypeFlags(void) const
Override to return specific type flag.
void createVisualParticles(size_t poolstart, size_t poolend)
Internal method for creating ParticleVisualData instances for the pool.
void setSortingEnabled(bool enabled)
Set whether or not particles are sorted according to the camera.
map< String, FreeEmittedEmitterList >::type FreeEmittedEmitterMap
const String & getOrigin(void) const
Get the origin of this particle system, e.g.
virtual void setDefaultWidth(Real width)
See setDefaultDimensions - this sets 1 component individually.
list< ParticleEmitter * >::type ActiveEmittedEmitterList
void setParticleQuota(size_t quota)
Sets the maximum number of particles this system is allowed to have active at once.
ActiveParticleList mActiveParticles
Active particle list.
ParticleEmitter * getEmitter(unsigned short index) const
Retrieves an emitter by it's index (zero-based).
size_t getEmittedEmitterQuota(void) const
Returns the maximum number of emitted emitters this system is allowed to have active at once.
virtual void _notifyParticleRotated(void)
Internal callback used by Particles to notify their parent that they have been rotated.
Controller< Real > * mTimeController
Controller for time update.
void initialiseEmittedEmitterPool(void)
Determine which emitters in the Particle Systems main emitter become a template for creating an pool ...
void _notifyOrigin(const String &origin)
Notify this particle system of it's origin.
FreeEmittedEmitterMap mFreeEmittedEmitters
Free emitted emitter list.
list< ParticleEmitter * >::type FreeEmittedEmitterList
void configureRenderer(void)
Internal method to configure the renderer.
vector< ParticleEmitter * >::type EmittedEmitterList
const String & getRendererName(void) const
Gets the name of the ParticleRenderer to be used to render this particle system.
Particle * createEmitterParticle(const String &emitterName)
Manually add an emitter particle to the system.
void _updateBounds(void)
Internal method for updating the bounds of the particle system.
virtual const String & getMaterialName(void) const
Sets the name of the material to be used for this billboard set.
static CmdCull msCullCmd
Command objects.
bool getSortingEnabled(void) const
Gets whether particles are sorted relative to the camera.
size_t mPoolSize
The number of particles in the pool.
void _expire(Real timeElapsed)
Internal method used to expire dead particles.
vector< ParticleAffector * >::type ParticleAffectorList
vector< ParticleEmitter * >::type ParticleEmitterList
void setNonVisibleUpdateTimeout(Real timeout)
Sets when the particle system should stop updating after it hasn't been visible for a while.
FreeEmittedEmitterList * findFreeEmittedEmitter(const String &name)
Find the list with free emitted emitters.
void initParameters(void)
Internal method for initialising string interface.
static void setDefaultIterationInterval(Real iterationInterval)
Set the default iteration interval for all ParticleSystem instances.
unsigned short getNumAffectors(void) const
Returns the number of affectors for this particle system.
static RadixSort< ActiveParticleList, Particle *, float > mRadixSorter
list< Particle * >::type ActiveParticleList
void setEmitting(bool v)
This is used to turn on or off particle emission for this system.
static CmdRenderer msRendererCmd
static CmdLocalSpace msLocalSpaceCmd
MaterialPtr mMaterial
Pointer to the material to use.
bool getKeepParticlesInLocalSpace(void) const
Gets whether particles (and any affector effects) remain relative to the node the particle system is ...
static CmdSorted msSortedCmd
static void setDefaultNonVisibleUpdateTimeout(Real timeout)
Set the default nonvisible timeout for all ParticleSystem instances.
String mResourceGroupName
Name of the resource group to use to load materials.
void setIterationInterval(Real iterationInterval)
Sets a 'iteration interval' on this particle system.
Particle * createParticle(void)
Manually add a particle to the system.
Real mNonvisibleTimeout
Update timeout when nonvisible (0 for no timeout)
void _triggerEmitters(Real timeElapsed)
Spawn new particles based on free quota and emitter requirements.
static Real getDefaultIterationInterval(void)
Get the default iteration interval for all ParticleSystem instances.
virtual Real getDefaultWidth(void) const
See setDefaultDimensions - this gets 1 component individually.
bool mIterationIntervalSet
Iteration interval set? Otherwise track default.
bool mIsEmitting
Used to control if the particle system should emit particles or not.
void _notifyReorganiseEmittedEmitterData(void)
This function clears all data structures that are used in combination with emitted emitters and sets ...
void setSpeedFactor(Real speedFactor)
Sets a 'speed factor' on this particle system, which means it scales the elapsed real time which has ...
Class representing a single particle instance.
Definition: OgreParticle.h:62
Class for performing a radix sort (fast comparison-less sort based on byte value) on various standard...
Definition: OgreRadixSort.h:89
Class to manage the scene object rendering queue.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly.
static String AUTODETECT_RESOURCE_GROUP_NAME
Special resource group name which causes resource group to be automatically determined based on searc...
Class defining the common interface which classes can use to present a reflection-style,...
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
unsigned char uint8
Definition: OgrePlatform.h:361
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:359
_StringBase String
unsigned short ushort

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.