- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

# 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-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __ParticleSystem_H__
    00030 #define __ParticleSystem_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033
    00034 #include "OgreVector3.h"
    00035 #include "OgreString.h"
    00036 #include "OgreParticleIterator.h"
    00037 #include "OgreStringInterface.h"
    00038 #include "OgreMovableObject.h"
    00039 #include "OgreRadixSort.h"
    00040 #include "OgreController.h"
    00041
    00042
    00043 namespace Ogre {
    00044
    00060     class _OgreExport ParticleSystem : public StringInterface, public MovableObject
    00061     {
    00062     public:
    00063
    00065         class _OgrePrivate CmdQuota : public ParamCommand
    00066         {
    00067         public:
    00068             String doGet(const void* target) const;
    00069             void doSet(void* target, const String& val);
    00070         };
    00072         class _OgrePrivate CmdEmittedEmitterQuota : public ParamCommand
    00073         {
    00074         public:
    00075             String doGet(const void* target) const;
    00076             void doSet(void* target, const String& val);
    00077         };
    00079         class _OgrePrivate CmdMaterial : public ParamCommand
    00080         {
    00081         public:
    00082             String doGet(const void* target) const;
    00083             void doSet(void* target, const String& val);
    00084         };
    00086         class _OgrePrivate CmdCull : public ParamCommand
    00087         {
    00088         public:
    00089             String doGet(const void* target) const;
    00090             void doSet(void* target, const String& val);
    00091         };
    00093         class _OgrePrivate CmdWidth : public ParamCommand
    00094         {
    00095         public:
    00096             String doGet(const void* target) const;
    00097             void doSet(void* target, const String& val);
    00098         };
    00100         class _OgrePrivate CmdHeight : public ParamCommand
    00101         {
    00102         public:
    00103             String doGet(const void* target) const;
    00104             void doSet(void* target, const String& val);
    00105         };
    00107         class _OgrePrivate CmdRenderer : public ParamCommand
    00108         {
    00109         public:
    00110             String doGet(const void* target) const;
    00111             void doSet(void* target, const String& val);
    00112         };
    00114         class CmdSorted : public ParamCommand
    00115         {
    00116         public:
    00117             String doGet(const void* target) const;
    00118             void doSet(void* target, const String& val);
    00119         };
    00121         class CmdLocalSpace : public ParamCommand
    00122         {
    00123         public:
    00124             String doGet(const void* target) const;
    00125             void doSet(void* target, const String& val);
    00126         };
    00128         class CmdIterationInterval : public ParamCommand
    00129         {
    00130         public:
    00131             String doGet(const void* target) const;
    00132             void doSet(void* target, const String& val);
    00133         };
    00135         class CmdNonvisibleTimeout : public ParamCommand
    00136         {
    00137         public:
    00138             String doGet(const void* target) const;
    00139             void doSet(void* target, const String& val);
    00140         };
    00141
    00143         ParticleSystem();
    00149         ParticleSystem(const String& name, const String& resourceGroupName);
    00150
    00151         virtual ~ParticleSystem();
    00152
    00162         void setRenderer(const String& typeName);
    00163
    00165         ParticleSystemRenderer* getRenderer(void) const;
    00167         const String& getRendererName(void) const;
    00168
    00178         ParticleEmitter* addEmitter(const String& emitterType);
    00179
    00189         ParticleEmitter* getEmitter(unsigned short index) const;
    00190
    00192         unsigned short getNumEmitters(void) const;
    00193
    00202         void removeEmitter(unsigned short index);
    00203
    00205         void removeAllEmitters(void);
    00206
    00207
    00217         ParticleAffector* addAffector(const String& affectorType);
    00218
    00228         ParticleAffector* getAffector(unsigned short index) const;
    00229
    00231         unsigned short getNumAffectors(void) const;
    00232
    00241         void removeAffector(unsigned short index);
    00242
    00244         void removeAllAffectors(void);
    00245
    00248         void clear();
    00249
    00257         size_t getNumParticles(void) const;
    00258
    00270         Particle* createParticle(void);
    00271
    00281         Particle* createEmitterParticle(const String& emitterName);
    00282
    00289         Particle* getParticle(size_t index);
    00290
    00295         size_t getParticleQuota(void) const;
    00296
    00307         void setParticleQuota(size_t quota);
    00308
    00313         size_t getEmittedEmitterQuota(void) const;
    00314
    00320         void setEmittedEmitterQuota(size_t quota);
    00321
    00327         ParticleSystem& operator=(const ParticleSystem& rhs);
    00328
    00335         void _update(Real timeElapsed);
    00336
    00343         ParticleIterator _getIterator(void);
    00344
    00349         virtual void setMaterialName(const String& name);
    00350
    00354         virtual const String& getMaterialName(void) const;
    00355
    00360         virtual void _notifyCurrentCamera(Camera* cam);
    00361
    00366         void _notifyAttached(Node* parent, bool isTagPoint = false);
    00367
    00372         virtual const AxisAlignedBox& getBoundingBox(void) const { return mAABB; }
    00373
    00378         virtual Real getBoundingRadius(void) const { return mBoundingRadius; }
    00379
    00384         virtual void _updateRenderQueue(RenderQueue* queue);
    00385
    00398         void fastForward(Real time, Real interval = 0.1);
    00399
    00408         void setSpeedFactor(Real speedFactor) { mSpeedFactor = speedFactor; }
    00409
    00412         Real getSpeedFactor(void) const { return mSpeedFactor; }
    00413
    00429         void setIterationInterval(Real iterationInterval);
    00430
    00433         Real getIterationInterval(void) const { return mIterationInterval; }
    00434
    00437         static void setDefaultIterationInterval(Real iterationInterval) { msDefaultIterationInterval = iterationInterval; }
    00438
    00441         static Real getDefaultIterationInterval(void) { return msDefaultIterationInterval; }
    00442
    00457         void setNonVisibleUpdateTimeout(Real timeout);
    00461         Real getNonVisibleUpdateTimeout(void) const { return mNonvisibleTimeout; }
    00462
    00465         static void setDefaultNonVisibleUpdateTimeout(Real timeout)
    00466         { msDefaultNonvisibleTimeout = timeout; }
    00467
    00470         static Real getDefaultNonVisibleUpdateTimeout(void) { return msDefaultNonvisibleTimeout; }
    00471
    00473         const String& getMovableType(void) const;
    00474
    00477         virtual void _notifyParticleResized(void);
    00478
    00481         virtual void _notifyParticleRotated(void);
    00482
    00493         virtual void setDefaultDimensions(Real width, Real height);
    00494
    00496         virtual void setDefaultWidth(Real width);
    00498         virtual Real getDefaultWidth(void) const;
    00500         virtual void setDefaultHeight(Real height);
    00502         virtual Real getDefaultHeight(void) const;
    00504         virtual bool getCullIndividually(void) const;
    00525         virtual void setCullIndividually(bool cullIndividual);
    00527         virtual const String& getResourceGroupName(void) const { return mResourceGroupName; }
    00534         const String& getOrigin(void) const { return mOrigin; }
    00536         void _notifyOrigin(const String& origin) { mOrigin = origin; }
    00537
    00539         void setRenderQueueGroup(uint8 queueID);
    00540
    00547         void setSortingEnabled(bool enabled) { mSorted = enabled; }
    00549         bool getSortingEnabled(void) const { return mSorted; }
    00550
    00560         void setBounds(const AxisAlignedBox& aabb);
    00561
    00578         void setBoundsAutoUpdated(bool autoUpdate, Real stopIn = 0.0f);
    00579
    00589         void setKeepParticlesInLocalSpace(bool keepLocal);
    00590
    00594         bool getKeepParticlesInLocalSpace(void) const { return mLocalSpace; }
    00595
    00609         void _updateBounds(void);
    00610
    00612         uint32 getTypeFlags(void) const;
    00613     protected:
    00614
    00616         static CmdCull msCullCmd;
    00617         static CmdHeight msHeightCmd;
    00618         static CmdMaterial msMaterialCmd;
    00619         static CmdQuota msQuotaCmd;
    00620         static CmdEmittedEmitterQuota msEmittedEmitterQuotaCmd;
    00621         static CmdWidth msWidthCmd;
    00622         static CmdRenderer msRendererCmd;
    00623         static CmdSorted msSortedCmd;
    00624         static CmdLocalSpace msLocalSpaceCmd;
    00625         static CmdIterationInterval msIterationIntervalCmd;
    00626         static CmdNonvisibleTimeout msNonvisibleTimeoutCmd;
    00627
    00628
    00629         AxisAlignedBox mAABB;
    00630         Real mBoundingRadius;
    00631         bool mBoundsAutoUpdate;
    00632         Real mBoundsUpdateTime;
    00633         Real mUpdateRemainTime;
    00634
    00636         AxisAlignedBox mWorldAABB;
    00637
    00639         String mResourceGroupName;
    00641         String mMaterialName;
    00643         bool mIsRendererConfigured;
    00645         MaterialPtr mpMaterial;
    00647         Real mDefaultWidth;
    00649         Real mDefaultHeight;
    00651         Real mSpeedFactor;
    00653         Real mIterationInterval;
    00655         bool mIterationIntervalSet;
    00657         bool mSorted;
    00659         bool mLocalSpace;
    00661         Real mNonvisibleTimeout;
    00663         bool mNonvisibleTimeoutSet;
    00665         Real mTimeSinceLastVisible;
    00667         unsigned long mLastVisibleFrame;
    00669         Controller<Real>* mTimeController;
    00671         bool mEmittedEmitterPoolInitialised;
    00672
    00673         typedef std::list<Particle*> ActiveParticleList;
    00674         typedef std::list<Particle*> FreeParticleList;
    00675         typedef std::vector<Particle*> ParticlePool;
    00676
    00678         struct SortByDirectionFunctor
    00679         {
    00681             Vector3 sortDir;
    00682
    00683             SortByDirectionFunctor(const Vector3& dir);
    00684             float operator()(Particle* p) const;
    00685         };
    00686
    00688         struct SortByDistanceFunctor
    00689         {
    00691             Vector3 sortPos;
    00692
    00693             SortByDistanceFunctor(const Vector3& pos);
    00694             float operator()(Particle* p) const;
    00695         };
    00696
    00697         static RadixSort<ActiveParticleList, Particle*, float> mRadixSorter;
    00698
    00708         ActiveParticleList mActiveParticles;
    00709
    00719         FreeParticleList mFreeParticles;
    00720
    00725         ParticlePool mParticlePool;
    00726
    00727         typedef std::list<ParticleEmitter*> FreeEmittedEmitterList;
    00728         typedef std::list<ParticleEmitter*> ActiveEmittedEmitterList;
    00729         typedef std::vector<ParticleEmitter*> EmittedEmitterList;
    00730         typedef std::map<String, FreeEmittedEmitterList> FreeEmittedEmitterMap;
    00731         typedef std::map<String, EmittedEmitterList> EmittedEmitterPool;
    00732
    00741         EmittedEmitterPool mEmittedEmitterPool;
    00742
    00747         FreeEmittedEmitterMap mFreeEmittedEmitters;
    00748
    00754         ActiveEmittedEmitterList mActiveEmittedEmitters;
    00755
    00756         typedef std::vector<ParticleEmitter*> ParticleEmitterList;
    00757         typedef std::vector<ParticleAffector*> ParticleAffectorList;
    00758
    00760         ParticleEmitterList mEmitters;
    00762         ParticleAffectorList mAffectors;
    00763
    00765         ParticleSystemRenderer* mRenderer;
    00766
    00768         bool mCullIndividual;
    00769
    00771         String mRendererType;
    00772
    00774         size_t mPoolSize;
    00775
    00777         size_t mEmittedEmitterPoolSize;
    00778
    00780         String mOrigin;
    00781
    00783         static Real msDefaultIterationInterval;
    00785         static Real msDefaultNonvisibleTimeout;
    00786
    00788         void _expire(Real timeElapsed);
    00789
    00791         void _triggerEmitters(Real timeElapsed);
    00792
    00795         void _executeTriggerEmitters(ParticleEmitter* emitter, unsigned requested, Real timeElapsed);
    00796
    00798         void _applyMotion(Real timeElapsed);
    00799
    00801         void _triggerAffectors(Real timeElapsed);
    00802
    00804         void _sortParticles(Camera* cam);
    00805
    00807         void increasePool(size_t size);
    00808
    00816         void increaseEmittedEmitterPool(size_t size);
    00817
    00819         void initParameters(void);
    00820
    00822         void configureRenderer(void);
    00823
    00825         void createVisualParticles(size_t poolstart, size_t poolend);
    00827         void destroyVisualParticles(size_t poolstart, size_t poolend);
    00828
    00834         void initialiseEmittedEmitters(void);
    00835
    00839         void initialiseEmittedEmitterPool(void);
    00840
    00842         void addFreeEmittedEmitters(void);
    00843
    00845         void removeAllEmittedEmitters(void);
    00846
    00850         FreeEmittedEmitterList* findFreeEmittedEmitter (const String& name);
    00851
    00857         void removeFromActiveEmittedEmitters (ParticleEmitter* emitter);
    00858
    00863         void addActiveEmittedEmittersToFreeList (void);
    00864
    00873         void _notifyReorganiseEmittedEmitterData (void);
    00874     };
    00875
    00876 }
    00877
    00878 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Mon Jun 16 12:48:53 2008