Animation.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #ifndef ANIMATION_H_
  2. #define ANIMATION_H_
  3. #include "Ref.h"
  4. namespace gameplay
  5. {
  6. class AnimationTarget;
  7. class AnimationController;
  8. class AnimationClip;
  9. class Curve;
  10. /**
  11. * Defines a generic property animation.
  12. *
  13. * To run an animation you must play an AnimationClip.
  14. * Every Animation has the default clip which will run from begin-end time.
  15. * You can create additional clips to run only parts of an animation and control
  16. * various runtime characteristics, such as repeat count, etc.
  17. */
  18. class Animation : public Ref
  19. {
  20. friend class AnimationController;
  21. friend class AnimationClip;
  22. friend class AnimationTarget;
  23. friend class Package;
  24. public:
  25. /**
  26. * Gets the Animation's ID.
  27. *
  28. * @return The Animation's ID.
  29. */
  30. const char* getId() const;
  31. /**
  32. * Gets the Animation's duration.
  33. *
  34. * @return The Animation's duration (in milliseconds).
  35. */
  36. unsigned long getDuration() const;
  37. /**
  38. * Creates an AnimationClip from an .animation file.
  39. */
  40. void createClips(const char* animationFile);
  41. /**
  42. * Creates an AnimationClip from the Animation.
  43. *
  44. * @param id The ID to the give the AnimationClip.
  45. * @param start The time (in milliseconds) that the AnimationClip will begin from.
  46. * @param end The time (in milliseconds) that the AnimationClip will end.
  47. *
  48. * @return The newly created AnimationClip; NULL if an AnimationClip already exists with the same ID.
  49. */
  50. AnimationClip* createClip(const char* id, unsigned long start, unsigned long end);
  51. /**
  52. * Finds the AnimationClip with the specified name. If NULL, gets the default clip.
  53. *
  54. * @param clipId The ID of the AnimationClip to get.
  55. *
  56. * @return The AnimationClip with the specified ID; NULL if an AnimationClip with the given ID is not found.
  57. */
  58. AnimationClip* getClip(const char* clipId = NULL);
  59. /**
  60. * Plays the AnimationClip with the specified name.
  61. *
  62. * @param clipId The ID of the AnimationClip to play. If NULL, plays the default clip.
  63. */
  64. void play(const char* clipId = NULL);
  65. /**
  66. * Stops the AnimationClip with the specified name.
  67. *
  68. * @param clipId The ID of the AnimationClip to stop. If NULL, stops the default clip.
  69. */
  70. void stop(const char* clipId = NULL);
  71. private:
  72. /**
  73. * Defines a channel which holds the target, target property, curve values, and duration.
  74. *
  75. * An animation can have 1 or more channels. All typical simple property animations
  76. * will have 1 channel. Skeletal animation will have 1 channel per joint to be animated.
  77. */
  78. class Channel
  79. {
  80. friend class AnimationClip;
  81. friend class Animation;
  82. friend class AnimationTarget;
  83. private:
  84. Channel(Animation* animation, AnimationTarget* target, int propertyId, Curve* curve, unsigned long duration);
  85. Channel(const Channel& copy);
  86. ~Channel();
  87. Animation* _animation; // Reference to the animation this channel belongs to.
  88. AnimationTarget* _target; // The target of this channel.
  89. int _propertyId; // The target property this channel targets.
  90. Curve* _curve; // The curve used to represent the animation data.
  91. unsigned long _duration; // The length of the animation (in milliseconds).
  92. };
  93. /**
  94. * Constructor.
  95. */
  96. Animation();
  97. /**
  98. * Constructor.
  99. */
  100. Animation(const Animation& copy);
  101. /**
  102. * Constructor.
  103. */
  104. Animation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, unsigned int type);
  105. /**
  106. * Constructor.
  107. */
  108. Animation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, unsigned int type);
  109. /**
  110. * Destructor.
  111. */
  112. ~Animation();
  113. /**
  114. * Adds a clip to this Animation.
  115. */
  116. void addClip(AnimationClip* clip);
  117. /**
  118. * Finds the clip with the given ID.
  119. */
  120. AnimationClip* findClip(const char* id) const;
  121. /**
  122. * Creates the default clip.
  123. */
  124. void createDefaultClip();
  125. /**
  126. * Creates a channel within this animation.
  127. */
  128. Channel* createChannel(AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, unsigned int type);
  129. /**
  130. * Creates a channel within this animation.
  131. */
  132. Channel* createChannel(AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, unsigned int type);
  133. /**
  134. * Adds a channel to the animation.
  135. */
  136. void addChannel(Channel* channel);
  137. /**
  138. * Removes a channel from the animation.
  139. */
  140. void removeChannel(Channel* channel);
  141. AnimationController* _controller; // The AnimationController that this Animation will run on.
  142. std::string _id; // The Animation's ID.
  143. unsigned long _duration; // the length of the animation (in milliseconds).
  144. std::vector<Channel*> _channels; // The channels within this Animation.
  145. AnimationClip* _defaultClip; // The Animation's default clip.
  146. std::vector<AnimationClip*>* _clips; // All the clips created from this Animation.
  147. };
  148. }
  149. #endif