OGRE  1.9
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 "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 
150  ParticleSystem();
156  ParticleSystem(const String& name, const String& resourceGroupName);
157 
158  virtual ~ParticleSystem();
159 
169  void setRenderer(const String& typeName);
170 
172  ParticleSystemRenderer* getRenderer(void) const;
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 
277  Particle* createParticle(void);
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 
335  ParticleSystem& operator=(const ParticleSystem& rhs);
336 
343  void _update(Real timeElapsed);
344 
351  ParticleIterator _getIterator(void);
352 
357  virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
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 
395  void visitRenderables(Renderable::Visitor* visitor,
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 
469  void setNonVisibleUpdateTimeout(Real timeout);
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 
717  SortByDirectionFunctor(const Vector3& dir);
718  float operator()(Particle* p) const;
719  };
720 
723  {
726 
727  SortByDistanceFunctor(const Vector3& pos);
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 
868  void initialiseEmittedEmitters(void);
869 
873  void initialiseEmittedEmitterPool(void);
874 
876  void addFreeEmittedEmitters(void);
877 
879  void removeAllEmittedEmitters(void);
880 
884  FreeEmittedEmitterList* findFreeEmittedEmitter (const String& name);
885 
891  void removeFromActiveEmittedEmitters (ParticleEmitter* emitter);
892 
897  void addActiveEmittedEmittersToFreeList (void);
898 
907  void _notifyReorganiseEmittedEmitterData (void);
908  };
912 }
913 
914 #include "OgreHeaderSuffix.h"
915 
916 #endif
bool mEmittedEmitterPoolInitialised
Indication whether the emitted emitter pool (= pool with particle emitters that are emitted) is initi...
unsigned char uint8
Definition: OgrePlatform.h:346
size_t mEmittedEmitterPoolSize
The number of emitted emitters in the pool.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
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...
unsigned int uint32
Definition: OgrePlatform.h:344
#define _OgreExport
Definition: OgrePlatform.h:260
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
A 3D box aligned with the x/y/z axes.
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).
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.
virtual const AxisAlignedBox & getBoundingBox(void) const
Overridden from MovableObject.
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:61
String mResourceGroupName
Name of the resource group to use to load materials.
#define _OgrePrivate
Definition: OgrePlatform.h:261
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:51
list< ParticleEmitter * >::type FreeEmittedEmitterList
unsigned short ushort
Real mIterationInterval
Iteration interval.
virtual Real getBoundingRadius(void) const
Overridden from MovableObject.
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.
AxisAlignedBox mWorldAABB
World AABB, only used to compare world-space positions to calc bounds.
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
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:64
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.