Particles.h
Upload User: xuczgm
Upload Date: 2022-04-25
Package Size: 8601k
Code Size: 2k
Category:

Special Effects

Development Platform:

Visual C++

  1. /****************************************************************************
  2.  Particles.h  Particle and particle system base classes.
  3.  
  4.  Author   :   Dave Astle
  5.  Date     :   2/1/2001
  6.  Written for OpenGL Game Programming
  7. *****************************************************************************/
  8. #ifndef __PARTICLES_H_INCLUDED__
  9. #define __PARTICLES_H_INCLUDED__
  10. /********************************* Includes *********************************/
  11. //using namespace std;
  12. #include "../include/vector.h"
  13. /***************************** Data structures ******************************/
  14. class CParticleSystem;
  15. struct particle_t
  16. {
  17.   CVector  m_pos;           // current position of the particle
  18.   CVector  m_prevPos;       // last position of the particle
  19.   CVector  m_velocity;      // direction and speed
  20.   CVector  m_acceleration;  // acceleration
  21.   float   m_energy;           // determines how long the particle is alive
  22.   float   m_size;             // size of particle
  23.   float   m_sizeDelta;        // amount to change the size over time
  24.   float   m_weight;           // determines how gravity affects the particle
  25.   float   m_weightDelta;      // change over time
  26.   float   m_color[4];         // current color of the particle
  27.   float   m_colorDelta[4];    // how the color changes with time
  28. };
  29. class CParticleSystem
  30. {
  31. public:
  32.      CParticleSystem(int maxParticles, CVector origin);
  33.   // abstract functions
  34.   virtual void  Update(float elapsedTime)     = 0;
  35.   virtual void  Render()                      = 0;
  36.   virtual int   Emit(int numParticles);
  37.   virtual void  InitializeSystem();
  38.   virtual void  KillSystem();
  39. protected:
  40.   virtual void  InitializeParticle(int index) = 0;
  41.   particle_t *m_particleList;    // particles for this emitter
  42.   int         m_maxParticles;     // maximum number of particles in total
  43.   int         m_numParticles;     // indicies of all free particles
  44.   CVector   m_origin;           // center of the particle system
  45.   float       m_accumulatedTime;  // used to track how long since the last particle was emitted
  46.   CVector   m_force;            // force (gravity, wind, etc.) acting on the particle system
  47. };
  48. #endif // __PARTICLES_H_INCLUDED__