AnimationTarget.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #ifndef ANIMATIONTARGET_H_
  2. #define ANIMATIONTARGET_H_
  3. #include "Curve.h"
  4. #include "AnimationController.h"
  5. namespace gameplay
  6. {
  7. class Animation;
  8. class AnimationValue;
  9. class NodeCloneContext;
  10. /**
  11. * Defines an interface allowing animation to target
  12. * an object for changing its animation properties.
  13. */
  14. class AnimationTarget
  15. {
  16. friend class Animation;
  17. friend class AnimationClip;
  18. friend class AnimationController;
  19. public:
  20. /**
  21. * Creates an animation on this target from a set of key value and key time pairs.
  22. * Cannot use Curve::BEZIER or CURVE::HERMITE as the interpolation type since they require tangents/control points.
  23. *
  24. * @param id The ID of the animation.
  25. * @param propertyId The property on this target to animate.
  26. * @param keyCount The number of keyframes in the animation. Must be greater than one.
  27. * @param keyTimes The list of key times for the animation (in milliseconds).
  28. * @param keyValues The list of key values for the animation.
  29. * @param type The curve interpolation type.
  30. *
  31. * @return The newly created animation.
  32. */
  33. Animation* createAnimation(const char* id, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, Curve::InterpolationType type);
  34. /**
  35. * Creates an animation on this target from a set of key value and key time pairs.
  36. *
  37. * @param id The ID of the animation.
  38. * @param propertyId The property on this target to animate.
  39. * @param keyCount The number of keyframes in the animation. Must be greater than one.
  40. * @param keyTimes The list of key times for the animation (in milliseconds).
  41. * @param keyValues The list of key values for the animation.
  42. * @param keyInValue The list of key in values for the animation.
  43. * @param keyOutValue The list of key out values for the animation.
  44. * @param type The curve interpolation type.
  45. *
  46. * @return The newly created animation.
  47. */
  48. Animation* createAnimation(const char* id, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, Curve::InterpolationType type);
  49. /**
  50. * Creates an animation on this target using the data from the given properties object.
  51. *
  52. * @param id The ID of the animation.
  53. * @param animationFile The animation file defining the animation data.
  54. *
  55. * @return The newly created animation.
  56. */
  57. Animation* createAnimation(const char* id, const char* animationFile);
  58. /**
  59. * Creates an animation on this target using the data from the given properties object.
  60. *
  61. * @param id The ID of the animation.
  62. * @param animationProperties The properties object defining the animation data.
  63. *
  64. * @return The newly created animation.
  65. */
  66. Animation* createAnimation(const char* id, Properties* animationProperties);
  67. /**
  68. * Creates a simple two keyframe from-to animation.
  69. * Cannot use Curve::BEZIER or CURVE::HERMITE as the interpolation type since they require tangents/control points.
  70. *
  71. * @param id The ID of the animation.
  72. * @param propertyId The property on this target to animate.
  73. * @param from The values to animate from.
  74. * @param to The values to animate to.
  75. * @param type The curve interpolation type.
  76. * @param duration The duration of the animation (in milliseconds).
  77. *
  78. * @return The newly created animation.
  79. */
  80. Animation* createAnimationFromTo(const char* id, int propertyId, float* from, float* to, Curve::InterpolationType type, unsigned long duration);
  81. /**
  82. * Creates a simple two keyframe from-by animation.
  83. * Cannot use Curve::BEZIER or CURVE::HERMITE as the interpolation type since they require tangents/control points.
  84. *
  85. * @param id The ID of the animation.
  86. * @param propertyId The property on this target to animate.
  87. * @param from The values to animate from.
  88. * @param by The values to animate by.
  89. * @param type The curve interpolation type.
  90. * @param duration The duration of the animation (in milliseconds).
  91. *
  92. * @return The newly created animation.
  93. */
  94. Animation* createAnimationFromBy(const char* id, int propertyId, float* from, float* by, Curve::InterpolationType type, unsigned long duration);
  95. /**
  96. * Destroys the animation with the specified ID. Destroys the first animation if ID is NULL.
  97. *
  98. * @param id The ID of the animation to destroy.
  99. */
  100. void destroyAnimation(const char* id = NULL);
  101. /**
  102. * Abstract method to return the property component count of the given property ID on the AnimationTarget.
  103. *
  104. * @param propertyId The ID of the property on the AnimationTarget to obtain the component count for.
  105. *
  106. * @return The property component count of the given property.
  107. */
  108. virtual unsigned int getAnimationPropertyComponentCount(int propertyId) const = 0;
  109. /**
  110. * Abstract method for getting the animation property value for the given property ID on the AnimationTarget.
  111. *
  112. * @param propertyId The ID of the property on the AnimationTarget to get the animation property value for.
  113. * @param value The container to get the animation property value in.
  114. */
  115. virtual void getAnimationPropertyValue(int propertyId, AnimationValue* value) = 0;
  116. /**
  117. * Abstract method for setting the animation property value for the given property ID on the AnimationTarget.
  118. *
  119. * @param propertyId The ID of the property on the AnimationTarget to set the animation property value on.
  120. * @param value The container to set the animation property value in.
  121. * @param blendWeight The blend weight.
  122. */
  123. virtual void setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight = 1.0f) = 0;
  124. /**
  125. * Gets the animation with the specified ID. If the ID is NULL, this function will return the first animation it finds.
  126. *
  127. * @param id The name of the animation to get.
  128. */
  129. Animation* getAnimation(const char* id = NULL) const;
  130. protected:
  131. /**
  132. * The type of animation target.
  133. */
  134. enum TargetType
  135. {
  136. SCALAR,
  137. TRANSFORM
  138. };
  139. /**
  140. * Constructor.
  141. */
  142. AnimationTarget();
  143. /**
  144. * Destructor.
  145. */
  146. virtual ~AnimationTarget();
  147. /**
  148. * Adds the given animation channel to this animation target.
  149. *
  150. * @param channel The animation channel to add.
  151. */
  152. void addChannel(Animation::Channel* channel);
  153. /**
  154. * Removes the given animation channel from this animation target.
  155. *
  156. * @param channel The animation channel to delete.
  157. */
  158. void removeChannel(Animation::Channel* channel);
  159. /**
  160. * Gets the Animation::Channel that belongs to the Animation with the specified ID.
  161. *
  162. * @param id The ID of the Animation the Channel belongs to.
  163. */
  164. Animation::Channel* getChannel(const char* id) const;
  165. /**
  166. * Copies data from this animation target into the given target for the purpose of cloning.
  167. *
  168. * @param target The target to copy into.
  169. * @param context The clone context.
  170. */
  171. void cloneInto(AnimationTarget* target, NodeCloneContext &context) const;
  172. /**
  173. * The target's type.
  174. *
  175. * @see TargetType::SCALAR
  176. * @see TargetType::TRANSFORM
  177. */
  178. TargetType _targetType;
  179. /**
  180. * Bit flag used to indicate which properties on the AnimationTarget are currently animating.
  181. */
  182. unsigned char _animationPropertyBitFlag;
  183. private:
  184. /**
  185. * Constructor.
  186. */
  187. AnimationTarget(const AnimationTarget& copy);
  188. /**
  189. * Gets the TargetType's property ID value for the specified property ID string.
  190. *
  191. * @param type The TargetType of the AnimationTarget.
  192. * @param propertyIdStr The property ID string.
  193. * @return The property ID value for teh property ID string; -1 if the propertyIdStr does not exist
  194. * for the TargetType.
  195. */
  196. static int getPropertyId(TargetType type, const char* propertyIdStr);
  197. std::vector<Animation::Channel*>* _animationChannels; // Collection of all animation channels that target the AnimationTarget
  198. };
  199. }
  200. #endif