ParticleEmitter.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreStringInterface.h>
  17. #include "Particle.h"
  18. #include "ParticleEmitterDictionary.h"
  19. class ParticleTechnique;
  20. /**
  21. * A particle emitter.
  22. */
  23. class ParticleEmitter : public Ogre::StringInterface, public Particle{
  24. public:
  25. /**
  26. * Constructor.
  27. */
  28. ParticleEmitter();
  29. /**
  30. * Destructor.
  31. */
  32. virtual ~ParticleEmitter();
  33. /**
  34. * Copies attributes to other particle emmiter.
  35. *
  36. * @param emitter[out] The particle emmite to copy the attributes to.
  37. */
  38. virtual void CopyAttributesTo(ParticleEmitter* emitter);
  39. /**
  40. * @todo Understand and document.
  41. */
  42. virtual void InitForEmission();
  43. /**
  44. * Calculates how many particles are to be emitted in a given time.
  45. *
  46. * @param time_elapsed[in] The elapsed time since the emitter has been
  47. * emitting.
  48. * @todo Understand and document.
  49. */
  50. virtual int CalculateRequestedParticles(Ogre::Real time_elapsed);
  51. /**
  52. * Initializes a article to be emmited.
  53. *
  54. * @param particle[out] The particle to be initialized.
  55. */
  56. virtual void InitParticleForEmission(Particle* particle);
  57. /**
  58. * Sets the parent technique for emitter.
  59. *
  60. * @param tech[in] Technique.
  61. * @todo Understand and document.
  62. */
  63. void SetParentTechnique(ParticleTechnique* tech){
  64. parent_technique_ = tech;
  65. };
  66. /**
  67. * Retrieves the parent technique of the emitter.
  68. *
  69. * @return Technique.
  70. * @todo Understand and document.
  71. */
  72. ParticleTechnique* GetParentTechnique() const {
  73. return parent_technique_;
  74. };
  75. /**
  76. * Set a name for the emitter.
  77. *
  78. * @param name[in] Name for the emitter.
  79. */
  80. void SetName(const Ogre::String& name){name_ = name;};
  81. /**
  82. * Retrieves the emitter name.
  83. *
  84. * @return Emitter name.
  85. */
  86. const Ogre::String& GetName() const{return name_;};
  87. /**
  88. * Sets the emitter type.
  89. *
  90. * @param emitter_type[in] The emitter type.
  91. */
  92. void SetEmitterType(const Ogre::String& emitter_type){
  93. emitter_type_ = emitter_type;
  94. };
  95. /**
  96. * Retrieves the emitter type.
  97. *
  98. * @return The emitter type.
  99. */
  100. const Ogre::String& GetEmitterType() const{return emitter_type_;};
  101. /**
  102. * Sets the name of the emits.
  103. *
  104. * When changed, notifies the technique of the change.
  105. *
  106. * @param emits_name[in] Name for the emits.
  107. * @todo What are the emits?
  108. */
  109. void SetEmitsName(const Ogre::String& emits_name);
  110. /**
  111. * Retrieves the name of the emits.
  112. *
  113. * @return Name of the emits
  114. * @todo What are the emits?
  115. */
  116. const Ogre::String& GetEmitsName() const{return emits_name_;};
  117. /**
  118. * Sets the type of the emits.
  119. *
  120. * @param emits_type[in] Type for the emits.
  121. * @todo What are the emits?
  122. */
  123. void SetEmitsType(ParticleType emits_type) {emits_type_ = emits_type;};
  124. /**
  125. * Retrieves the type of the emits.
  126. *
  127. * @return Type of the emits.
  128. * @todo What are the emits?
  129. */
  130. ParticleType GetEmitsType() const {return emits_type_;};
  131. /**
  132. * Set the emission rate for the emitter.
  133. *
  134. * @param rate[in] Emission rate.
  135. */
  136. void SetEmissionRate(int rate) {emission_rate_ = rate;};
  137. /**
  138. * Retrieves the emission rate of the emitter.
  139. *
  140. * @return Emission rate.
  141. */
  142. int GetEmissionRate() const {return emission_rate_;};
  143. /**
  144. * Sets the particle direction for the emitter.
  145. *
  146. * It sets a fixed direction. For a variable, ranged direction, use
  147. * {@see setEmitDirectionRange}.
  148. *
  149. * @param dir[in] Particle direction.
  150. */
  151. void SetEmitDirection(const Ogre::Vector3& dir){
  152. emit_direction_1_ = dir;
  153. emit_direction_2_ = dir;
  154. };
  155. /**
  156. * Sets the particle direction for the emitter.
  157. *
  158. * It sets a ranged direction. For each paticle, a random direction
  159. * between DIR_1 and DIR_2 will be assigned. For a fixed direction, use
  160. * {@see setEmitDirection}.
  161. *
  162. * @param dir_1[in] One of the limits for the range of directions.
  163. * @param dir_2[in] One of the limits for the range of directions.
  164. */
  165. void SetEmitDirectionRange(
  166. const Ogre::Vector3& dir_1, const Ogre::Vector3& dir_2
  167. ){
  168. emit_direction_1_ = dir_1;
  169. emit_direction_2_ = dir_2;
  170. };
  171. /**
  172. * Sets the time the particles must be displayed between being emitted
  173. * and disappearing.
  174. *
  175. * @param time[in] Duration of the particles.
  176. * @todo Time is in secons? milliseconds? frames?
  177. */
  178. void SetEmitTotalTimeToLive(float time){
  179. emit_total_time_to_live_ = time;
  180. };
  181. protected:
  182. /**
  183. * The particle technique.
  184. */
  185. ParticleTechnique* parent_technique_;
  186. /**
  187. * The emitter name.
  188. */
  189. Ogre::String name_;
  190. /**
  191. * The emitter type.
  192. */
  193. Ogre::String emitter_type_;
  194. /**
  195. * The emits name.
  196. */
  197. Ogre::String emits_name_;
  198. /**
  199. * The emits type.
  200. */
  201. ParticleType emits_type_;
  202. /**
  203. * Dictionary for emission rates.
  204. */
  205. static ParticleEmitterDictionary::EmissionRate
  206. emission_rate_dictionary_;
  207. /**
  208. * The emission rate.
  209. */
  210. int emission_rate_;
  211. /**
  212. * The remaining particles to be emitted.
  213. */
  214. Ogre::Real emission_remainder_;
  215. /**
  216. * Dictionary for particle directions.
  217. */
  218. static ParticleEmitterDictionary::Direction direction_dictionary_;
  219. /**
  220. * One of the limits for the range of directions.
  221. */
  222. Ogre::Vector3 emit_direction_1_;
  223. /**
  224. * One of the limits for the range of directions.
  225. */
  226. Ogre::Vector3 emit_direction_2_;
  227. /**
  228. * Disctionary for particle durations.
  229. */
  230. static ParticleEmitterDictionary::TotalTimeToLive
  231. total_time_to_live_dictionary_;
  232. /**
  233. * Particle duration.
  234. */
  235. float emit_total_time_to_live_;
  236. };