Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Emitter.h 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*!
  2. * \file include/Emitter.h
  3. * \brief Particle emitter class.
  4. *
  5. * \author Mongoose
  6. */
  7. #ifndef _EMITTER_H_
  8. #define _EMITTER_H_
  9. #include "Particle.h"
  10. /*!
  11. * \brief Particle emitter class.
  12. */
  13. class Emitter {
  14. public:
  15. /*!
  16. * \brief Flags an Emitter can have
  17. */
  18. typedef enum {
  19. fUseFrustumCulling = (1 << 0), //!< Use frustum culling
  20. fUseDepthSorting = (1 << 1) //!< Use depth sorting
  21. } EmitterFlags;
  22. /*!
  23. * \brief Constructs an object of Emitter
  24. * \param name valid C string
  25. * \param n greater than 0
  26. */
  27. Emitter(const char *name, int n);
  28. /*!
  29. * \brief Deconstructs an object of Emitter
  30. */
  31. ~Emitter();
  32. /*!
  33. * \brief Get the particles
  34. * \returns array of Particles
  35. */
  36. Particle *Particles();
  37. /*!
  38. * \brief Number of particles emitted
  39. * \returns Number of particles emitted
  40. */
  41. int Count();
  42. /*!
  43. * \brief Sets position of emitter in 3D space
  44. * \param x X coordinate
  45. * \param y Y coordinate
  46. * \param z Z coordinate
  47. */
  48. void Pos(float x, float y, float z);
  49. /*!
  50. * \brief Returns position of emitter in 3D space
  51. * \param x Where X coordinate will be stored
  52. * \param y Where Y coordinate will be stored
  53. * \param z Where Z coordinate will be stored
  54. */
  55. void Pos(float *x, float *y, float *z);
  56. /*!
  57. * \brief Sets orientation of emitter in 3D space
  58. * \param x X coordinate
  59. * \param y Y coordinate
  60. * \param z Z coordinate
  61. */
  62. void Orientation(float x, float y, float z);
  63. /*!
  64. * \brief Returns orientation of emitter in 3D space
  65. * \param x Where X coordinate will be stored
  66. * \param y Where Y coordinate will be stored
  67. * \param z Where Z coordinate will be stored
  68. */
  69. void Orientation(float *x, float *y, float *z);
  70. /*!
  71. * \brief Get the flags of this Emitter
  72. * \returns EmitterFlags
  73. */
  74. unsigned int Flags();
  75. /*!
  76. * \brief Set or Unset a flag
  77. * \param flag EmitterFlag to change
  78. * \param op new state (true - set)
  79. */
  80. void Flags(unsigned int flag, bool op);
  81. /*!
  82. * \brief Allocates the particle array and sets the count.
  83. * If the array has been allocated previously it will be
  84. * deallocated and a new one made.
  85. * \param n new size, greater than 0
  86. */
  87. void ParticleArray(int n);
  88. /*!
  89. * \brief Renders the particles
  90. */
  91. void Draw();
  92. /*!
  93. * \brief Sets the emitters name
  94. * \param name is a valid C string
  95. */
  96. void Name(const char *name);
  97. /*!
  98. * \brief Resets all particle texture ids
  99. * \param id new id
  100. * \sa Particle::TextureId()
  101. */
  102. void SetTextureId(int id);
  103. /*!
  104. * \brief Set the texture id for a range of particles in the array
  105. * \param particle_start start of range
  106. * \param particle_end end of range
  107. * \param id new id
  108. * \sa Particle::TextureId()
  109. */
  110. void TextureId(unsigned int particle_start, unsigned int particle_end, int id);
  111. /*!
  112. * \brief Set the color of a range of particles in the array
  113. * \param particle_start start of range
  114. * \param particle_end end of range
  115. * \param r new red part of color (0.0 to 1.0)
  116. * \param g new green part of color (0.0 to 1.0)
  117. * \param b new blue part of color (0.0 to 1.0)
  118. * \sa Particle::Color()
  119. */
  120. void Color(unsigned int particle_start, unsigned int particle_end, float r, float g, float b);
  121. /*!
  122. * \brief Set the speed of a range of particles in the array.
  123. * Take note that the speed starts out at 2000, and lower means faster.
  124. * \param particle_start start of range
  125. * \param particle_end end of range
  126. * \param x X speed
  127. * \param y Y speed
  128. * \param z Z speed
  129. * \sa Particle::Speed
  130. */
  131. void Speed(unsigned int particle_start, unsigned int particle_end, float x, float y, float z);
  132. /*!
  133. * \brief Let a force (eg. Gravity) act on a range of particles in the array
  134. * \param particle_start start of range
  135. * \param particle_end end of range
  136. * \param x X force
  137. * \param y Y force
  138. * \param z Z force
  139. * \sa Particle::Force()
  140. */
  141. void Force(unsigned int particle_start, unsigned int particle_end, float x, float y, float z);
  142. static vec_t mFrustum[6][4]; //!< View Volume copy
  143. private:
  144. static int compareParticleDist(const void *voidA, const void *voidB);
  145. char *_name; //!< Emitter name
  146. unsigned int _flags; //!< Emitter flags
  147. vec3_t _pos; //!< Position in 3D space
  148. vec3_t _mangle; //!< Oreintation in 3D space
  149. Particle *_particle; //!< Array of particles
  150. unsigned int _count; //!< Particle count
  151. };
  152. #endif