OGRE: OgreParticleSystem.h Source File - OGRE Documentation

# OgreParticleSystem.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __ParticleSystem_H__
    00029 #define __ParticleSystem_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032
    00033 #include "OgreVector3.h"
    00034 #include "OgreString.h"
    00035 #include "OgreParticleIterator.h"
    00036 #include "OgreStringInterface.h"
    00037 #include "OgreMovableObject.h"
    00038 #include "OgreRadixSort.h"
    00039 #include "OgreController.h"
    00040 #include "OgreResourceGroupManager.h"
    00041
    00042
    00043 namespace Ogre {
    00044
    00066     class _OgreExport ParticleSystem : public StringInterface, public MovableObject
    00067     {
    00068     public:
    00069
    00071         class _OgrePrivate CmdQuota : public ParamCommand
    00072         {
    00073         public:
    00074             String doGet(const void* target) const;
    00075             void doSet(void* target, const String& val);
    00076         };
    00078         class _OgrePrivate CmdEmittedEmitterQuota : public ParamCommand
    00079         {
    00080         public:
    00081             String doGet(const void* target) const;
    00082             void doSet(void* target, const String& val);
    00083         };
    00085         class _OgrePrivate CmdMaterial : public ParamCommand
    00086         {
    00087         public:
    00088             String doGet(const void* target) const;
    00089             void doSet(void* target, const String& val);
    00090         };
    00092         class _OgrePrivate CmdCull : public ParamCommand
    00093         {
    00094         public:
    00095             String doGet(const void* target) const;
    00096             void doSet(void* target, const String& val);
    00097         };
    00099         class _OgrePrivate CmdWidth : public ParamCommand
    00100         {
    00101         public:
    00102             String doGet(const void* target) const;
    00103             void doSet(void* target, const String& val);
    00104         };
    00106         class _OgrePrivate CmdHeight : public ParamCommand
    00107         {
    00108         public:
    00109             String doGet(const void* target) const;
    00110             void doSet(void* target, const String& val);
    00111         };
    00113         class _OgrePrivate CmdRenderer : public ParamCommand
    00114         {
    00115         public:
    00116             String doGet(const void* target) const;
    00117             void doSet(void* target, const String& val);
    00118         };
    00120         class CmdSorted : public ParamCommand
    00121         {
    00122         public:
    00123             String doGet(const void* target) const;
    00124             void doSet(void* target, const String& val);
    00125         };
    00127         class CmdLocalSpace : public ParamCommand
    00128         {
    00129         public:
    00130             String doGet(const void* target) const;
    00131             void doSet(void* target, const String& val);
    00132         };
    00134         class CmdIterationInterval : public ParamCommand
    00135         {
    00136         public:
    00137             String doGet(const void* target) const;
    00138             void doSet(void* target, const String& val);
    00139         };
    00141         class CmdNonvisibleTimeout : public ParamCommand
    00142         {
    00143         public:
    00144             String doGet(const void* target) const;
    00145             void doSet(void* target, const String& val);
    00146         };
    00147
    00149         ParticleSystem();
    00155         ParticleSystem(const String& name, const String& resourceGroupName);
    00156
    00157         virtual ~ParticleSystem();
    00158
    00168         void setRenderer(const String& typeName);
    00169
    00171         ParticleSystemRenderer* getRenderer(void) const;
    00173         const String& getRendererName(void) const;
    00174
    00184         ParticleEmitter* addEmitter(const String& emitterType);
    00185
    00195         ParticleEmitter* getEmitter(unsigned short index) const;
    00196
    00198         unsigned short getNumEmitters(void) const;
    00199
    00208         void removeEmitter(unsigned short index);
    00209
    00211         void removeAllEmitters(void);
    00212
    00213
    00223         ParticleAffector* addAffector(const String& affectorType);
    00224
    00234         ParticleAffector* getAffector(unsigned short index) const;
    00235
    00237         unsigned short getNumAffectors(void) const;
    00238
    00247         void removeAffector(unsigned short index);
    00248
    00250         void removeAllAffectors(void);
    00251
    00254         void clear();
    00255
    00263         size_t getNumParticles(void) const;
    00264
    00276         Particle* createParticle(void);
    00277
    00287         Particle* createEmitterParticle(const String& emitterName);
    00288
    00295         Particle* getParticle(size_t index);
    00296
    00301         size_t getParticleQuota(void) const;
    00302
    00313         void setParticleQuota(size_t quota);
    00314
    00319         size_t getEmittedEmitterQuota(void) const;
    00320
    00326         void setEmittedEmitterQuota(size_t quota);
    00327
    00333         ParticleSystem& operator=(const ParticleSystem& rhs);
    00334
    00341         void _update(Real timeElapsed);
    00342
    00349         ParticleIterator _getIterator(void);
    00350
    00355         virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
    00356
    00360         virtual const String& getMaterialName(void) const;
    00361
    00366         virtual void _notifyCurrentCamera(Camera* cam);
    00367
    00372         void _notifyAttached(Node* parent, bool isTagPoint = false);
    00373
    00378         virtual const AxisAlignedBox& getBoundingBox(void) const { return mAABB; }
    00379
    00384         virtual Real getBoundingRadius(void) const { return mBoundingRadius; }
    00385
    00390         virtual void _updateRenderQueue(RenderQueue* queue);
    00391
    00393         void visitRenderables(Renderable::Visitor* visitor,
    00394             bool debugRenderables = false);
    00395
    00408         void fastForward(Real time, Real interval = 0.1);
    00409
    00418         void setSpeedFactor(Real speedFactor) { mSpeedFactor = speedFactor; }
    00419
    00422         Real getSpeedFactor(void) const { return mSpeedFactor; }
    00423
    00439         void setIterationInterval(Real iterationInterval);
    00440
    00443         Real getIterationInterval(void) const { return mIterationInterval; }
    00444
    00447         static void setDefaultIterationInterval(Real iterationInterval) { msDefaultIterationInterval = iterationInterval; }
    00448
    00451         static Real getDefaultIterationInterval(void) { return msDefaultIterationInterval; }
    00452
    00467         void setNonVisibleUpdateTimeout(Real timeout);
    00471         Real getNonVisibleUpdateTimeout(void) const { return mNonvisibleTimeout; }
    00472
    00475         static void setDefaultNonVisibleUpdateTimeout(Real timeout)
    00476         { msDefaultNonvisibleTimeout = timeout; }
    00477
    00480         static Real getDefaultNonVisibleUpdateTimeout(void) { return msDefaultNonvisibleTimeout; }
    00481
    00483         const String& getMovableType(void) const;
    00484
    00487         virtual void _notifyParticleResized(void);
    00488
    00491         virtual void _notifyParticleRotated(void);
    00492
    00503         virtual void setDefaultDimensions(Real width, Real height);
    00504
    00506         virtual void setDefaultWidth(Real width);
    00508         virtual Real getDefaultWidth(void) const;
    00510         virtual void setDefaultHeight(Real height);
    00512         virtual Real getDefaultHeight(void) const;
    00514         virtual bool getCullIndividually(void) const;
    00535         virtual void setCullIndividually(bool cullIndividual);
    00537         virtual const String& getResourceGroupName(void) const { return mResourceGroupName; }
    00544         const String& getOrigin(void) const { return mOrigin; }
    00546         void _notifyOrigin(const String& origin) { mOrigin = origin; }
    00547
    00549         void setRenderQueueGroup(uint8 queueID);
    00550
    00557         void setSortingEnabled(bool enabled) { mSorted = enabled; }
    00559         bool getSortingEnabled(void) const { return mSorted; }
    00560
    00570         void setBounds(const AxisAlignedBox& aabb);
    00571
    00588         void setBoundsAutoUpdated(bool autoUpdate, Real stopIn = 0.0f);
    00589
    00599         void setKeepParticlesInLocalSpace(bool keepLocal);
    00600
    00604         bool getKeepParticlesInLocalSpace(void) const { return mLocalSpace; }
    00605
    00619         void _updateBounds(void);
    00620
    00630         void setEmitting(bool v);
    00631
    00637         bool getEmitting() const;
    00638
    00640         uint32 getTypeFlags(void) const;
    00641     protected:
    00642
    00644         static CmdCull msCullCmd;
    00645         static CmdHeight msHeightCmd;
    00646         static CmdMaterial msMaterialCmd;
    00647         static CmdQuota msQuotaCmd;
    00648         static CmdEmittedEmitterQuota msEmittedEmitterQuotaCmd;
    00649         static CmdWidth msWidthCmd;
    00650         static CmdRenderer msRendererCmd;
    00651         static CmdSorted msSortedCmd;
    00652         static CmdLocalSpace msLocalSpaceCmd;
    00653         static CmdIterationInterval msIterationIntervalCmd;
    00654         static CmdNonvisibleTimeout msNonvisibleTimeoutCmd;
    00655
    00656
    00657         AxisAlignedBox mAABB;
    00658         Real mBoundingRadius;
    00659         bool mBoundsAutoUpdate;
    00660         Real mBoundsUpdateTime;
    00661         Real mUpdateRemainTime;
    00662
    00664         AxisAlignedBox mWorldAABB;
    00665
    00667         String mResourceGroupName;
    00669         String mMaterialName;
    00671         bool mIsRendererConfigured;
    00673         MaterialPtr mpMaterial;
    00675         Real mDefaultWidth;
    00677         Real mDefaultHeight;
    00679         Real mSpeedFactor;
    00681         Real mIterationInterval;
    00683         bool mIterationIntervalSet;
    00685         bool mSorted;
    00687         bool mLocalSpace;
    00689         Real mNonvisibleTimeout;
    00691         bool mNonvisibleTimeoutSet;
    00693         Real mTimeSinceLastVisible;
    00695         unsigned long mLastVisibleFrame;
    00697         Controller<Real>* mTimeController;
    00699         bool mEmittedEmitterPoolInitialised;
    00701         bool mIsEmitting;
    00702
    00703         typedef list<Particle*>::type ActiveParticleList;
    00704         typedef list<Particle*>::type FreeParticleList;
    00705         typedef vector<Particle*>::type ParticlePool;
    00706
    00708         struct SortByDirectionFunctor
    00709         {
    00711             Vector3 sortDir;
    00712
    00713             SortByDirectionFunctor(const Vector3& dir);
    00714             float operator()(Particle* p) const;
    00715         };
    00716
    00718         struct SortByDistanceFunctor
    00719         {
    00721             Vector3 sortPos;
    00722
    00723             SortByDistanceFunctor(const Vector3& pos);
    00724             float operator()(Particle* p) const;
    00725         };
    00726
    00727         static RadixSort<ActiveParticleList, Particle*, float> mRadixSorter;
    00728
    00738         ActiveParticleList mActiveParticles;
    00739
    00749         FreeParticleList mFreeParticles;
    00750
    00755         ParticlePool mParticlePool;
    00756
    00757         typedef list<ParticleEmitter*>::type FreeEmittedEmitterList;
    00758         typedef list<ParticleEmitter*>::type ActiveEmittedEmitterList;
    00759         typedef vector<ParticleEmitter*>::type EmittedEmitterList;
    00760         typedef map<String, FreeEmittedEmitterList>::type FreeEmittedEmitterMap;
    00761         typedef map<String, EmittedEmitterList>::type EmittedEmitterPool;
    00762
    00771         EmittedEmitterPool mEmittedEmitterPool;
    00772
    00777         FreeEmittedEmitterMap mFreeEmittedEmitters;
    00778
    00784         ActiveEmittedEmitterList mActiveEmittedEmitters;
    00785
    00786         typedef vector<ParticleEmitter*>::type ParticleEmitterList;
    00787         typedef vector<ParticleAffector*>::type ParticleAffectorList;
    00788
    00790         ParticleEmitterList mEmitters;
    00792         ParticleAffectorList mAffectors;
    00793
    00795         ParticleSystemRenderer* mRenderer;
    00796
    00798         bool mCullIndividual;
    00799
    00801         String mRendererType;
    00802
    00804         size_t mPoolSize;
    00805
    00807         size_t mEmittedEmitterPoolSize;
    00808
    00810         String mOrigin;
    00811
    00813         static Real msDefaultIterationInterval;
    00815         static Real msDefaultNonvisibleTimeout;
    00816
    00818         void _expire(Real timeElapsed);
    00819
    00821         void _triggerEmitters(Real timeElapsed);
    00822
    00825         void _executeTriggerEmitters(ParticleEmitter* emitter, unsigned requested, Real timeElapsed);
    00826
    00828         void _applyMotion(Real timeElapsed);
    00829
    00831         void _triggerAffectors(Real timeElapsed);
    00832
    00834         void _sortParticles(Camera* cam);
    00835
    00837         void increasePool(size_t size);
    00838
    00846         void increaseEmittedEmitterPool(size_t size);
    00847
    00849         void initParameters(void);
    00850
    00852         void configureRenderer(void);
    00853
    00855         void createVisualParticles(size_t poolstart, size_t poolend);
    00857         void destroyVisualParticles(size_t poolstart, size_t poolend);
    00858
    00864         void initialiseEmittedEmitters(void);
    00865
    00869         void initialiseEmittedEmitterPool(void);
    00870
    00872         void addFreeEmittedEmitters(void);
    00873
    00875         void removeAllEmittedEmitters(void);
    00876
    00880         FreeEmittedEmitterList* findFreeEmittedEmitter (const String& name);
    00881
    00887         void removeFromActiveEmittedEmitters (ParticleEmitter* emitter);
    00888
    00893         void addActiveEmittedEmittersToFreeList (void);
    00894
    00903         void _notifyReorganiseEmittedEmitterData (void);
    00904     };
    00908 }
    00909
    00910 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52