ParticleEngine.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. #ifndef __Particle_ENGINE__
  5. #define __Particle_ENGINE__
  6. class PongApp;
  7. class ParticleEngine;
  8. class Particle;
  9. class ParticleType {
  10. public:
  11. ParticleType( unsigned int textureID );
  12. virtual ~ParticleType();
  13. // Angle and anglevariance
  14. int m_angle;
  15. int m_angleRandom;
  16. // Angle increment/time and radiance for it.
  17. int m_angleInc;
  18. int m_angleIncRandom;
  19. // Size and sizevariance
  20. int m_size;
  21. int m_sizeRandom;
  22. // Size increment/time and vadiance for it
  23. int m_sizeInc;
  24. int m_sizeIncRandom;
  25. // Lifetime in fixed seconds and variance for it.
  26. int m_lifeTime;
  27. int m_lifeTimeRandom;
  28. // Fraction for this type
  29. int m_fraction;
  30. // Gravity for this type
  31. int m_gravity;
  32. // Angle increments increment/time
  33. int m_angleIncInc;
  34. // Size increments increment/time
  35. int m_sizeIncInc;
  36. // GLTexture used for rendering this type
  37. unsigned int textureID;
  38. // Attributes for this function as real seconds
  39. void setVisibility( float fadeInTime,
  40. float fadeOutTime,
  41. float generalVisibility );
  42. float m_fadeOutTimeSecs;
  43. float m_fadeInTimeSecs;
  44. float m_generalVisibility;
  45. bool m_additiveParticle;
  46. void setColors( float r, float g, float b,
  47. float rr, float gr, float br );
  48. float col[3];
  49. float col_random[3];
  50. };
  51. class Particle {
  52. public:
  53. Particle();
  54. ~Particle();
  55. void run( ParticleEngine *engine, int *fixedGravity, int fixedFrameTime );
  56. int m_pos[3];
  57. int m_dir[3];
  58. int m_lifeTime;
  59. int m_aliveCounter;
  60. int m_angle;
  61. int m_angleInc;
  62. int m_size;
  63. int m_sizeInc;
  64. unsigned int color;
  65. ParticleType *m_type;
  66. };
  67. class ParticleEngine {
  68. public:
  69. ParticleEngine(int maxParticles );
  70. virtual ~ParticleEngine();
  71. void run( float frameTime );
  72. void setGravity( float *gravityVector ) {
  73. m_gravity[0] = (int)( gravityVector[0] * 65536.0f );
  74. m_gravity[1] = (int)( gravityVector[1] * 65536.0f );
  75. m_gravity[2] = (int)( gravityVector[2] * 65536.0f );
  76. };
  77. void render( SpriteBatch *batch, ParticleType *renderType );
  78. /*
  79. * count: how many particles to emit
  80. * type: pointer to particletype defining the type of particles to emit
  81. * pos: position of the emit
  82. * posrandom: variance for position of emit
  83. * dir: direction of emit
  84. * dirrandom: variance for direction of emit
  85. */
  86. void emitParticles( int count,
  87. ParticleType *type,
  88. float *pos, float posRandom,
  89. float *dir, float dirRandom );
  90. protected:
  91. int m_gravity[3];
  92. Particle *m_particles;
  93. int m_maxParticles;
  94. int m_currentParticle;
  95. };
  96. #endif