ParticleEmitter.pkg 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. $#include "ParticleEmitter.h"
  2. /// Particle emitter shapes.
  3. enum EmitterType
  4. {
  5. EMITTER_SPHERE,
  6. EMITTER_BOX
  7. };
  8. /*
  9. /// One particle in the particle system.
  10. struct Particle
  11. {
  12. /// Velocity.
  13. Vector3 velocity_;
  14. /// Original billboard size.
  15. Vector2 size_;
  16. /// Time elapsed from creation.
  17. float timer_;
  18. /// Lifetime.
  19. float timeToLive_;
  20. /// Size scaling value.
  21. float scale_;
  22. /// Rotation speed.
  23. float rotationSpeed_;
  24. /// Current color animation index.
  25. unsigned colorIndex_;
  26. /// Current texture animation index.
  27. unsigned texIndex_;
  28. };
  29. */
  30. /// %Color animation frame definition.
  31. struct ColorFrame
  32. {
  33. /// Construct with default values.
  34. ColorFrame();
  35. /// Construct with a color and zero time.
  36. ColorFrame(const Color& color);
  37. /// Construct from a color and time.
  38. ColorFrame(const Color& color, float time);
  39. /// Return interpolated value with another color-time pair at the time specified.
  40. Color Interpolate(const ColorFrame& next, float time);
  41. /// Color.
  42. Color color_ @ color;
  43. /// Time.
  44. float time_ @ time;
  45. };
  46. /// %Texture animation frame definition.
  47. struct TextureFrame
  48. {
  49. /// Construct with default values.
  50. TextureFrame();
  51. /// UV coordinates.
  52. Rect uv_ @ uv;
  53. /// Time.
  54. float time_ @ time;
  55. };
  56. /// %Particle emitter component.
  57. class ParticleEmitter : public BillboardSet
  58. {
  59. public:
  60. /// Load emitter parameters from an XML file.
  61. bool Load(XMLFile* file);
  62. /// Set maximum number of particles.
  63. void SetNumParticles(unsigned num);
  64. /// Set emission rate (both minimum and maximum.)
  65. void SetEmissionRate(float rate);
  66. /// Set minimum emission rate.
  67. void SetMinEmissionRate(float rate);
  68. /// Set maximum emission rate.
  69. void SetMaxEmissionRate(float rate);
  70. /// Set emitter type.
  71. void SetEmitterType(EmitterType type);
  72. /// Set emitter size.
  73. void SetEmitterSize(const Vector3& size);
  74. /// Set emission active period length (0 = infinite.)
  75. void SetActiveTime(float time);
  76. /// Set emission inactive period length (0 = infinite.)
  77. void SetInactiveTime(float time);
  78. /// Set whether should be emitting and optionally reset emission period.
  79. void SetEmitting(bool enable, bool resetPeriod = false);
  80. /// Set whether to update when particles are not visible.
  81. void SetUpdateInvisible(bool enable);
  82. /// Set particle time to live (both minimum and maximum.)
  83. void SetTimeToLive(float time);
  84. /// Set particle minimum time to live.
  85. void SetMinTimeToLive(float time);
  86. /// Set particle maximum time to live.
  87. void SetMaxTimeToLive(float time);
  88. /// Set particle size (both minimum and maximum.)
  89. void SetParticleSize(const Vector2& size);
  90. /// Set particle minimum size.
  91. void SetMinParticleSize(const Vector2& size);
  92. /// Set particle maximum size.
  93. void SetMaxParticleSize(const Vector2& size);
  94. /// Set negative direction limit.
  95. void SetMinDirection(const Vector3& direction);
  96. /// Set positive direction limit.
  97. void SetMaxDirection(const Vector3& direction);
  98. /// Set particle velocity (both minimum and maximum.)
  99. void SetVelocity(float velocity);
  100. /// Set particle minimum velocity.
  101. void SetMinVelocity(float velocity);
  102. /// Set particle maximum velocity.
  103. void SetMaxVelocity(float velocity);
  104. /// Set particle rotation (both minimum and maximum.)
  105. void SetRotation(float rotation);
  106. /// Set particle minimum rotation.
  107. void SetMinRotation(float rotation);
  108. /// Set particle maximum rotation.
  109. void SetMaxRotation(float rotation);
  110. /// Set particle rotation speed (both minimum and maximum.)
  111. void SetRotationSpeed(float speed);
  112. /// Set particle minimum rotation speed.
  113. void SetMinRotationSpeed(float speed);
  114. /// Set particle maximum rotation speed.
  115. void SetMaxRotationSpeed(float speed);
  116. /// Set constant force acting on particles.
  117. void SetConstantForce(const Vector3& force);
  118. /// Set particle velocity damping force.
  119. void SetDampingForce(float force);
  120. /// Set particle size additive modifier.
  121. void SetSizeAdd(float sizeAdd);
  122. /// Set particle size multiplicative modifier.
  123. void SetSizeMul(float sizeMul);
  124. /// Set color of particles.
  125. void SetColor(const Color& color);
  126. /// Set number of color animation frames.
  127. void SetNumColors(unsigned num);
  128. /// Set number of texture animation frames.
  129. void SetNumTextureFrames(unsigned num);
  130. /// Return maximum number of particles.
  131. unsigned GetNumParticles() const;
  132. /// Return whether is currently emitting.
  133. bool IsEmitting() const;
  134. /// Return whether to update when particles are not visible.
  135. bool GetUpdateInvisible() const;
  136. /// Return minimum emission rate.
  137. float GetMinEmissionRate() const;
  138. /// Return maximum emission rate.
  139. float GetMaxEmissionRate() const;
  140. /// Return emitter type.
  141. EmitterType GetEmitterType() const;
  142. /// Return emitter size.
  143. const Vector3& GetEmitterSize() const;
  144. /// Return emission active period length (0 = infinite.)
  145. float GetActiveTime() const;
  146. /// Return emission inactive period length (0 = infinite.)
  147. float GetInactiveTime() const;
  148. /// Return particle minimum time to live.
  149. float GetMinTimeToLive() const;
  150. /// Return particle maximum time to live.
  151. float GetMaxTimeToLive() const;
  152. /// Return particle minimum size.
  153. const Vector2& GetMinParticleSize() const;
  154. /// Return particle maximum size.
  155. const Vector2& GetMaxParticleSize() const;
  156. /// Return negative direction limit.
  157. const Vector3& GetMinDirection() const;
  158. /// Return positive direction limit.
  159. const Vector3& GetMaxDirection() const;
  160. /// Return particle minimum velocity.
  161. float GetMinVelocity() const;
  162. /// Return particle maximum velocity.
  163. float GetMaxVelocity() const;
  164. /// Return particle minimum rotation.
  165. float GetMinRotation() const;
  166. /// Return particle maximum rotation.
  167. float GetMaxRotation() const;
  168. /// Return particle minimum rotation speed.
  169. float GetMinRotationSpeed() const;
  170. /// Return particle maximum rotation speed.
  171. float GetMaxRotationSpeed() const;
  172. /// Return constant force acting on particles.
  173. const Vector3& GetConstantForce() const;
  174. /// Return particle velocity damping force.
  175. float GetDampingForce() const;
  176. /// Return particle size additive modifier.
  177. float GetSizeAdd() const;
  178. /// Return particle size multiplicative modifier.
  179. float GetSizeMul() const;
  180. /// Return number of color animation frames.
  181. unsigned GetNumColors() const;
  182. /// Return a color animation frame, or null if outside range.
  183. ColorFrame* GetColor(unsigned index);
  184. /// Return number of texture animation frames.
  185. unsigned GetNumTextureFrames() const;
  186. /// Return a texture animation frame, or null if outside range.
  187. TextureFrame* GetTextureFrame(unsigned index);
  188. };