Animation.h 6.0 KB

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