Background2DAnimation.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 <OgreString.h>
  17. #include <Ogre.h>
  18. #include <vector>
  19. #include "map/QGearsTile.h"
  20. class Background2D;
  21. /**
  22. * An animation in the background of a field.
  23. */
  24. class Background2DAnimation{
  25. public:
  26. /**
  27. * Constructor.
  28. *
  29. * @param name[in] The animation name.
  30. * @param background[in] The background to animate.
  31. * @param tile_index[in] The tile the animation applies to.
  32. */
  33. Background2DAnimation(
  34. const Ogre::String& name, Background2D* background,
  35. const int tile_index
  36. );
  37. /**
  38. * Destructor.
  39. */
  40. virtual ~Background2DAnimation();
  41. /**
  42. * Repetition status of the animation.
  43. */
  44. enum State{
  45. /**
  46. * The animation must be played once.
  47. */
  48. ONCE,
  49. /**
  50. * The animation must loop indefinitely.
  51. */
  52. LOOPED
  53. };
  54. /**
  55. * Adds time, so the animation state is changed according to it.
  56. *
  57. * @param time[in] The time passed
  58. * @todo time is in seconds?
  59. */
  60. void AddTime(const float time);
  61. /**
  62. * Retrieves the animation name.
  63. *
  64. * @return The animation name.
  65. */
  66. const Ogre::String& GetName() const;
  67. /**
  68. * Sets the time the animation has been running.
  69. *
  70. * @param time[in] The time the animation has been running.
  71. * @todo time is in seconds?
  72. */
  73. void SetTime( const float time );
  74. /**
  75. * Retrieves the time the animation has been running.
  76. *
  77. * @return The time the animation has been running.
  78. * @todo time is in seconds?
  79. */
  80. float GetTime() const;
  81. /**
  82. * Sets the duration of the animation.
  83. *
  84. * @param time[in] The duration of the animation.
  85. * @todo time is in seconds?
  86. */
  87. void SetLength(const float time);
  88. /**
  89. * Retrieves the duration of the animation.
  90. *
  91. * @return The duration of the animation.
  92. * @todo time is in seconds?
  93. */
  94. float GetLength() const;
  95. /**
  96. * Adds a keyframe to the animation.
  97. *
  98. * @param key_frame[in] The keyframe to add.
  99. */
  100. virtual void AddUVKeyFrame(const QGears::KeyFrame key_frame);
  101. /**
  102. * Adds a keyframe to the animation.
  103. *
  104. * @param time[in] Time to add the keyframe at.
  105. * @param uv[in] Animation vector.
  106. * @todo time is in seconds?
  107. */
  108. virtual void AddUVKeyFrame(const float time, const Ogre::Vector4& uv);
  109. /**
  110. * Adds a keyframe to the animation.
  111. *
  112. * @param time[in] Time to add the keyframe at.
  113. * @param u1[in] Animation vector component.
  114. * @param v1[in] Animation vector component.
  115. * @param u2[in] Animation vector component.
  116. * @param v2[in] Animation vector component.
  117. * @todo time is in seconds?
  118. */
  119. virtual void AddUVKeyFrame(
  120. const float time,
  121. const float u1, const float v1, const float u2, const float v2
  122. );
  123. private:
  124. /**
  125. * Constructor.
  126. */
  127. Background2DAnimation();
  128. /**
  129. * The animation name.
  130. */
  131. Ogre::String name_;
  132. /**
  133. * The background the animation belongs to.
  134. */
  135. Background2D* background_;
  136. /**
  137. * The index of the tile tha animation applies to.
  138. */
  139. int tile_index_;
  140. /**
  141. * The animation current time.
  142. */
  143. float time_;
  144. /**
  145. * The duration of the animation.
  146. */
  147. float length_;
  148. /**
  149. * A keyframe.
  150. */
  151. struct Background2DKeyFrameUV{
  152. /**
  153. * Keyframe time.
  154. */
  155. float time;
  156. /**
  157. * Keyframe vector component.
  158. */
  159. float u1;
  160. /**
  161. * Keyframe vector component.
  162. */
  163. float v1;
  164. /**
  165. * Keyframe vector component.
  166. */
  167. float u2;
  168. /**
  169. * Keyframe vector component.
  170. */
  171. float v2;
  172. };
  173. /**
  174. * Keyframe list.
  175. */
  176. std::vector<Background2DKeyFrameUV> uv_;
  177. };