Animation.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. #ifndef SPINE_ANIMATION_H_
  31. #define SPINE_ANIMATION_H_
  32. #include <spine/Event.h>
  33. #include <spine/Attachment.h>
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. typedef struct spTimeline spTimeline;
  38. struct spSkeleton;
  39. typedef struct spAnimation {
  40. const char* const name;
  41. float duration;
  42. int timelinesCount;
  43. spTimeline** timelines;
  44. #ifdef __cplusplus
  45. spAnimation() :
  46. name(0),
  47. duration(0),
  48. timelinesCount(0),
  49. timelines(0) {
  50. }
  51. #endif
  52. } spAnimation;
  53. spAnimation* spAnimation_create (const char* name, int timelinesCount);
  54. void spAnimation_dispose (spAnimation* self);
  55. /** Poses the skeleton at the specified time for this animation.
  56. * @param lastTime The last time the animation was applied.
  57. * @param events Any triggered events are added. May be null.*/
  58. void spAnimation_apply (const spAnimation* self, struct spSkeleton* skeleton, float lastTime, float time, int loop,
  59. spEvent** events, int* eventsCount, float alpha, int /*boolean*/ setupPose, int /*boolean*/ mixingOut);
  60. #ifdef SPINE_SHORT_NAMES
  61. typedef spAnimation Animation;
  62. #define Animation_create(...) spAnimation_create(__VA_ARGS__)
  63. #define Animation_dispose(...) spAnimation_dispose(__VA_ARGS__)
  64. #define Animation_apply(...) spAnimation_apply(__VA_ARGS__)
  65. #endif
  66. /**/
  67. typedef enum {
  68. SP_TIMELINE_ROTATE,
  69. SP_TIMELINE_TRANSLATE,
  70. SP_TIMELINE_SCALE,
  71. SP_TIMELINE_SHEAR,
  72. SP_TIMELINE_ATTACHMENT,
  73. SP_TIMELINE_COLOR,
  74. SP_TIMELINE_DEFORM,
  75. SP_TIMELINE_EVENT,
  76. SP_TIMELINE_DRAWORDER,
  77. SP_TIMELINE_IKCONSTRAINT,
  78. SP_TIMELINE_TRANSFORMCONSTRAINT,
  79. SP_TIMELINE_PATHCONSTRAINTPOSITION,
  80. SP_TIMELINE_PATHCONSTRAINTSPACING,
  81. SP_TIMELINE_PATHCONSTRAINTMIX
  82. } spTimelineType;
  83. struct spTimeline {
  84. const spTimelineType type;
  85. const void* const vtable;
  86. #ifdef __cplusplus
  87. spTimeline() :
  88. type(SP_TIMELINE_SCALE),
  89. vtable(0) {
  90. }
  91. #endif
  92. };
  93. void spTimeline_dispose (spTimeline* self);
  94. void spTimeline_apply (const spTimeline* self, struct spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents,
  95. int* eventsCount, float alpha, int /*boolean*/ setupPose, int /*boolean*/ mixingOut);
  96. int spTimeline_getPropertyId (const spTimeline* self);
  97. #ifdef SPINE_SHORT_NAMES
  98. typedef spTimeline Timeline;
  99. #define TIMELINE_SCALE SP_TIMELINE_SCALE
  100. #define TIMELINE_ROTATE SP_TIMELINE_ROTATE
  101. #define TIMELINE_TRANSLATE SP_TIMELINE_TRANSLATE
  102. #define TIMELINE_COLOR SP_TIMELINE_COLOR
  103. #define TIMELINE_ATTACHMENT SP_TIMELINE_ATTACHMENT
  104. #define TIMELINE_EVENT SP_TIMELINE_EVENT
  105. #define TIMELINE_DRAWORDER SP_TIMELINE_DRAWORDER
  106. #define Timeline_dispose(...) spTimeline_dispose(__VA_ARGS__)
  107. #define Timeline_apply(...) spTimeline_apply(__VA_ARGS__)
  108. #endif
  109. /**/
  110. typedef struct spCurveTimeline {
  111. spTimeline super;
  112. float* curves; /* type, x, y, ... */
  113. #ifdef __cplusplus
  114. spCurveTimeline() :
  115. super(),
  116. curves(0) {
  117. }
  118. #endif
  119. } spCurveTimeline;
  120. void spCurveTimeline_setLinear (spCurveTimeline* self, int frameIndex);
  121. void spCurveTimeline_setStepped (spCurveTimeline* self, int frameIndex);
  122. /* Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
  123. * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of
  124. * the difference between the keyframe's values. */
  125. void spCurveTimeline_setCurve (spCurveTimeline* self, int frameIndex, float cx1, float cy1, float cx2, float cy2);
  126. float spCurveTimeline_getCurvePercent (const spCurveTimeline* self, int frameIndex, float percent);
  127. #ifdef SPINE_SHORT_NAMES
  128. typedef spCurveTimeline CurveTimeline;
  129. #define CurveTimeline_setLinear(...) spCurveTimeline_setLinear(__VA_ARGS__)
  130. #define CurveTimeline_setStepped(...) spCurveTimeline_setStepped(__VA_ARGS__)
  131. #define CurveTimeline_setCurve(...) spCurveTimeline_setCurve(__VA_ARGS__)
  132. #define CurveTimeline_getCurvePercent(...) spCurveTimeline_getCurvePercent(__VA_ARGS__)
  133. #endif
  134. /**/
  135. typedef struct spBaseTimeline {
  136. spCurveTimeline super;
  137. int const framesCount;
  138. float* const frames; /* time, angle, ... for rotate. time, x, y, ... for translate and scale. */
  139. int boneIndex;
  140. #ifdef __cplusplus
  141. spBaseTimeline() :
  142. super(),
  143. framesCount(0),
  144. frames(0),
  145. boneIndex(0) {
  146. }
  147. #endif
  148. } spBaseTimeline;
  149. /**/
  150. static const int ROTATE_PREV_TIME = -2, ROTATE_PREV_ROTATION = -1;
  151. static const int ROTATE_ROTATION = 1;
  152. static const int ROTATE_ENTRIES = 2;
  153. typedef struct spBaseTimeline spRotateTimeline;
  154. spRotateTimeline* spRotateTimeline_create (int framesCount);
  155. void spRotateTimeline_setFrame (spRotateTimeline* self, int frameIndex, float time, float angle);
  156. #ifdef SPINE_SHORT_NAMES
  157. typedef spRotateTimeline RotateTimeline;
  158. #define RotateTimeline_create(...) spRotateTimeline_create(__VA_ARGS__)
  159. #define RotateTimeline_setFrame(...) spRotateTimeline_setFrame(__VA_ARGS__)
  160. #endif
  161. /**/
  162. static const int TRANSLATE_ENTRIES = 3;
  163. typedef struct spBaseTimeline spTranslateTimeline;
  164. spTranslateTimeline* spTranslateTimeline_create (int framesCount);
  165. void spTranslateTimeline_setFrame (spTranslateTimeline* self, int frameIndex, float time, float x, float y);
  166. #ifdef SPINE_SHORT_NAMES
  167. typedef spTranslateTimeline TranslateTimeline;
  168. #define TranslateTimeline_create(...) spTranslateTimeline_create(__VA_ARGS__)
  169. #define TranslateTimeline_setFrame(...) spTranslateTimeline_setFrame(__VA_ARGS__)
  170. #endif
  171. /**/
  172. typedef struct spBaseTimeline spScaleTimeline;
  173. spScaleTimeline* spScaleTimeline_create (int framesCount);
  174. void spScaleTimeline_setFrame (spScaleTimeline* self, int frameIndex, float time, float x, float y);
  175. #ifdef SPINE_SHORT_NAMES
  176. typedef spScaleTimeline ScaleTimeline;
  177. #define ScaleTimeline_create(...) spScaleTimeline_create(__VA_ARGS__)
  178. #define ScaleTimeline_setFrame(...) spScaleTimeline_setFrame(__VA_ARGS__)
  179. #endif
  180. /**/
  181. typedef struct spBaseTimeline spShearTimeline;
  182. spShearTimeline* spShearTimeline_create (int framesCount);
  183. void spShearTimeline_setFrame (spShearTimeline* self, int frameIndex, float time, float x, float y);
  184. #ifdef SPINE_SHORT_NAMES
  185. typedef spShearTimeline ShearTimeline;
  186. #define ShearTimeline_create(...) spShearTimeline_create(__VA_ARGS__)
  187. #define ShearTimeline_setFrame(...) spShearTimeline_setFrame(__VA_ARGS__)
  188. #endif
  189. /**/
  190. static const int COLOR_ENTRIES = 5;
  191. typedef struct spColorTimeline {
  192. spCurveTimeline super;
  193. int const framesCount;
  194. float* const frames; /* time, r, g, b, a, ... */
  195. int slotIndex;
  196. #ifdef __cplusplus
  197. spColorTimeline() :
  198. super(),
  199. framesCount(0),
  200. frames(0),
  201. slotIndex(0) {
  202. }
  203. #endif
  204. } spColorTimeline;
  205. spColorTimeline* spColorTimeline_create (int framesCount);
  206. void spColorTimeline_setFrame (spColorTimeline* self, int frameIndex, float time, float r, float g, float b, float a);
  207. #ifdef SPINE_SHORT_NAMES
  208. typedef spColorTimeline ColorTimeline;
  209. #define ColorTimeline_create(...) spColorTimeline_create(__VA_ARGS__)
  210. #define ColorTimeline_setFrame(...) spColorTimeline_setFrame(__VA_ARGS__)
  211. #endif
  212. /**/
  213. typedef struct spAttachmentTimeline {
  214. spTimeline super;
  215. int const framesCount;
  216. float* const frames; /* time, ... */
  217. int slotIndex;
  218. const char** const attachmentNames;
  219. #ifdef __cplusplus
  220. spAttachmentTimeline() :
  221. super(),
  222. framesCount(0),
  223. frames(0),
  224. slotIndex(0),
  225. attachmentNames(0) {
  226. }
  227. #endif
  228. } spAttachmentTimeline;
  229. spAttachmentTimeline* spAttachmentTimeline_create (int framesCount);
  230. /* @param attachmentName May be 0. */
  231. void spAttachmentTimeline_setFrame (spAttachmentTimeline* self, int frameIndex, float time, const char* attachmentName);
  232. #ifdef SPINE_SHORT_NAMES
  233. typedef spAttachmentTimeline AttachmentTimeline;
  234. #define AttachmentTimeline_create(...) spAttachmentTimeline_create(__VA_ARGS__)
  235. #define AttachmentTimeline_setFrame(...) spAttachmentTimeline_setFrame(__VA_ARGS__)
  236. #endif
  237. /**/
  238. typedef struct spEventTimeline {
  239. spTimeline super;
  240. int const framesCount;
  241. float* const frames; /* time, ... */
  242. spEvent** const events;
  243. #ifdef __cplusplus
  244. spEventTimeline() :
  245. super(),
  246. framesCount(0),
  247. frames(0),
  248. events(0) {
  249. }
  250. #endif
  251. } spEventTimeline;
  252. spEventTimeline* spEventTimeline_create (int framesCount);
  253. void spEventTimeline_setFrame (spEventTimeline* self, int frameIndex, spEvent* event);
  254. #ifdef SPINE_SHORT_NAMES
  255. typedef spEventTimeline EventTimeline;
  256. #define EventTimeline_create(...) spEventTimeline_create(__VA_ARGS__)
  257. #define EventTimeline_setFrame(...) spEventTimeline_setFrame(__VA_ARGS__)
  258. #endif
  259. /**/
  260. typedef struct spDrawOrderTimeline {
  261. spTimeline super;
  262. int const framesCount;
  263. float* const frames; /* time, ... */
  264. const int** const drawOrders;
  265. int const slotsCount;
  266. #ifdef __cplusplus
  267. spDrawOrderTimeline() :
  268. super(),
  269. framesCount(0),
  270. frames(0),
  271. drawOrders(0),
  272. slotsCount(0) {
  273. }
  274. #endif
  275. } spDrawOrderTimeline;
  276. spDrawOrderTimeline* spDrawOrderTimeline_create (int framesCount, int slotsCount);
  277. void spDrawOrderTimeline_setFrame (spDrawOrderTimeline* self, int frameIndex, float time, const int* drawOrder);
  278. #ifdef SPINE_SHORT_NAMES
  279. typedef spDrawOrderTimeline DrawOrderTimeline;
  280. #define DrawOrderTimeline_create(...) spDrawOrderTimeline_create(__VA_ARGS__)
  281. #define DrawOrderTimeline_setFrame(...) spDrawOrderTimeline_setFrame(__VA_ARGS__)
  282. #endif
  283. /**/
  284. typedef struct spDeformTimeline {
  285. spCurveTimeline super;
  286. int const framesCount;
  287. float* const frames; /* time, ... */
  288. int const frameVerticesCount;
  289. const float** const frameVertices;
  290. int slotIndex;
  291. spAttachment* attachment;
  292. #ifdef __cplusplus
  293. spDeformTimeline() :
  294. super(),
  295. framesCount(0),
  296. frames(0),
  297. frameVerticesCount(0),
  298. frameVertices(0),
  299. slotIndex(0) {
  300. }
  301. #endif
  302. } spDeformTimeline;
  303. spDeformTimeline* spDeformTimeline_create (int framesCount, int frameVerticesCount);
  304. void spDeformTimeline_setFrame (spDeformTimeline* self, int frameIndex, float time, float* vertices);
  305. #ifdef SPINE_SHORT_NAMES
  306. typedef spDeformTimeline DeformTimeline;
  307. #define DeformTimeline_create(...) spDeformTimeline_create(__VA_ARGS__)
  308. #define DeformTimeline_setFrame(...) spDeformTimeline_setFrame(__VA_ARGS__)
  309. #endif
  310. /**/
  311. static const int IKCONSTRAINT_ENTRIES = 3;
  312. typedef struct spIkConstraintTimeline {
  313. spCurveTimeline super;
  314. int const framesCount;
  315. float* const frames; /* time, mix, bendDirection, ... */
  316. int ikConstraintIndex;
  317. #ifdef __cplusplus
  318. spIkConstraintTimeline() :
  319. super(),
  320. framesCount(0),
  321. frames(0),
  322. ikConstraintIndex(0) {
  323. }
  324. #endif
  325. } spIkConstraintTimeline;
  326. spIkConstraintTimeline* spIkConstraintTimeline_create (int framesCount);
  327. void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameIndex, float time, float mix, int bendDirection);
  328. #ifdef SPINE_SHORT_NAMES
  329. typedef spIkConstraintTimeline IkConstraintTimeline;
  330. #define IkConstraintTimeline_create(...) spIkConstraintTimeline_create(__VA_ARGS__)
  331. #define IkConstraintTimeline_setFrame(...) spIkConstraintTimeline_setFrame(__VA_ARGS__)
  332. #endif
  333. /**/
  334. static const int TRANSFORMCONSTRAINT_ENTRIES = 5;
  335. typedef struct spTransformConstraintTimeline {
  336. spCurveTimeline super;
  337. int const framesCount;
  338. float* const frames; /* time, rotate mix, translate mix, scale mix, shear mix, ... */
  339. int transformConstraintIndex;
  340. #ifdef __cplusplus
  341. spTransformConstraintTimeline() :
  342. super(),
  343. framesCount(0),
  344. frames(0),
  345. transformConstraintIndex(0) {
  346. }
  347. #endif
  348. } spTransformConstraintTimeline;
  349. spTransformConstraintTimeline* spTransformConstraintTimeline_create (int framesCount);
  350. void spTransformConstraintTimeline_setFrame (spTransformConstraintTimeline* self, int frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix);
  351. #ifdef SPINE_SHORT_NAMES
  352. typedef spTransformConstraintTimeline TransformConstraintTimeline;
  353. #define TransformConstraintTimeline_create(...) spTransformConstraintTimeline_create(__VA_ARGS__)
  354. #define TransformConstraintTimeline_setFrame(...) spTransformConstraintTimeline_setFrame(__VA_ARGS__)
  355. #endif
  356. /**/
  357. static const int PATHCONSTRAINTPOSITION_ENTRIES = 2;
  358. typedef struct spPathConstraintPositionTimeline {
  359. spCurveTimeline super;
  360. int const framesCount;
  361. float* const frames; /* time, rotate mix, translate mix, scale mix, shear mix, ... */
  362. int pathConstraintIndex;
  363. #ifdef __cplusplus
  364. spPathConstraintPositionTimeline() :
  365. super(),
  366. framesCount(0),
  367. frames(0),
  368. pathConstraintIndex(0) {
  369. }
  370. #endif
  371. } spPathConstraintPositionTimeline;
  372. spPathConstraintPositionTimeline* spPathConstraintPositionTimeline_create (int framesCount);
  373. void spPathConstraintPositionTimeline_setFrame (spPathConstraintPositionTimeline* self, int frameIndex, float time, float value);
  374. #ifdef SPINE_SHORT_NAMES
  375. typedef spPathConstraintPositionTimeline PathConstraintPositionTimeline;
  376. #define PathConstraintPositionTimeline_create(...) spPathConstraintPositionTimeline_create(__VA_ARGS__)
  377. #define PathConstraintPositionTimeline_setFrame(...) spPathConstraintPositionTimeline_setFrame(__VA_ARGS__)
  378. #endif
  379. /**/
  380. static const int PATHCONSTRAINTSPACING_ENTRIES = 2;
  381. typedef struct spPathConstraintSpacingTimeline {
  382. spCurveTimeline super;
  383. int const framesCount;
  384. float* const frames; /* time, rotate mix, translate mix, scale mix, shear mix, ... */
  385. int pathConstraintIndex;
  386. #ifdef __cplusplus
  387. spPathConstraintSpacingTimeline() :
  388. super(),
  389. framesCount(0),
  390. frames(0),
  391. pathConstraintIndex(0) {
  392. }
  393. #endif
  394. } spPathConstraintSpacingTimeline;
  395. spPathConstraintSpacingTimeline* spPathConstraintSpacingTimeline_create (int framesCount);
  396. void spPathConstraintSpacingTimeline_setFrame (spPathConstraintSpacingTimeline* self, int frameIndex, float time, float value);
  397. #ifdef SPINE_SHORT_NAMES
  398. typedef spPathConstraintSpacingTimeline PathConstraintSpacingTimeline;
  399. #define PathConstraintSpacingTimeline_create(...) spPathConstraintSpacingTimeline_create(__VA_ARGS__)
  400. #define PathConstraintSpacingTimeline_setFrame(...) spPathConstraintSpacingTimeline_setFrame(__VA_ARGS__)
  401. #endif
  402. /**/
  403. static const int PATHCONSTRAINTMIX_ENTRIES = 3;
  404. typedef struct spPathConstraintMixTimeline {
  405. spCurveTimeline super;
  406. int const framesCount;
  407. float* const frames; /* time, rotate mix, translate mix, scale mix, shear mix, ... */
  408. int pathConstraintIndex;
  409. #ifdef __cplusplus
  410. spPathConstraintMixTimeline() :
  411. super(),
  412. framesCount(0),
  413. frames(0),
  414. pathConstraintIndex(0) {
  415. }
  416. #endif
  417. } spPathConstraintMixTimeline;
  418. spPathConstraintMixTimeline* spPathConstraintMixTimeline_create (int framesCount);
  419. void spPathConstraintMixTimeline_setFrame (spPathConstraintMixTimeline* self, int frameIndex, float time, float rotateMix, float translateMix);
  420. #ifdef SPINE_SHORT_NAMES
  421. typedef spPathConstraintMixTimeline PathConstraintMixTimeline;
  422. #define PathConstraintMixTimeline_create(...) spPathConstraintMixTimeline_create(__VA_ARGS__)
  423. #define PathConstraintMixTimeline_setFrame(...) spPathConstraintMixTimeline_setFrame(__VA_ARGS__)
  424. #endif
  425. /**/
  426. #ifdef __cplusplus
  427. }
  428. #endif
  429. #endif /* SPINE_ANIMATION_H_ */