AnimationTarget.h 8.9 KB

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