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-2012 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
    00314         void setParticleQuota(size_t quota);
    00315
    00320         size_t getEmittedEmitterQuota(void) const;
    00321
    00327         void setEmittedEmitterQuota(size_t quota);
    00328
    00334         ParticleSystem& operator=(const ParticleSystem& rhs);
    00335
    00342         void _update(Real timeElapsed);
    00343
    00350         ParticleIterator _getIterator(void);
    00351
    00356         virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
    00357
    00361         virtual const String& getMaterialName(void) const;
    00362
    00367         virtual void _notifyCurrentCamera(Camera* cam);
    00368
    00373         void _notifyAttached(Node* parent, bool isTagPoint = false);
    00374
    00379         virtual const AxisAlignedBox& getBoundingBox(void) const { return mAABB; }
    00380
    00385         virtual Real getBoundingRadius(void) const { return mBoundingRadius; }
    00386
    00391         virtual void _updateRenderQueue(RenderQueue* queue);
    00392
    00394         void visitRenderables(Renderable::Visitor* visitor,
    00395             bool debugRenderables = false);
    00396
    00409         void fastForward(Real time, Real interval = 0.1);
    00410
    00419         void setSpeedFactor(Real speedFactor) { mSpeedFactor = speedFactor; }
    00420
    00423         Real getSpeedFactor(void) const { return mSpeedFactor; }
    00424
    00440         void setIterationInterval(Real iterationInterval);
    00441
    00444         Real getIterationInterval(void) const { return mIterationInterval; }
    00445
    00448         static void setDefaultIterationInterval(Real iterationInterval) { msDefaultIterationInterval = iterationInterval; }
    00449
    00452         static Real getDefaultIterationInterval(void) { return msDefaultIterationInterval; }
    00453
    00468         void setNonVisibleUpdateTimeout(Real timeout);
    00472         Real getNonVisibleUpdateTimeout(void) const { return mNonvisibleTimeout; }
    00473
    00476         static void setDefaultNonVisibleUpdateTimeout(Real timeout)
    00477         { msDefaultNonvisibleTimeout = timeout; }
    00478
    00481         static Real getDefaultNonVisibleUpdateTimeout(void) { return msDefaultNonvisibleTimeout; }
    00482
    00484         const String& getMovableType(void) const;
    00485
    00488         virtual void _notifyParticleResized(void);
    00489
    00492         virtual void _notifyParticleRotated(void);
    00493
    00504         virtual void setDefaultDimensions(Real width, Real height);
    00505
    00507         virtual void setDefaultWidth(Real width);
    00509         virtual Real getDefaultWidth(void) const;
    00511         virtual void setDefaultHeight(Real height);
    00513         virtual Real getDefaultHeight(void) const;
    00515         virtual bool getCullIndividually(void) const;
    00536         virtual void setCullIndividually(bool cullIndividual);
    00538         virtual const String& getResourceGroupName(void) const { return mResourceGroupName; }
    00545         const String& getOrigin(void) const { return mOrigin; }
    00547         void _notifyOrigin(const String& origin) { mOrigin = origin; }
    00548
    00550         void setRenderQueueGroup(uint8 queueID);
    00552         void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority);
    00553
    00560         void setSortingEnabled(bool enabled) { mSorted = enabled; }
    00562         bool getSortingEnabled(void) const { return mSorted; }
    00563
    00573         void setBounds(const AxisAlignedBox& aabb);
    00574
    00591         void setBoundsAutoUpdated(bool autoUpdate, Real stopIn = 0.0f);
    00592
    00602         void setKeepParticlesInLocalSpace(bool keepLocal);
    00603
    00607         bool getKeepParticlesInLocalSpace(void) const { return mLocalSpace; }
    00608
    00622         void _updateBounds(void);
    00623
    00633         void setEmitting(bool v);
    00634
    00640         bool getEmitting() const;
    00641
    00643         uint32 getTypeFlags(void) const;
    00644     protected:
    00645
    00647         static CmdCull msCullCmd;
    00648         static CmdHeight msHeightCmd;
    00649         static CmdMaterial msMaterialCmd;
    00650         static CmdQuota msQuotaCmd;
    00651         static CmdEmittedEmitterQuota msEmittedEmitterQuotaCmd;
    00652         static CmdWidth msWidthCmd;
    00653         static CmdRenderer msRendererCmd;
    00654         static CmdSorted msSortedCmd;
    00655         static CmdLocalSpace msLocalSpaceCmd;
    00656         static CmdIterationInterval msIterationIntervalCmd;
    00657         static CmdNonvisibleTimeout msNonvisibleTimeoutCmd;
    00658
    00659
    00660         AxisAlignedBox mAABB;
    00661         Real mBoundingRadius;
    00662         bool mBoundsAutoUpdate;
    00663         Real mBoundsUpdateTime;
    00664         Real mUpdateRemainTime;
    00665
    00667         AxisAlignedBox mWorldAABB;
    00668
    00670         String mResourceGroupName;
    00672         String mMaterialName;
    00674         bool mIsRendererConfigured;
    00676         MaterialPtr mMaterial;
    00678         Real mDefaultWidth;
    00680         Real mDefaultHeight;
    00682         Real mSpeedFactor;
    00684         Real mIterationInterval;
    00686         bool mIterationIntervalSet;
    00688         bool mSorted;
    00690         bool mLocalSpace;
    00692         Real mNonvisibleTimeout;
    00694         bool mNonvisibleTimeoutSet;
    00696         Real mTimeSinceLastVisible;
    00698         unsigned long mLastVisibleFrame;
    00700         Controller<Real>* mTimeController;
    00702         bool mEmittedEmitterPoolInitialised;
    00704         bool mIsEmitting;
    00705
    00706         typedef list<Particle*>::type ActiveParticleList;
    00707         typedef list<Particle*>::type FreeParticleList;
    00708         typedef vector<Particle*>::type ParticlePool;
    00709
    00711         struct SortByDirectionFunctor
    00712         {
    00714             Vector3 sortDir;
    00715
    00716             SortByDirectionFunctor(const Vector3& dir);
    00717             float operator()(Particle* p) const;
    00718         };
    00719
    00721         struct SortByDistanceFunctor
    00722         {
    00724             Vector3 sortPos;
    00725
    00726             SortByDistanceFunctor(const Vector3& pos);
    00727             float operator()(Particle* p) const;
    00728         };
    00729
    00730         static RadixSort<ActiveParticleList, Particle*, float> mRadixSorter;
    00731
    00741         ActiveParticleList mActiveParticles;
    00742
    00752         FreeParticleList mFreeParticles;
    00753
    00758         ParticlePool mParticlePool;
    00759
    00760         typedef list<ParticleEmitter*>::type FreeEmittedEmitterList;
    00761         typedef list<ParticleEmitter*>::type ActiveEmittedEmitterList;
    00762         typedef vector<ParticleEmitter*>::type EmittedEmitterList;
    00763         typedef map<String, FreeEmittedEmitterList>::type FreeEmittedEmitterMap;
    00764         typedef map<String, EmittedEmitterList>::type EmittedEmitterPool;
    00765
    00774         EmittedEmitterPool mEmittedEmitterPool;
    00775
    00780         FreeEmittedEmitterMap mFreeEmittedEmitters;
    00781
    00787         ActiveEmittedEmitterList mActiveEmittedEmitters;
    00788
    00789         typedef vector<ParticleEmitter*>::type ParticleEmitterList;
    00790         typedef vector<ParticleAffector*>::type ParticleAffectorList;
    00791
    00793         ParticleEmitterList mEmitters;
    00795         ParticleAffectorList mAffectors;
    00796
    00798         ParticleSystemRenderer* mRenderer;
    00799
    00801         bool mCullIndividual;
    00802
    00804         String mRendererType;
    00805
    00807         size_t mPoolSize;
    00808
    00810         size_t mEmittedEmitterPoolSize;
    00811
    00813         String mOrigin;
    00814
    00816         static Real msDefaultIterationInterval;
    00818         static Real msDefaultNonvisibleTimeout;
    00819
    00821         void _expire(Real timeElapsed);
    00822
    00824         void _triggerEmitters(Real timeElapsed);
    00825
    00828         void _executeTriggerEmitters(ParticleEmitter* emitter, unsigned requested, Real timeElapsed);
    00829
    00831         void _applyMotion(Real timeElapsed);
    00832
    00834         void _triggerAffectors(Real timeElapsed);
    00835
    00837         void _sortParticles(Camera* cam);
    00838
    00840         void increasePool(size_t size);
    00841
    00849         void increaseEmittedEmitterPool(size_t size);
    00850
    00852         void initParameters(void);
    00853
    00855         void configureRenderer(void);
    00856
    00858         void createVisualParticles(size_t poolstart, size_t poolend);
    00860         void destroyVisualParticles(size_t poolstart, size_t poolend);
    00861
    00867         void initialiseEmittedEmitters(void);
    00868
    00872         void initialiseEmittedEmitterPool(void);
    00873
    00875         void addFreeEmittedEmitters(void);
    00876
    00878         void removeAllEmittedEmitters(void);
    00879
    00883         FreeEmittedEmitterList* findFreeEmittedEmitter (const String& name);
    00884
    00890         void removeFromActiveEmittedEmitters (ParticleEmitter* emitter);
    00891
    00896         void addActiveEmittedEmittersToFreeList (void);
    00897
    00906         void _notifyReorganiseEmittedEmitterData (void);
    00907     };
    00911 }
    00912
    00913 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:22