Particle.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 <OgrePrerequisites.h>
  17. #include <Ogre.h>
  18. #include "ParticleAdditionalData.h"
  19. class ParticleEmitter;
  20. /**
  21. * A particle.
  22. *
  23. * Particles are emitted by one {@see ParticleEmitter}.
  24. */
  25. class Particle{
  26. public:
  27. /**
  28. * Types of particles.
  29. */
  30. enum ParticleType{
  31. /**
  32. * A visual particle.
  33. */
  34. PT_VISUAL,
  35. /**
  36. * @todo Document.
  37. */
  38. PT_EMITTER
  39. };
  40. /**
  41. * Constructor.
  42. */
  43. Particle();
  44. /**
  45. * Destructor.
  46. */
  47. virtual ~Particle() = 0;
  48. /**
  49. * Initializes the particle.
  50. *
  51. * It makes it ready for emission.
  52. */
  53. virtual void InitForEmission(){};
  54. /**
  55. * Initializes the particle.
  56. *
  57. * It makes it ready for expiration.
  58. * @todo: Document this properly.
  59. */
  60. virtual void InitForExpiration(){};
  61. /**
  62. * Updates the particle.
  63. *
  64. * Updates it position based on the time lived by the particle.
  65. *
  66. * @param time_elapsed[in] Time lived by the particle.
  67. */
  68. virtual void Update(Ogre::Real time_elapsed);
  69. /**
  70. * Copies the particle attributes to another particle.
  71. *
  72. * @param particle[out] The particl to copy the atttributes to.
  73. */
  74. virtual void CopyAttributesTo(Particle* particle);
  75. /**
  76. * Retrieves the particle type.
  77. *
  78. * @return The particle type.
  79. */
  80. ParticleType GetParticleType() const {return particle_type_;};
  81. /**
  82. * Sets the particle emitter.
  83. *
  84. * @param parent_emitter[in] The emitter for the particle.
  85. * @todo Check if parent_emitter is an in or out parameter.
  86. */
  87. void SetParentEmitter(ParticleEmitter* parent_emitter){
  88. parent_emitter_ = parent_emitter;
  89. };
  90. /**
  91. * Retrieves the particle emitter.
  92. *
  93. * @return The emitter.
  94. */
  95. ParticleEmitter* GetParentEmitter() const {return parent_emitter_;};
  96. /**
  97. * Enables or disables the particle
  98. *
  99. * @param enabled[in] True to enable the particle, false to disable it.
  100. */
  101. void SetEnabled(bool enabled) {enabled_ = enabled;};
  102. /**
  103. * Checks if the particle is enabled.
  104. *
  105. * @return True if the particle is enabled, false otherwise.
  106. */
  107. bool IsEnabled() const {return enabled_;};
  108. /**
  109. * Toggles the particle emitability.
  110. *
  111. * @param emittable[in] True to make the particle emittable, false to
  112. * prevent it to be emitted.
  113. */
  114. void SetEmittable(bool emittable) {emittable_ = emittable;};
  115. /**
  116. * Checks if the particle can be emitted.
  117. *
  118. * @return True if the particle can be emitted, false if it can't.
  119. */
  120. bool IsEmittable() const {return emittable_;};
  121. /**
  122. * Additional data for the particle.
  123. */
  124. ParticleAdditionalData* additional_data;
  125. /**
  126. * The particle position.
  127. */
  128. Ogre::Vector3 position;
  129. /**
  130. * The direction that the particle is or will be emitted to.
  131. */
  132. Ogre::Vector3 direction;
  133. /**
  134. * The particle duration.
  135. *
  136. * @todo Seconds? Milliseconds? Frames?
  137. * @todo Differenche with total_time_to_live?
  138. */
  139. float time_to_live;
  140. /**
  141. * The particle duration.
  142. *
  143. * @todo Seconds? Milliseconds? Frames?
  144. * @todo Differenche with time_to_live?
  145. */
  146. float total_time_to_live;
  147. protected:
  148. /**
  149. * The particle emitter.
  150. */
  151. ParticleEmitter* parent_emitter_;
  152. /**
  153. * The particle type.
  154. */
  155. ParticleType particle_type_;
  156. /**
  157. * Indicates if the particle is enabled.
  158. */
  159. bool enabled_;
  160. /**
  161. * Indicates if the particl can be emitted.
  162. */
  163. bool emittable_;
  164. };