OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2014 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 "OgreParticleIterator.h"
35 #include "OgreStringInterface.h"
36 #include "OgreMovableObject.h"
37 #include "OgreRadixSort.h"
39 #include "OgreHeaderPrefix.h"
40 
41 
42 namespace Ogre {
43 
66  {
67  public:
68 
71  {
72  public:
73  String doGet(const void* target) const;
74  void doSet(void* target, const String& val);
75  };
78  {
79  public:
80  String doGet(const void* target) const;
81  void doSet(void* target, const String& val);
82  };
85  {
86  public:
87  String doGet(const void* target) const;
88  void doSet(void* target, const String& val);
89  };
92  {
93  public:
94  String doGet(const void* target) const;
95  void doSet(void* target, const String& val);
96  };
99  {
100  public:
101  String doGet(const void* target) const;
102  void doSet(void* target, const String& val);
103  };
106  {
107  public:
108  String doGet(const void* target) const;
109  void doSet(void* target, const String& val);
110  };
113  {
114  public:
115  String doGet(const void* target) const;
116  void doSet(void* target, const String& val);
117  };
119  class CmdSorted : public ParamCommand
120  {
121  public:
122  String doGet(const void* target) const;
123  void doSet(void* target, const String& val);
124  };
127  {
128  public:
129  String doGet(const void* target) const;
130  void doSet(void* target, const String& val);
131  };
134  {
135  public:
136  String doGet(const void* target) const;
137  void doSet(void* target, const String& val);
138  };
141  {
142  public:
143  String doGet(const void* target) const;
144  void doSet(void* target, const String& val);
145  };
146 
152  ParticleSystem( IdType id, ObjectMemoryManager *objectMemoryManager,
153  const String& resourceGroupName );
154 
155  virtual ~ParticleSystem();
156 
166  void setRenderer(const String& typeName);
167 
169  ParticleSystemRenderer* getRenderer(void) const;
171  const String& getRendererName(void) const;
172 
182  ParticleEmitter* addEmitter(const String& emitterType);
183 
193  ParticleEmitter* getEmitter(unsigned short index) const;
194 
196  unsigned short getNumEmitters(void) const;
197 
206  void removeEmitter(unsigned short index);
207 
209  void removeAllEmitters(void);
210 
211 
221  ParticleAffector* addAffector(const String& affectorType);
222 
232  ParticleAffector* getAffector(unsigned short index) const;
233 
235  unsigned short getNumAffectors(void) const;
236 
245  void removeAffector(unsigned short index);
246 
248  void removeAllAffectors(void);
249 
252  void clear();
253 
261  size_t getNumParticles(void) const;
262 
274  Particle* createParticle(void);
275 
285  Particle* createEmitterParticle(const String& emitterName);
286 
293  Particle* getParticle(size_t index);
294 
299  size_t getParticleQuota(void) const;
300 
312  void setParticleQuota(size_t quota);
313 
318  size_t getEmittedEmitterQuota(void) const;
319 
325  void setEmittedEmitterQuota(size_t quota);
326 
332  ParticleSystem& operator=(const ParticleSystem& rhs);
333 
340  void _update(Real timeElapsed);
341 
348  ParticleIterator _getIterator(void);
349 
354  virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
355 
359  virtual const String& getMaterialName(void) const;
360 
365  void _notifyAttached(Node* parent);
366 
371  virtual void _updateRenderQueue(RenderQueue* queue, Camera *camera, const Camera *lodCamera);
372 
374  void visitRenderables(Renderable::Visitor* visitor,
375  bool debugRenderables = false);
376 
389  void fastForward(Real time, Real interval = 0.1);
390 
399  void setSpeedFactor(Real speedFactor) { mSpeedFactor = speedFactor; }
400 
403  Real getSpeedFactor(void) const { return mSpeedFactor; }
404 
420  void setIterationInterval(Real iterationInterval);
421 
424  Real getIterationInterval(void) const { return mIterationInterval; }
425 
428  static void setDefaultIterationInterval(Real iterationInterval) { msDefaultIterationInterval = iterationInterval; }
429 
432  static Real getDefaultIterationInterval(void) { return msDefaultIterationInterval; }
433 
448  void setNonVisibleUpdateTimeout(Real timeout);
452  Real getNonVisibleUpdateTimeout(void) const { return mNonvisibleTimeout; }
453 
457  { msDefaultNonvisibleTimeout = timeout; }
458 
461  static Real getDefaultNonVisibleUpdateTimeout(void) { return msDefaultNonvisibleTimeout; }
462 
464  const String& getMovableType(void) const;
465 
468  virtual void _notifyParticleResized(void);
469 
472  virtual void _notifyParticleRotated(void);
473 
484  virtual void setDefaultDimensions(Real width, Real height);
485 
487  virtual void setDefaultWidth(Real width);
489  virtual Real getDefaultWidth(void) const;
491  virtual void setDefaultHeight(Real height);
493  virtual Real getDefaultHeight(void) const;
495  virtual bool getCullIndividually(void) const;
516  virtual void setCullIndividually(bool cullIndividual);
518  virtual const String& getResourceGroupName(void) const { return mResourceGroupName; }
525  const String& getOrigin(void) const { return mOrigin; }
527  void _notifyOrigin(const String& origin) { mOrigin = origin; }
528 
530  void setRenderQueueGroup(uint8 queueID);
532  void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority);
533 
540  void setSortingEnabled(bool enabled) { mSorted = enabled; }
542  bool getSortingEnabled(void) const { return mSorted; }
543 
560  void setBoundsAutoUpdated(bool autoUpdate, Real stopIn = 0.0f);
561 
571  void setKeepParticlesInLocalSpace(bool keepLocal);
572 
576  bool getKeepParticlesInLocalSpace(void) const { return mLocalSpace; }
577 
591  void _updateBounds(void);
592 
602  void setEmitting(bool v);
603 
609  bool getEmitting() const;
610  protected:
611 
624 
628 
648  bool mSorted;
658  unsigned long mLastVisibleFrame;
665 
669 
672  {
675 
676  SortByDirectionFunctor(const Vector3& dir);
677  float operator()(Particle* p) const;
678  };
679 
682  {
685 
686  SortByDistanceFunctor(const Vector3& pos);
687  float operator()(Particle* p) const;
688  };
689 
691 
702 
713 
719 
725 
735 
741 
748 
751 
756 
759 
762 
765 
767  size_t mPoolSize;
768 
771 
774 
779 
781  void _expire(Real timeElapsed);
782 
784  void _triggerEmitters(Real timeElapsed);
785 
788  void _executeTriggerEmitters(ParticleEmitter* emitter, unsigned requested, Real timeElapsed);
789 
791  void _applyMotion(Real timeElapsed);
792 
794  void _triggerAffectors(Real timeElapsed);
795 
797  void _sortParticles(Camera* cam);
798 
800  void increasePool(size_t size);
801 
809  void increaseEmittedEmitterPool(size_t size);
810 
812  void initParameters(void);
813 
815  void configureRenderer(void);
816 
818  void createVisualParticles(size_t poolstart, size_t poolend);
820  void destroyVisualParticles(size_t poolstart, size_t poolend);
821 
827  void initialiseEmittedEmitters(void);
828 
832  void initialiseEmittedEmitterPool(void);
833 
835  void addFreeEmittedEmitters(void);
836 
838  void removeAllEmittedEmitters(void);
839 
843  FreeEmittedEmitterList* findFreeEmittedEmitter (const String& name);
844 
850  void removeFromActiveEmittedEmitters (ParticleEmitter* emitter);
851 
856  void addActiveEmittedEmittersToFreeList (void);
857 
866  void _notifyReorganiseEmittedEmitterData (void);
867  };
871 }
872 
873 #include "OgreHeaderSuffix.h"
874 
875 #endif
bool mEmittedEmitterPoolInitialised
Indication whether the emitted emitter pool (= pool with particle emitters that are emitted) is initi...
unsigned char uint8
Definition: OgrePlatform.h:422
size_t mEmittedEmitterPoolSize
The number of emitted emitters in the pool.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
static CmdQuota msQuotaCmd
Real mNonvisibleTimeout
Update timeout when nonvisible (0 for no timeout)
EmittedEmitterPool mEmittedEmitterPool
Pool of emitted emitters for use and reuse in the active emitted emitter list.
Class defining particle system based special effects.
float Real
Software floating point type.
String mMaterialName
Name of the material to use.
Abstract class defining the interface required to be implemented by classes which provide rendering c...
#define _OgreExport
Definition: OgrePlatform.h:255
vector< ParticleAffector * >::type ParticleAffectorList
map< String, EmittedEmitterList >::type EmittedEmitterPool
unsigned long mLastVisibleFrame
Last frame in which known to be visible.
static Real getDefaultNonVisibleUpdateTimeout(void)
Get the default nonvisible timeout for all ParticleSystem instances.
Real getIterationInterval(void) const
Gets a 'iteration interval' on this particle system.
static void setDefaultNonVisibleUpdateTimeout(Real timeout)
Set the default nonvisible timeout for all ParticleSystem instances.
Class for performing a radix sort (fast comparison-less sort based on byte value) on various standard...
Definition: OgreRadixSort.h:88
bool getKeepParticlesInLocalSpace(void) const
Gets whether particles (and any affector effects) remain relative to the node the particle system is ...
virtual const String & getResourceGroupName(void) const
Return the resource group to be used to load dependent resources.
void setSortingEnabled(bool enabled)
Set whether or not particles are sorted according to the camera.
void setSpeedFactor(Real speedFactor)
Sets a 'speed factor' on this particle system, which means it scales the elapsed real time which has ...
Real mDefaultHeight
Default height of each particle.
static String AUTODETECT_RESOURCE_GROUP_NAME
Special resource group name which causes resource group to be automatically determined based on searc...
Command object for cull_each (see ParamCommand).
static CmdEmittedEmitterQuota msEmittedEmitterQuotaCmd
vector< ParticleEmitter * >::type ParticleEmitterList
static void setDefaultIterationInterval(Real iterationInterval)
Set the default iteration interval for all ParticleSystem instances.
ParticleSystemRenderer * mRenderer
The renderer used to render this particle system.
String mOrigin
Optional origin of this particle system (eg script name)
bool mLocalSpace
Particles in local space?
Controller< Real > * mTimeController
Controller for time update.
Command object for particle_width (see ParamCommand).
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
Command object for particle_height (see ParamCommand).
static CmdCull msCullCmd
Command objects.
Abstract class defining a movable object in a scene.
static CmdNonvisibleTimeout msNonvisibleTimeoutCmd
bool mIterationIntervalSet
Iteration interval set? Otherwise track default.
ParticleEmitterList mEmitters
List of particle emitters, ie sources of particles.
Command object for quota (see ParamCommand).
void _notifyOrigin(const String &origin)
Notify this particle system of it's origin.
static CmdIterationInterval msIterationIntervalCmd
Real mSpeedFactor
Speed factor.
map< String, FreeEmittedEmitterList >::type FreeEmittedEmitterMap
Command object for nonvisible timeout (see ParamCommand).
vector< ParticleEmitter * >::type EmittedEmitterList
static CmdLocalSpace msLocalSpaceCmd
Real getNonVisibleUpdateTimeout(void) const
Gets when the particle system should stop updating after it hasn't been visible for a while...
const String & getOrigin(void) const
Get the origin of this particle system, e.g.
Command object for sorting (see ParamCommand).
Class defining the common interface which classes can use to present a reflection-style, self-defining parameter set to callers.
FreeEmittedEmitterMap mFreeEmittedEmitters
Free emitted emitter list.
MaterialPtr mMaterial
Pointer to the material to use.
static CmdRenderer msRendererCmd
static CmdMaterial msMaterialCmd
Class representing a single particle instance.
Definition: OgreParticle.h:60
String mResourceGroupName
Name of the resource group to use to load materials.
Ogre::uint32 IdType
Big projects with lots, lots of units for very long periods of time (MMORPGs?) may want to define thi...
Definition: OgreId.h:36
#define _OgrePrivate
Definition: OgrePlatform.h:256
Real mTimeSinceLastVisible
Amount of time non-visible so far.
bool mCullIndividual
Do we cull each particle individually?
size_t mPoolSize
The number of particles in the pool.
list< Particle * >::type ActiveParticleList
String mRendererType
The name of the type of renderer used to render this system.
static RadixSort< ActiveParticleList, Particle *, float > mRadixSorter
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
bool mIsEmitting
Used to control if the particle system should emit particles or not.
Command object for material (see ParamCommand).
ActiveEmittedEmitterList mActiveEmittedEmitters
Active emitted emitter list.
Convenience class to make it easy to step through all particles in a ParticleSystem.
Abstract class defining the interface to be implemented by particle emitters.
ParticleAffectorList mAffectors
List of particle affectors, ie modifiers of particles.
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
list< ParticleEmitter * >::type FreeEmittedEmitterList
unsigned short ushort
Real mIterationInterval
Iteration interval.
Abstract class defining the interface to be implemented by particle affectors.
Command object for local space (see ParamCommand).
static CmdHeight msHeightCmd
list< Particle * >::type FreeParticleList
Class to manage the scene object rendering queue.
Command object for iteration interval(see ParamCommand).
static CmdSorted msSortedCmd
bool mIsRendererConfigured
Have we set the material etc on the renderer?
ParticlePool mParticlePool
Pool of particle instances for use and reuse in the active particle list.
Real getSpeedFactor(void) const
Gets the 'speed factor' on this particle system.
_StringBase String
Definition: OgreCommon.h:53
ActiveParticleList mActiveParticles
Active particle list.
static Real msDefaultIterationInterval
Default iteration interval.
bool mNonvisibleTimeoutSet
Update timeout when nonvisible set? Otherwise track default.
bool getSortingEnabled(void) const
Gets whether particles are sorted relative to the camera.
bool mSorted
Particles sorted according to camera?
Command object for emittedEmitterQuota (see ParamCommand).
static Real msDefaultNonvisibleTimeout
Default nonvisible update timeout.
list< ParticleEmitter * >::type ActiveEmittedEmitterList
Command object for renderer (see ParamCommand).
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:58
FreeParticleList mFreeParticles
Free particle queue.
static CmdWidth msWidthCmd
static Real getDefaultIterationInterval(void)
Get the default iteration interval for all ParticleSystem instances.
Abstract class which is command object which gets/sets parameters.
vector< Particle * >::type ParticlePool
Real mDefaultWidth
Default width of each particle.