Animation.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /******************************************************************************
  2. * Spine Runtimes Software License
  3. * Version 2
  4. *
  5. * Copyright (c) 2013, Esoteric Software
  6. * All rights reserved.
  7. *
  8. * You are granted a perpetual, non-exclusive, non-sublicensable and
  9. * non-transferable license to install, execute and perform the Spine Runtimes
  10. * Software (the "Software") solely for internal use. Without the written
  11. * permission of Esoteric Software, you may not (a) modify, translate, adapt or
  12. * otherwise create derivative works, improvements of the Software or develop
  13. * new applications using the Software or (b) remove, delete, alter or obscure
  14. * any trademarks or any copyright, trademark, patent or other intellectual
  15. * property or proprietary rights notices on or in the Software, including
  16. * any copy thereof. Redistributions in binary or source form must include
  17. * this license and terms. THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  19. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTARE BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *****************************************************************************/
  28. #ifndef SPINE_ANIMATION_H_
  29. #define SPINE_ANIMATION_H_
  30. #include <spine/Event.h>
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. typedef struct spTimeline spTimeline;
  35. struct spSkeleton;
  36. typedef struct {
  37. const char* const name;
  38. float duration;
  39. int timelineCount;
  40. spTimeline** timelines;
  41. } spAnimation;
  42. spAnimation* spAnimation_create (const char* name, int timelineCount);
  43. void spAnimation_dispose (spAnimation* self);
  44. /** Poses the skeleton at the specified time for this animation.
  45. * @param lastTime The last time the animation was applied.
  46. * @param events Any triggered events are added. */
  47. void spAnimation_apply (const spAnimation* self, struct spSkeleton* skeleton, float lastTime, float time, int loop,
  48. spEvent** events, int* eventCount);
  49. /** Poses the skeleton at the specified time for this animation mixed with the current pose.
  50. * @param lastTime The last time the animation was applied.
  51. * @param events Any triggered events are added.
  52. * @param alpha The amount of this animation that affects the current pose. */
  53. void spAnimation_mix (const spAnimation* self, struct spSkeleton* skeleton, float lastTime, float time, int loop,
  54. spEvent** events, int* eventCount, float alpha);
  55. #ifdef SPINE_SHORT_NAMES
  56. typedef spAnimation Animation;
  57. #define Animation_create(...) spAnimation_create(__VA_ARGS__)
  58. #define Animation_dispose(...) spAnimation_dispose(__VA_ARGS__)
  59. #define Animation_apply(...) spAnimation_apply(__VA_ARGS__)
  60. #define Animation_mix(...) spAnimation_mix(__VA_ARGS__)
  61. #endif
  62. /**/
  63. typedef enum {
  64. TIMELINE_SCALE, TIMELINE_ROTATE, TIMELINE_TRANLATE, TIMELINE_COLOR, TIMELINE_ATTACHMENT, TIMELINE_EVENT, TIMELINE_DRAWORDER
  65. } spTimelineType;
  66. struct spTimeline {
  67. const spTimelineType type;
  68. const void* const vtable;
  69. };
  70. void spTimeline_dispose (spTimeline* self);
  71. void spTimeline_apply (const spTimeline* self, struct spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents,
  72. int* eventCount, float alpha);
  73. #ifdef SPINE_SHORT_NAMES
  74. typedef spTimeline Timeline;
  75. #define Timeline_dispose(...) spTimeline_dispose(__VA_ARGS__)
  76. #define Timeline_apply(...) spTimeline_apply(__VA_ARGS__)
  77. #endif
  78. /**/
  79. typedef struct {
  80. spTimeline super;
  81. float* curves; /* dfx, dfy, ddfx, ddfy, dddfx, dddfy, ... */
  82. } spCurveTimeline;
  83. void spCurveTimeline_setLinear (spCurveTimeline* self, int frameIndex);
  84. void spCurveTimeline_setStepped (spCurveTimeline* self, int frameIndex);
  85. /* Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
  86. * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of
  87. * the difference between the keyframe's values. */
  88. void spCurveTimeline_setCurve (spCurveTimeline* self, int frameIndex, float cx1, float cy1, float cx2, float cy2);
  89. float spCurveTimeline_getCurvePercent (const spCurveTimeline* self, int frameIndex, float percent);
  90. #ifdef SPINE_SHORT_NAMES
  91. typedef spCurveTimeline CurveTimeline;
  92. #define CurveTimeline_setLinear(...) spCurveTimeline_setLinear(__VA_ARGS__)
  93. #define CurveTimeline_setStepped(...) spCurveTimeline_setStepped(__VA_ARGS__)
  94. #define CurveTimeline_setCurve(...) spCurveTimeline_setCurve(__VA_ARGS__)
  95. #define CurveTimeline_getCurvePercent(...) spCurveTimeline_getCurvePercent(__VA_ARGS__)
  96. #endif
  97. /**/
  98. typedef struct spBaseTimeline {
  99. spCurveTimeline super;
  100. int const framesLength;
  101. float* const frames; /* time, angle, ... for rotate. time, x, y, ... for translate and scale. */
  102. int boneIndex;
  103. } spRotateTimeline;
  104. spRotateTimeline* spRotateTimeline_create (int frameCount);
  105. void spRotateTimeline_setFrame (spRotateTimeline* self, int frameIndex, float time, float angle);
  106. #ifdef SPINE_SHORT_NAMES
  107. typedef spRotateTimeline RotateTimeline;
  108. #define RotateTimeline_create(...) spRotateTimeline_create(__VA_ARGS__)
  109. #define RotateTimeline_setFrame(...) spRotateTimeline_setFrame(__VA_ARGS__)
  110. #endif
  111. /**/
  112. typedef struct spBaseTimeline spTranslateTimeline;
  113. spTranslateTimeline* spTranslateTimeline_create (int frameCount);
  114. void spTranslateTimeline_setFrame (spTranslateTimeline* self, int frameIndex, float time, float x, float y);
  115. #ifdef SPINE_SHORT_NAMES
  116. typedef spTranslateTimeline TranslateTimeline;
  117. #define TranslateTimeline_create(...) spTranslateTimeline_create(__VA_ARGS__)
  118. #define TranslateTimeline_setFrame(...) spTranslateTimeline_setFrame(__VA_ARGS__)
  119. #endif
  120. /**/
  121. typedef struct spBaseTimeline spScaleTimeline;
  122. spScaleTimeline* spScaleTimeline_create (int frameCount);
  123. void spScaleTimeline_setFrame (spScaleTimeline* self, int frameIndex, float time, float x, float y);
  124. #ifdef SPINE_SHORT_NAMES
  125. typedef spScaleTimeline ScaleTimeline;
  126. #define ScaleTimeline_create(...) spScaleTimeline_create(__VA_ARGS__)
  127. #define ScaleTimeline_setFrame(...) spScaleTimeline_setFrame(__VA_ARGS__)
  128. #endif
  129. /**/
  130. typedef struct {
  131. spCurveTimeline super;
  132. int const framesLength;
  133. float* const frames; /* time, r, g, b, a, ... */
  134. int slotIndex;
  135. } spColorTimeline;
  136. spColorTimeline* spColorTimeline_create (int frameCount);
  137. void spColorTimeline_setFrame (spColorTimeline* self, int frameIndex, float time, float r, float g, float b, float a);
  138. #ifdef SPINE_SHORT_NAMES
  139. typedef spColorTimeline ColorTimeline;
  140. #define ColorTimeline_create(...) spColorTimeline_create(__VA_ARGS__)
  141. #define ColorTimeline_setFrame(...) spColorTimeline_setFrame(__VA_ARGS__)
  142. #endif
  143. /**/
  144. typedef struct {
  145. spTimeline super;
  146. int const framesLength;
  147. float* const frames; /* time, ... */
  148. int slotIndex;
  149. const char** const attachmentNames;
  150. } spAttachmentTimeline;
  151. spAttachmentTimeline* spAttachmentTimeline_create (int frameCount);
  152. /* @param attachmentName May be 0. */
  153. void spAttachmentTimeline_setFrame (spAttachmentTimeline* self, int frameIndex, float time, const char* attachmentName);
  154. #ifdef SPINE_SHORT_NAMES
  155. typedef spAttachmentTimeline AttachmentTimeline;
  156. #define AttachmentTimeline_create(...) spAttachmentTimeline_create(__VA_ARGS__)
  157. #define AttachmentTimeline_setFrame(...) spAttachmentTimeline_setFrame(__VA_ARGS__)
  158. #endif
  159. /**/
  160. typedef struct {
  161. spTimeline super;
  162. int const framesLength;
  163. float* const frames; /* time, ... */
  164. spEvent** const events;
  165. } spEventTimeline;
  166. spEventTimeline* spEventTimeline_create (int frameCount);
  167. void spEventTimeline_setFrame (spEventTimeline* self, int frameIndex, float time, spEvent* event);
  168. #ifdef SPINE_SHORT_NAMES
  169. typedef spEventTimeline EventTimeline;
  170. #define EventTimeline_create(...) spEventTimeline_create(__VA_ARGS__)
  171. #define EventTimeline_setFrame(...) spEventTimeline_setFrame(__VA_ARGS__)
  172. #endif
  173. /**/
  174. typedef struct {
  175. spTimeline super;
  176. int const framesLength;
  177. float* const frames; /* time, ... */
  178. const int** const drawOrders;
  179. int const slotCount;
  180. } spDrawOrderTimeline;
  181. spDrawOrderTimeline* spDrawOrderTimeline_create (int frameCount, int slotCount);
  182. void spDrawOrderTimeline_setFrame (spDrawOrderTimeline* self, int frameIndex, float time, const int* drawOrder);
  183. #ifdef SPINE_SHORT_NAMES
  184. typedef spDrawOrderTimeline DrawOrderTimeline;
  185. #define DrawOrderTimeline_create(...) spDrawOrderTimeline_create(__VA_ARGS__)
  186. #define DrawOrderTimeline_setFrame(...) spDrawOrderTimeline_setFrame(__VA_ARGS__)
  187. #endif
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #endif /* SPINE_ANIMATION_H_ */