particle.h

00001 /*--License:
00002         Lilith 3D Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2002-2003
00004         www.grinninglizard.com/lilith
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program is distributed in the hope that it will be useful,
00012         but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License
00017         along with this program; if not, write to the Free Software
00018         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020         The full text of the license can be found in license.txt
00021 */
00022 #ifndef LILITH_PARTICLE_INCLUDED
00023 #define LILITH_PARTICLE_INCLUDED
00024 
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4786 )       // Debugger truncating names.
00027 #endif
00028 #include <list>
00029 #include "mesh.h"
00030 #include "../grinliz/glrandom.h"
00031 #include "../grinliz/glcolor.h"
00032 
00033 namespace lilith3d
00034 {
00035 
00036 class Texture;
00037 
00046 class ParticleSystem : public MeshGroup
00047 {
00048   public:
00049         virtual void DoTick() = 0;
00050         virtual ~ParticleSystem();
00051 
00052         virtual const char* SystemName() = 0;
00053         virtual int PrepareStreamOut() = 0;
00054 
00055         // Used by most systems.
00056         virtual void StreamOut( const Shader* shader, ELightPass light, EPass pass );
00057 
00058   protected:
00059         ParticleSystem();
00060         void Init( int count, const Texture* tex );
00061 
00062         int maxNumVertex;
00063         const Texture*  texture;
00064         grinliz::Vector3F*      quads;
00065         grinliz::Color4F*       color;
00066         grinliz::Vector2F*      texUV;
00067 };
00068 
00069 
00074 class GravParticles : public ParticleSystem
00075 {
00076   public:
00077         GravParticles();
00078         ~GravParticles();
00079 
00080         enum
00081         {
00082                 CIRCULAR_WHITE,         
00083                 FLAME0,                         
00084                 FLAME1,                         
00085 
00086                 FLAME_COUNT = 2,
00087         };
00088 
00089         virtual const char* SystemName()        { return "GravParticles"; }
00090 
00091         void Create( const grinliz::Vector3F& location,
00092                                  const grinliz::Vector3F& velocity,
00093                                  const grinliz::Color3F& color,
00094                                  float gravity,
00095                                  float size,
00096                                  int type = CIRCULAR_WHITE,
00097                                  float decay = DECAY );
00098 
00099         virtual void DoTick();
00100         virtual int PrepareStreamOut();
00101 
00102         virtual void DoCulling()                {}
00103 
00104         static const float FAST_DECAY;
00105         static const float DECAY;
00106 
00107         static const float GRAVITY;
00108 
00109         static const float VERYSMALL;
00110         static const float SMALL;
00111         static const float MEDIUM;
00112         static const float LARGE;
00113 
00114   private:
00115         void SwapParticle( int a, int b );
00116 
00117         enum {
00118                 MAX_PARTICLE = 1024
00119         };
00120 
00121         struct Particle
00122         {
00123                 grinliz::Vector3F loc;
00124                 grinliz::Vector3F velocity;
00125                 float gravity;
00126                 float size;
00127                 float decay;
00128         };
00129         int numParticle;
00130         Particle* particle;
00131 };
00132 
00133 
00137 class RainDropParticles : public ParticleSystem
00138 {
00139   public:
00140         RainDropParticles();
00141         ~RainDropParticles();
00142 
00143         virtual const char* SystemName()        { return "RainDropParticles"; }
00144 
00145         void Rain( float intensity );
00146         virtual void DoTick();
00147 
00148         virtual void DoCulling();
00149 
00150         virtual void StreamOut( const Shader* shader, ELightPass light, EPass pass );
00151         virtual int PrepareStreamOut()                                                          { return 0; }
00152 
00153   private:
00154         static const float DROP_LENGTH;
00155         static const float DROP_VELOCITY;
00156 
00157         struct RainDrop 
00158         {
00159                 grinliz::Vector3F pos;
00160                 bool splash;
00161         };
00162         std::list< RainDrop > rainDropList;
00163 
00164         float intensity;
00165         grinliz::Random rand;
00166         U32 timeOfLastDrop;
00167 };
00168 
00169 
00172 class RainSplashParticles : public ParticleSystem
00173 {
00174   public:
00175         RainSplashParticles();
00176         ~RainSplashParticles();
00177 
00178         virtual const char* SystemName()        { return "RainSplashParticles"; }
00179 
00180         void Create( const grinliz::Vector3F& location );
00181         virtual void DoTick();
00182 
00183         virtual void DoCulling()                {}
00184 
00185         virtual int PrepareStreamOut();
00186 
00187   private:
00188         static const float SPLASH_VELOCITY;
00189         static const float MAX_SIZE;
00190         enum {
00191                 MAX_PARTICLE = 32
00192         };
00193 
00194         struct Splash 
00195         {
00196                 float x, y, z;
00197                 float size;
00198         };
00199         Splash* splash;
00200         int numSplash;
00201 };
00202 };
00203 
00204 #endif

Generated on Fri Mar 23 19:36:22 2007 for Lilith3D by  doxygen 1.5.1-p1