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-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
    00387         void visitRenderables(Renderable::Visitor* visitor,
    00388             bool debugRenderables = false);
    00389
    00402         void fastForward(Real time, Real interval = 0.1);
    00403
    00412         void setSpeedFactor(Real speedFactor) { mSpeedFactor = speedFactor; }
    00413
    00416         Real getSpeedFactor(void) const { return mSpeedFactor; }
    00417
    00433         void setIterationInterval(Real iterationInterval);
    00434
    00437         Real getIterationInterval(void) const { return mIterationInterval; }
    00438
    00441         static void setDefaultIterationInterval(Real iterationInterval) { msDefaultIterationInterval = iterationInterval; }
    00442
    00445         static Real getDefaultIterationInterval(void) { return msDefaultIterationInterval; }
    00446
    00461         void setNonVisibleUpdateTimeout(Real timeout);
    00465         Real getNonVisibleUpdateTimeout(void) const { return mNonvisibleTimeout; }
    00466
    00469         static void setDefaultNonVisibleUpdateTimeout(Real timeout)
    00470         { msDefaultNonvisibleTimeout = timeout; }
    00471
    00474         static Real getDefaultNonVisibleUpdateTimeout(void) { return msDefaultNonvisibleTimeout; }
    00475
    00477         const String& getMovableType(void) const;
    00478
    00481         virtual void _notifyParticleResized(void);
    00482
    00485         virtual void _notifyParticleRotated(void);
    00486
    00497         virtual void setDefaultDimensions(Real width, Real height);
    00498
    00500         virtual void setDefaultWidth(Real width);
    00502         virtual Real getDefaultWidth(void) const;
    00504         virtual void setDefaultHeight(Real height);
    00506         virtual Real getDefaultHeight(void) const;
    00508         virtual bool getCullIndividually(void) const;
    00529         virtual void setCullIndividually(bool cullIndividual);
    00531         virtual const String& getResourceGroupName(void) const { return mResourceGroupName; }
    00538         const String& getOrigin(void) const { return mOrigin; }
    00540         void _notifyOrigin(const String& origin) { mOrigin = origin; }
    00541
    00543         void setRenderQueueGroup(uint8 queueID);
    00544
    00551         void setSortingEnabled(bool enabled) { mSorted = enabled; }
    00553         bool getSortingEnabled(void) const { return mSorted; }
    00554
    00564         void setBounds(const AxisAlignedBox& aabb);
    00565
    00582         void setBoundsAutoUpdated(bool autoUpdate, Real stopIn = 0.0f);
    00583
    00593         void setKeepParticlesInLocalSpace(bool keepLocal);
    00594
    00598         bool getKeepParticlesInLocalSpace(void) const { return mLocalSpace; }
    00599
    00613         void _updateBounds(void);
    00614
    00616         uint32 getTypeFlags(void) const;
    00617     protected:
    00618
    00620         static CmdCull msCullCmd;
    00621         static CmdHeight msHeightCmd;
    00622         static CmdMaterial msMaterialCmd;
    00623         static CmdQuota msQuotaCmd;
    00624         static CmdEmittedEmitterQuota msEmittedEmitterQuotaCmd;
    00625         static CmdWidth msWidthCmd;
    00626         static CmdRenderer msRendererCmd;
    00627         static CmdSorted msSortedCmd;
    00628         static CmdLocalSpace msLocalSpaceCmd;
    00629         static CmdIterationInterval msIterationIntervalCmd;
    00630         static CmdNonvisibleTimeout msNonvisibleTimeoutCmd;
    00631
    00632
    00633         AxisAlignedBox mAABB;
    00634         Real mBoundingRadius;
    00635         bool mBoundsAutoUpdate;
    00636         Real mBoundsUpdateTime;
    00637         Real mUpdateRemainTime;
    00638
    00640         AxisAlignedBox mWorldAABB;
    00641
    00643         String mResourceGroupName;
    00645         String mMaterialName;
    00647         bool mIsRendererConfigured;
    00649         MaterialPtr mpMaterial;
    00651         Real mDefaultWidth;
    00653         Real mDefaultHeight;
    00655         Real mSpeedFactor;
    00657         Real mIterationInterval;
    00659         bool mIterationIntervalSet;
    00661         bool mSorted;
    00663         bool mLocalSpace;
    00665         Real mNonvisibleTimeout;
    00667         bool mNonvisibleTimeoutSet;
    00669         Real mTimeSinceLastVisible;
    00671         unsigned long mLastVisibleFrame;
    00673         Controller<Real>* mTimeController;
    00675         bool mEmittedEmitterPoolInitialised;
    00676
    00677         typedef std::list<Particle*> ActiveParticleList;
    00678         typedef std::list<Particle*> FreeParticleList;
    00679         typedef std::vector<Particle*> ParticlePool;
    00680
    00682         struct SortByDirectionFunctor
    00683         {
    00685             Vector3 sortDir;
    00686
    00687             SortByDirectionFunctor(const Vector3& dir);
    00688             float operator()(Particle* p) const;
    00689         };
    00690
    00692         struct SortByDistanceFunctor
    00693         {
    00695             Vector3 sortPos;
    00696
    00697             SortByDistanceFunctor(const Vector3& pos);
    00698             float operator()(Particle* p) const;
    00699         };
    00700
    00701         static RadixSort<ActiveParticleList, Particle*, float> mRadixSorter;
    00702
    00712         ActiveParticleList mActiveParticles;
    00713
    00723         FreeParticleList mFreeParticles;
    00724
    00729         ParticlePool mParticlePool;
    00730
    00731         typedef std::list<ParticleEmitter*> FreeEmittedEmitterList;
    00732         typedef std::list<ParticleEmitter*> ActiveEmittedEmitterList;
    00733         typedef std::vector<ParticleEmitter*> EmittedEmitterList;
    00734         typedef std::map<String, FreeEmittedEmitterList> FreeEmittedEmitterMap;
    00735         typedef std::map<String, EmittedEmitterList> EmittedEmitterPool;
    00736
    00745         EmittedEmitterPool mEmittedEmitterPool;
    00746
    00751         FreeEmittedEmitterMap mFreeEmittedEmitters;
    00752
    00758         ActiveEmittedEmitterList mActiveEmittedEmitters;
    00759
    00760         typedef std::vector<ParticleEmitter*> ParticleEmitterList;
    00761         typedef std::vector<ParticleAffector*> ParticleAffectorList;
    00762
    00764         ParticleEmitterList mEmitters;
    00766         ParticleAffectorList mAffectors;
    00767
    00769         ParticleSystemRenderer* mRenderer;
    00770
    00772         bool mCullIndividual;
    00773
    00775         String mRendererType;
    00776
    00778         size_t mPoolSize;
    00779
    00781         size_t mEmittedEmitterPoolSize;
    00782
    00784         String mOrigin;
    00785
    00787         static Real msDefaultIterationInterval;
    00789         static Real msDefaultNonvisibleTimeout;
    00790
    00792         void _expire(Real timeElapsed);
    00793
    00795         void _triggerEmitters(Real timeElapsed);
    00796
    00799         void _executeTriggerEmitters(ParticleEmitter* emitter, unsigned requested, Real timeElapsed);
    00800
    00802         void _applyMotion(Real timeElapsed);
    00803
    00805         void _triggerAffectors(Real timeElapsed);
    00806
    00808         void _sortParticles(Camera* cam);
    00809
    00811         void increasePool(size_t size);
    00812
    00820         void increaseEmittedEmitterPool(size_t size);
    00821
    00823         void initParameters(void);
    00824
    00826         void configureRenderer(void);
    00827
    00829         void createVisualParticles(size_t poolstart, size_t poolend);
    00831         void destroyVisualParticles(size_t poolstart, size_t poolend);
    00832
    00838         void initialiseEmittedEmitters(void);
    00839
    00843         void initialiseEmittedEmitterPool(void);
    00844
    00846         void addFreeEmittedEmitters(void);
    00847
    00849         void removeAllEmittedEmitters(void);
    00850
    00854         FreeEmittedEmitterList* findFreeEmittedEmitter (const String& name);
    00855
    00861         void removeFromActiveEmittedEmitters (ParticleEmitter* emitter);
    00862
    00867         void addActiveEmittedEmittersToFreeList (void);
    00868
    00877         void _notifyReorganiseEmittedEmitterData (void);
    00878     };
    00879
    00880 }
    00881
    00882 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:19 2009