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-2005 The OGRE Team 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 */ 00025 #ifndef __ParticleSystem_H__ 00026 #define __ParticleSystem_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 00030 #include "OgreVector3.h" 00031 #include "OgreString.h" 00032 #include "OgreParticleIterator.h" 00033 #include "OgreStringInterface.h" 00034 #include "OgreMovableObject.h" 00035 #include "OgreRadixSort.h" 00036 #include "OgreController.h" 00037 00038 00039 namespace Ogre { 00040 00056 class _OgreExport ParticleSystem : public StringInterface, public MovableObject 00057 { 00058 public: 00059 00061 class _OgrePrivate CmdQuota : public ParamCommand 00062 { 00063 public: 00064 String doGet(const void* target) const; 00065 void doSet(void* target, const String& val); 00066 }; 00068 class _OgrePrivate CmdMaterial : public ParamCommand 00069 { 00070 public: 00071 String doGet(const void* target) const; 00072 void doSet(void* target, const String& val); 00073 }; 00075 class _OgrePrivate CmdCull : public ParamCommand 00076 { 00077 public: 00078 String doGet(const void* target) const; 00079 void doSet(void* target, const String& val); 00080 }; 00082 class _OgrePrivate CmdWidth : public ParamCommand 00083 { 00084 public: 00085 String doGet(const void* target) const; 00086 void doSet(void* target, const String& val); 00087 }; 00089 class _OgrePrivate CmdHeight : public ParamCommand 00090 { 00091 public: 00092 String doGet(const void* target) const; 00093 void doSet(void* target, const String& val); 00094 }; 00096 class _OgrePrivate CmdRenderer : public ParamCommand 00097 { 00098 public: 00099 String doGet(const void* target) const; 00100 void doSet(void* target, const String& val); 00101 }; 00103 class CmdSorted : public ParamCommand 00104 { 00105 public: 00106 String doGet(const void* target) const; 00107 void doSet(void* target, const String& val); 00108 }; 00110 class CmdLocalSpace : public ParamCommand 00111 { 00112 public: 00113 String doGet(const void* target) const; 00114 void doSet(void* target, const String& val); 00115 }; 00117 class CmdIterationInterval : public ParamCommand 00118 { 00119 public: 00120 String doGet(const void* target) const; 00121 void doSet(void* target, const String& val); 00122 }; 00124 class CmdNonvisibleTimeout : public ParamCommand 00125 { 00126 public: 00127 String doGet(const void* target) const; 00128 void doSet(void* target, const String& val); 00129 }; 00130 00132 ParticleSystem(); 00138 ParticleSystem(const String& name, const String& resourceGroupName); 00139 00140 virtual ~ParticleSystem(); 00141 00151 void setRenderer(const String& typeName); 00152 00154 ParticleSystemRenderer* getRenderer(void) const; 00156 const String& getRendererName(void) const; 00157 00167 ParticleEmitter* addEmitter(const String& emitterType); 00168 00178 ParticleEmitter* getEmitter(unsigned short index) const; 00179 00181 unsigned short getNumEmitters(void) const; 00182 00191 void removeEmitter(unsigned short index); 00192 00194 void removeAllEmitters(void); 00195 00196 00206 ParticleAffector* addAffector(const String& affectorType); 00207 00217 ParticleAffector* getAffector(unsigned short index) const; 00218 00220 unsigned short getNumAffectors(void) const; 00221 00230 void removeAffector(unsigned short index); 00231 00233 void removeAllAffectors(void); 00234 00237 void clear(); 00238 00246 size_t getNumParticles(void) const; 00247 00259 Particle* createParticle(void); 00260 00267 Particle* getParticle(size_t index); 00268 00273 size_t getParticleQuota(void) const; 00274 00285 void setParticleQuota(size_t quota); 00286 00287 00293 ParticleSystem& operator=(const ParticleSystem& rhs); 00294 00301 void _update(Real timeElapsed); 00302 00309 ParticleIterator _getIterator(void); 00310 00315 virtual void setMaterialName(const String& name); 00316 00320 virtual const String& getMaterialName(void) const; 00321 00326 virtual void _notifyCurrentCamera(Camera* cam); 00327 00332 void _notifyAttached(Node* parent, bool isTagPoint = false); 00333 00338 virtual const AxisAlignedBox& getBoundingBox(void) const { return mAABB; } 00339 00344 virtual Real getBoundingRadius(void) const { return mBoundingRadius; } 00345 00350 virtual void _updateRenderQueue(RenderQueue* queue); 00351 00364 void fastForward(Real time, Real interval = 0.1); 00365 00374 void setSpeedFactor(Real speedFactor) { mSpeedFactor = speedFactor; } 00375 00378 Real getSpeedFactor(void) const { return mSpeedFactor; } 00379 00395 void setIterationInterval(Real iterationInterval); 00396 00399 Real getIterationInterval(void) const { return mIterationInterval; } 00400 00403 static void setDefaultIterationInterval(Real iterationInterval) { msDefaultIterationInterval = iterationInterval; } 00404 00407 static Real getDefaultIterationInterval(void) { return msDefaultIterationInterval; } 00408 00423 void setNonVisibleUpdateTimeout(Real timeout); 00427 Real getNonVisibleUpdateTimeout(void) const { return mNonvisibleTimeout; } 00428 00431 static void setDefaultNonVisibleUpdateTimeout(Real timeout) 00432 { msDefaultNonvisibleTimeout = timeout; } 00433 00436 static Real getDefaultNonVisibleUpdateTimeout(void) { return msDefaultNonvisibleTimeout; } 00437 00439 const String& getMovableType(void) const; 00440 00443 virtual void _notifyParticleResized(void); 00444 00447 virtual void _notifyParticleRotated(void); 00448 00459 virtual void setDefaultDimensions(Real width, Real height); 00460 00462 virtual void setDefaultWidth(Real width); 00464 virtual Real getDefaultWidth(void) const; 00466 virtual void setDefaultHeight(Real height); 00468 virtual Real getDefaultHeight(void) const; 00470 virtual bool getCullIndividually(void) const; 00491 virtual void setCullIndividually(bool cullIndividual); 00493 virtual const String& getResourceGroupName(void) const { return mResourceGroupName; } 00500 const String& getOrigin(void) const { return mOrigin; } 00502 void _notifyOrigin(const String& origin) { mOrigin = origin; } 00503 00505 void setRenderQueueGroup(uint8 queueID); 00506 00513 void setSortingEnabled(bool enabled) { mSorted = enabled; } 00515 bool getSortingEnabled(void) const { return mSorted; } 00516 00526 void setBounds(const AxisAlignedBox& aabb); 00527 00544 void setBoundsAutoUpdated(bool autoUpdate, Real stopIn = 0.0f); 00545 00555 void setKeepParticlesInLocalSpace(bool keepLocal); 00556 00560 bool getKeepParticlesInLocalSpace(void) const { return mLocalSpace; } 00561 00575 void _updateBounds(void); 00576 00578 uint32 getTypeFlags(void) const; 00579 protected: 00580 00582 static CmdCull msCullCmd; 00583 static CmdHeight msHeightCmd; 00584 static CmdMaterial msMaterialCmd; 00585 static CmdQuota msQuotaCmd; 00586 static CmdWidth msWidthCmd; 00587 static CmdRenderer msRendererCmd; 00588 static CmdSorted msSortedCmd; 00589 static CmdLocalSpace msLocalSpaceCmd; 00590 static CmdIterationInterval msIterationIntervalCmd; 00591 static CmdNonvisibleTimeout msNonvisibleTimeoutCmd; 00592 00593 00594 AxisAlignedBox mAABB; 00595 Real mBoundingRadius; 00596 bool mBoundsAutoUpdate; 00597 Real mBoundsUpdateTime; 00598 Real mUpdateRemainTime; 00599 00601 AxisAlignedBox mWorldAABB; 00602 00604 String mResourceGroupName; 00606 String mMaterialName; 00608 bool mIsRendererConfigured; 00610 MaterialPtr mpMaterial; 00612 Real mDefaultWidth; 00614 Real mDefaultHeight; 00616 Real mSpeedFactor; 00618 Real mIterationInterval; 00620 bool mIterationIntervalSet; 00622 bool mSorted; 00624 bool mLocalSpace; 00626 Real mNonvisibleTimeout; 00628 bool mNonvisibleTimeoutSet; 00630 Real mTimeSinceLastVisible; 00632 unsigned long mLastVisibleFrame; 00634 Controller<Real>* mTimeController; 00635 00636 typedef std::list<Particle*> ActiveParticleList; 00637 typedef std::list<Particle*> FreeParticleList; 00638 typedef std::vector<Particle*> ParticlePool; 00639 00641 struct SortByDirectionFunctor 00642 { 00644 Vector3 sortDir; 00645 00646 SortByDirectionFunctor(const Vector3& dir); 00647 float operator()(Particle* p) const; 00648 }; 00649 00651 struct SortByDistanceFunctor 00652 { 00654 Vector3 sortPos; 00655 00656 SortByDistanceFunctor(const Vector3& pos); 00657 float operator()(Particle* p) const; 00658 }; 00659 00660 static RadixSort<ActiveParticleList, Particle*, float> mRadixSorter; 00661 00671 ActiveParticleList mActiveParticles; 00672 00682 FreeParticleList mFreeParticles; 00683 00688 ParticlePool mParticlePool; 00689 00690 typedef std::vector<ParticleEmitter*> ParticleEmitterList; 00691 typedef std::vector<ParticleAffector*> ParticleAffectorList; 00692 00694 ParticleEmitterList mEmitters; 00696 ParticleAffectorList mAffectors; 00697 00699 ParticleSystemRenderer* mRenderer; 00700 00702 bool mCullIndividual; 00703 00705 String mRendererType; 00706 00708 size_t mPoolSize; 00709 00711 String mOrigin; 00712 00714 static Real msDefaultIterationInterval; 00716 static Real msDefaultNonvisibleTimeout; 00717 00719 void _expire(Real timeElapsed); 00720 00722 void _triggerEmitters(Real timeElapsed); 00723 00725 void _applyMotion(Real timeElapsed); 00726 00728 void _triggerAffectors(Real timeElapsed); 00729 00731 void _sortParticles(Camera* cam); 00732 00734 void increasePool(size_t size); 00735 00737 void initParameters(void); 00738 00740 void configureRenderer(void); 00741 00743 void createVisualParticles(size_t poolstart, size_t poolend); 00745 void destroyVisualParticles(size_t poolstart, size_t poolend); 00746 00747 }; 00748 00749 } 00750 00751 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:46 2006