Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

particle.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                      particle.h  -  Particle system classes
00003                              -------------------
00004     begin                : Thu May 9 2002
00005     copyright            : (C) 2002 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, particle.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2002
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NEPARTICLE_H
00028 #define __NEPARTICLE_H
00029 
00030 
00037 #define __NEED_VECTOR_FLOAT
00038 
00039 #include "base.h"
00040 #include "scenenode.h"
00041 #include "physicsnode.h"
00042 
00043 #include <vector>
00044 
00045 
00046 namespace NeoEngine
00047 {
00048 
00049 
00050 // External classes
00051 class Room;
00052 
00053 
00054 typedef PhysicsNode Particle;
00055 
00056 
00062 class NEOENGINE_API ParticleAllocatorCallback
00063 {
00064     public:
00065 
00073         virtual void                                  AllocateParticles( unsigned int uiNumParticles, Particle **ppkParticles ) = 0;
00074 };
00075 
00076 
00082 class NEOENGINE_API ParticleGenerator
00083 {
00084     friend class ParticleSystem;
00085 
00086     protected:
00087 
00089         float                                         m_fFraction;
00090 
00092         float                                         m_fVelocity;
00093 
00095         float                                         m_fVelocityAccuracy;
00096 
00098         float                                         m_fDensity;
00099 
00101         ParticleAllocatorCallback                  *m_pkAllocatorCallback;
00102 
00103 
00109         virtual void                                  Allocate( unsigned int uiNumParticles, Particle **ppkParticles );
00110 
00111 
00112     public:
00113 
00120                                                       ParticleGenerator( float fVelocity, float fVelocityAccuracy, float fDensity, ParticleAllocatorCallback *pkAllocatorCallback = 0 ) : m_fFraction(0.0f), m_fVelocity( fVelocity ), m_fVelocityAccuracy( fVelocityAccuracy ), m_fDensity( fDensity ), m_pkAllocatorCallback( pkAllocatorCallback ) {}
00121 
00124         virtual                                      ~ParticleGenerator() {}
00125 
00134         virtual unsigned int                          Generate( float fDeltaTime, unsigned int uiMaxParticles, Particle **ppkParticles, const Vector3d &kPos ) = 0;
00135 };
00136 
00137 
00143 class NEOENGINE_API SphereParticleGenerator : public ParticleGenerator
00144 {
00145     public:
00146 
00156                                                       SphereParticleGenerator( float fVelocity, float fVelocityAccuracy, float fDensity, ParticleAllocatorCallback *pkAllocatorCallback = 0 );
00157 
00160         virtual                                      ~SphereParticleGenerator();
00161 
00170         virtual unsigned int                          Generate( float fDeltaTime, unsigned int uiMaxParticles, Particle **ppkParticles, const Vector3d &kPos );
00171 };
00172 
00173 
00179 class NEOENGINE_API ParticleSystem : public SceneNode
00180 {
00181     public:
00182         DefineVisitable()
00183 
00184     protected:
00185 
00186 
00192         class NEOENGINE_API ParticleSubSystem
00193         {
00194             public:
00195 
00200                 enum PARTICLESUBSYSTEMDEF
00201                 {
00203                   NUMPARTICLES                        = 10
00204                 };
00205 
00206 
00208                 Particle                             *m_apkParticles[ NUMPARTICLES ];
00209 
00211                 float                                 m_afLifetime[ NUMPARTICLES ];
00212 
00214                 float                                 m_afTTL[ NUMPARTICLES ];
00215 
00217                 unsigned int                          m_uiNumUsedSlots;
00218 
00219 
00222                                                       ParticleSubSystem() { memset( m_apkParticles, 0, sizeof( Particle* ) * NUMPARTICLES ); m_uiNumUsedSlots = 0; }
00223 
00227                                                      ~ParticleSubSystem();
00228 
00232                 inline int                            GetFreeSlot() { if( m_uiNumUsedSlots >= NUMPARTICLES ) return -1; return m_uiNumUsedSlots; }
00233 
00238                 inline void                           FreeSlot( unsigned int uiSlot )               
00239                 {
00240                     if( uiSlot >= m_uiNumUsedSlots )
00241                         return;
00242 
00243                     for( unsigned int uiNextSlot = uiSlot + 1; uiNextSlot < m_uiNumUsedSlots; ++uiNextSlot, ++uiSlot )
00244                     {
00245                         m_apkParticles[ uiSlot ] = m_apkParticles[ uiNextSlot ];
00246                         m_afLifetime[ uiSlot ]   = m_afLifetime[ uiNextSlot ];
00247                         m_afTTL[ uiSlot ]        = m_afTTL[ uiNextSlot ];
00248                     }
00249 
00250                     m_apkParticles[ --m_uiNumUsedSlots ] = 0;
00251                 }
00252         };
00253 
00254 
00256         ParticleSubSystem                           **m_ppkSubSystems;
00257 
00259         unsigned int                                  m_uiNumParticles;
00260 
00262         unsigned int                                  m_uiMaxParticles;
00263 
00265         unsigned int                                  m_uiNumSubSystemPointers;
00266 
00268         unsigned int                                  m_uiNumSubSystems;
00269 
00271         float                                         m_fNormalTTL;
00272 
00274         float                                         m_fTTLAccuracy;
00275 
00277         ParticleGenerator                            *m_pkGenerator;
00278 
00280         Particle                                    **m_ppkGeneratePool;
00281 
00283         unsigned int                                  m_uiGeneratePoolSize;
00284 
00286         unsigned int                                  m_uiNumFreeParticles;
00287 
00289         Room                                         *m_pkRoom;
00290 
00292         bool                                          m_bGenerate;
00293 
00294 
00295     public:
00296 
00303                                                       ParticleSystem( ParticleGenerator *pkGenerator, unsigned int uiMaxParticles, float fTTL = 0.0f, float fTTLAccuracy = 0.0f );
00304 
00308         virtual                                      ~ParticleSystem();
00309 
00314         virtual void                                  Update( float fDeltaTime = 0.0f );
00315 
00320         virtual SceneNode                            *Duplicate();
00321 
00325         unsigned int                                  GetNumParticles() { return m_uiNumParticles; }
00326 
00331         void                                          SetRoom( Room *pkRoom );
00332 
00337         inline void                                   SetGenerate( bool bGenerate ) { m_bGenerate = bGenerate; }
00338 
00342         inline void                                   ToggleGenerate() { m_bGenerate = !m_bGenerate; }
00343 };
00344 
00345 
00346 };
00347 
00348 
00349 #endif

Generated on Wed Jan 21 14:21:07 2004 for NeoEngine by doxygen 1.3.5