Keyframe.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /* Keyframovy animacni modul
  2. */
  3. #ifndef __KEYFRAME_H
  4. #define __KEYFRAME_H
  5. #define TRIDA_A 1 // incoming case
  6. #define TRIDA_B -1 // outgoing case
  7. #define TRIDA_LOOP 2 // loop animace
  8. void dbg_print_matrix(GLMATRIX * m);
  9. void dbg_print_track_uhel(TRACK_INFO * p_track);
  10. void dbg_print_track_quaternion(TRACK_INFO * p_track);
  11. void dbg_print_track_abs(TRACK_INFO * p_track);
  12. void dbg_print_track_abs_uhel(TRACK_INFO * p_track);
  13. void kprint_matrix(GLMATRIX * m);
  14. void key_pivot_sub(EDIT_OBJEKT * p_obj, BOD * p_pivot);
  15. void key_tri_to_matrix_zero(GLMATRIX * p_m, HIERARCHY_TRACK_INFO * p_track);
  16. void key_root_to_zero(HIERARCHY_ROOT * p_root);
  17. void key_root_to_matrix(HIERARCHY_ROOT * p_root, int time, GLMATRIX * p_otec);
  18. TRACK_INFO *key_track_vyrob(int poskey, int rotkey, int scalekey);
  19. HIERARCHY_ROOT *key_root_vyrob_indir(EDIT_KONTEJNER * p_kont,
  20. HIERARCHY_ROOT * p_root);
  21. HIERARCHY_TRACK_INFO *key_tri_vyrob_indir(HIERARCHY_TRACK_INFO * p_hir,
  22. int poskey, int rotkey, int scalekey);
  23. HIERARCHY_TRACK_INFO *key_tri_vyrob_un_indir(void);
  24. HIERARCHY_TRACK_INFO *key_tri_vyrob(int poskey, int rotkey, int scalekey);
  25. HIERARCHY_TRACK_INFO *key_track_to_tri(TRACK_INFO * p_track);
  26. BOD *key_position_tangent(HIERARCHY_TRACK_INFO * p_track, int kn, int trida,
  27. BOD * p_tn);
  28. inline QUAT *key_rotkey_to_quat(ROTKEY * p_rot, QUAT * p_q);
  29. void key_zrus_track(TRACK_INFO ** p_track);
  30. void key_tri_child_pridej(HIERARCHY_TRACK_INFO * p_root,
  31. HIERARCHY_TRACK_INFO * p_child);
  32. void key_root_child_pridej(HIERARCHY_ROOT * p_root,
  33. HIERARCHY_TRACK_INFO * p_child);
  34. void key_root_to_root_indir(EDIT_KONTEJNER * p_kont, HIERARCHY_ROOT * p_cil,
  35. HIERARCHY_ROOT * p_src);
  36. void key_root_to_sim_indir(EDIT_KONTEJNER * p_kont, HIERARCHY_SIM * p_sim,
  37. HIERARCHY_ROOT * p_root, int float_scale);
  38. void key_kontejner_reanimuj(EDIT_KONTEJNER * p_kont, HIERARCHY_ROOT * p_root);
  39. void key_kontejner_reanimuj_matrix(EDIT_KONTEJNER * p_kont, GLMATRIX * p_m);
  40. void key_sim_to_sim_indir(SIMPLE_TRACK_INFO * p_dest,
  41. SIMPLE_TRACK_INFO * p_src);
  42. void key_sim_animuj_strom(SIMPLE_TRACK_INFO * p_sim, int time,
  43. GLMATRIX * p_otec);
  44. SIMPLE_TRACK_INFO *key_sim_vyrob_indir(SIMPLE_TRACK_INFO * p_sim,
  45. int framenum);
  46. SIMPLE_TRACK_INFO *key_tri_to_sim_indir(HIERARCHY_TRACK_INFO * p_track,
  47. SIMPLE_TRACK_INFO * p_sim, int loop, int float_scale);
  48. void key_sim_uloz(SIMPLE_TRACK_INFO * p_sim, char *p_file, char *p_dir);
  49. int key_sim_nahraj(char *p_subdir, SIMPLE_TRACK_INFO * p_sim,
  50. char *p_file, char *p_dir, int linear);
  51. GLMATRIX *key_sim_to_matrix(SIMPLE_TRACK_INFO * p_sim, int time,
  52. GLMATRIX * p_m);
  53. GLMATRIX *key_sim_to_matrix_param(SIMPLE_TRACK_INFO * p_sim, int time,
  54. GLMATRIX * p_m, BOD * p_pos, QUAT * p_quat, BOD * p_scale);
  55. void key_sim_root_to_matrix(EDIT_KONTEJNER * p_kont, HIERARCHY_SIM * p_sim,
  56. int time, GLMATRIX * p_m);
  57. void key_mesh_reanimuj(GAME_MESH_OLD * p_mesh, int time, GLMATRIX * p_top);
  58. void key_kan_to_kamera(KAMERA * p_kam, KAMERA_TRACK_INFO * p_track, int time);
  59. int key_je_frame_klic(KEY_POINT_BRS * p_list, int klicu, dword frame);
  60. int key_je_time_klic(KEY_POINT_BRS * p_list, int klicu, dword time);
  61. void key_kontejner_retransformuj(EDIT_KONTEJNER * p_kont_top);
  62. void key_kontejner_recalc_normal_anim(EDIT_KONTEJNER * p_kont);
  63. void key_kont_updatuj_flagy(EDIT_KONTEJNER * p_kont);
  64. void key_sim_animuj_strom_pivoty(SIMPLE_TRACK_INFO * p_sim, int time,
  65. GLMATRIX * p_otec);
  66. void key_kontejner_sim_reanimuj_pivoty(EDIT_KONTEJNER * p_kont);
  67. int key_track_klic_vloz(byte ** p_hodnoty, KEY_POINT_BRS ** p_skeys,
  68. int keynum, int size_of_hodnota, byte * p_new_hodnota,
  69. KEY_POINT_BRS * p_new_keys);
  70. int key_track_klic_vloz_auto(byte ** p_hodnoty, KEY_POINT_BRS ** p_skeys,
  71. int keynum, int size_of_hodnota, byte * p_new_hodnota,
  72. KEY_POINT_BRS * p_new_keys);
  73. int key_track_klic_smaz(byte ** p_hodnoty, KEY_POINT_BRS ** p_skeys,
  74. int *p_keynum, int size_of_hodnota, dword del_time);
  75. int key_kamera_vyrob_indir(KAMERA_TRACK_INFO * p_track, int pos_keys,
  76. int trg_keys, int roll_keys, int fov_keys, int quat_keys);
  77. int key_kamera_uloz(KAMERA_TRACK_INFO * p_track, char *p_jmeno_kamery,
  78. char *p_jmeno_anim, char *p_file, char *p_dir);
  79. int key_kamera_nahraj(KAMERA_TRACK_INFO * p_track, char *p_jmeno_kamery,
  80. char *p_jmeno_anim, char *p_subdir, char *p_file, char *p_dir);
  81. void key_kamera_zrus_indir(KAMERA_TRACK_INFO * p_track);
  82. int key_kamera_track_cti(KAMERA_TRACK_INFO * p_track, BOD * p_p, BOD * p_t,
  83. float *p_roll, float *p_fov);
  84. float key_track_interpolace_float(float *p_vysl, float *p_body,
  85. KEY_POINT_BRS * p_keys, int time, int endtime, int keynum, int loop);
  86. BOD *key_track_interpolace_bod(BOD * p_vysl, BOD * p_body,
  87. KEY_POINT_BRS * p_keys, int time, int endtime, int keynum, int loop);
  88. QUAT *key_track_interpolace_quat(QUAT * p_quat, QUAT * p_at,
  89. KEY_POINT_BRS * p_rkeys, int time, int endtime, int keynum, int loop);
  90. WBOD *key_track_interpolace_wbod(WBOD * p_vysl, WBOD * p_body,
  91. KEY_POINT_BRS * p_keys, int time, int endtime, int keynum, int loop);
  92. float key_track_interpolace_float_linear(float *p_vysl, float *p_body,
  93. KEY_POINT_BRS * p_keys, int time, int endtime, int keynum, int loop);
  94. BOD *key_track_interpolace_bod_linear(BOD * p_vysl, BOD * p_body,
  95. KEY_POINT_BRS * p_keys, int time, int endtime, int keynum, int loop);
  96. QUAT *key_track_interpolace_quat_linear(QUAT * p_quat, QUAT * p_at,
  97. KEY_POINT_BRS * p_rkeys, int time, int endtime, int keynum, int loop);
  98. WBOD *key_track_interpolace_wbod_linear(WBOD * p_vysl, WBOD * p_body,
  99. KEY_POINT_BRS * p_keys, int time, int endtime, int keynum, int loop);
  100. ANIM_TEXT *key_vyrob_material_animace(int poskey, int rotkey, int scalekey,
  101. int pivotkey);
  102. ANIM_TEXT *key_kopiruj_material_animace(ANIM_TEXT * p_src);
  103. void key_zrus_material_animace(ANIM_TEXT ** p_mat);
  104. void key_sim_to_text_matrix(ANIM_TEXT * p_text, int time, GLMATRIX * p_ttext);
  105. void key_mat_to_text_matrix(GLMATRIX * p_ttext, BOD * p_pos, float uhel,
  106. BOD * p_scale, BOD * p_pivot);
  107. ANIM_TEXT *key_text_nahraj(char *p_file, char *p_dir);
  108. int key_text_uloz(ANIM_TEXT * p_track, char *p_file, char *p_dir);
  109. void key_sim_zrus_vnitrek(SIMPLE_TRACK_INFO * p_sim);
  110. void key_sim_root_zrus(HIERARCHY_SIM * p_sim);
  111. void key_sim_zrus(SIMPLE_TRACK_INFO * p_sim);
  112. void key_tri_calc_absolutne(TRACK_INFO * p_track, QUAT * p_puvodni);
  113. void key_sim_root_to_sim_root_indir(EDIT_KONTEJNER * p_kont,
  114. HIERARCHY_SIM * p_cil, HIERARCHY_SIM * p_src);
  115. void key_sim_dopln_matrix_kont(EDIT_KONTEJNER * p_kont,
  116. HIERARCHY_SIM * p_src);
  117. void key_sim_root_to_sim_indir(HIERARCHY_SIM * p_root,
  118. SIMPLE_TRACK_INFO * p_sim);
  119. void key_kontejner_sim_reanimuj(EDIT_KONTEJNER * p_kont);
  120. void key_sim_dopln_matrix_mesh(GAME_MESH_OLD * p_mesh,
  121. SIMPLE_TRACK_INFO * p_sim);
  122. int key_sim_nahraj_extended(EDIT_KONTEJNER * p_kont, int cislo_anim,
  123. char *p_file, char *p_dir);
  124. void key_sim_root_vloz_pivoty_do_animace(EDIT_KONTEJNER * p_kont,
  125. HIERARCHY_SIM * p_root);
  126. void key_sim_root_vloz_pivoty_do_animace_kont(EDIT_KONTEJNER * p_kont);
  127. void key_mesh_transformuj_obalky(GAME_MESH_OLD * p_mesh, GLMATRIX * p_mat);
  128. void key_mesh_transformuj_obalky_keyframe(GAME_MESH_OLD * p_mesh,
  129. GLMATRIX * p_mat);
  130. //void key_mesh_calc_global_obalku(GAME_MESH_OLD *p_mesh);
  131. inline void key_mesh_recalc_normal_anim(GAME_MESH_OLD * p_mesh);
  132. void key_sim_calc_absolutne(SIMPLE_TRACK_INFO * p_sim);
  133. #define SIM_KONST 50.0f //delici kostanta casu pro sim animace
  134. #define SIM_KONSTI 50 //delici kostanta casu pro sim animace
  135. #define ROOT_NODE 0xffff
  136. // 20 framu/sec, 1 frame = 1 klic
  137. // framenum = keynum
  138. /*
  139. start - cas ktery se ma preskocit
  140. stop - cas konce (kdy se to konci)
  141. time_start - predpocitany absolutni cas startu animace
  142. time_stop - predpocitani absolutni cas konce animace
  143. time_delka - predpocitana delka animace
  144. time - relativni cas animace (0..delka)
  145. */
  146. /* Prepocitava start/stop na casy start/stop animace
  147. */
  148. inline void calc_time(dword framenum, dword next_time, dword start,
  149. dword stop, dword * pstart, dword * pstop, dword * time_start,
  150. dword * time_stop, dword * time_delka)
  151. {
  152. *pstart = start;
  153. *pstop = stop;
  154. *time_delka = !stop ? (framenum - 1) * SIM_KONSTI : stop;
  155. *time_start = next_time - start;
  156. *time_stop = *time_start + *time_delka;
  157. }
  158. inline void calc_time_bez_stop(dword framenum, dword next_time, dword pstart,
  159. dword pstop, dword * p_time_start, dword * p_time_stop,
  160. dword * p_time_delka)
  161. {
  162. *p_time_delka = !(pstop) ? (framenum - 1) * SIM_KONSTI : pstop;
  163. *p_time_start = next_time - pstart;
  164. *p_time_stop = *p_time_start + *p_time_delka;
  165. }
  166. inline void calc_time_end(dword endtime,
  167. dword next_time,
  168. dword start,
  169. dword stop,
  170. dword * p_pstart,
  171. dword * p_pstop,
  172. dword * p_time_start, dword * p_time_stop, dword * p_time_delka)
  173. {
  174. *p_pstart = start * SIM_KONSTI;
  175. *p_pstop = stop * SIM_KONSTI;
  176. *p_time_delka = !(*p_pstop) ? endtime : *p_pstop;
  177. *p_time_start = next_time - *p_pstart;
  178. *p_time_stop = *p_time_start + *p_time_delka;
  179. }
  180. /*
  181. int next_time = p_ber->TimeEndLastFrame;
  182. if((konec = (next_time > p_kam->time_stop))) {
  183. calc_time_loop(next_time,
  184. p_kam->start,
  185. p_kam->time_start,
  186. p_kam->time_stop,
  187. p_kam->time_delka,
  188. p_kam->time);
  189. */
  190. /* Vypocet casu do dalsi smycky
  191. start - start cas animace
  192. next_time -
  193. */
  194. inline void calc_time_loop(dword next_time,
  195. dword start,
  196. dword * p_time_start,
  197. dword * p_time_stop, dword * p_time_delka, dword * p_time)
  198. {
  199. *p_time_start = *p_time_stop - start;
  200. *p_time = next_time - *p_time_start;
  201. if (*p_time > 2 * (*p_time_delka)) { // pokud to je 2x pretocene, zacneme znova
  202. *p_time_start = next_time - start;
  203. *p_time = next_time - *p_time_start;
  204. }
  205. *p_time_stop = *p_time_start + *p_time_delka;
  206. }
  207. /*
  208. *p_time_start = *p_time_stop - start;
  209. *p_time_stop = *p_time_start + *p_time_delka;
  210. *p_time = next_time - *p_time_start;
  211. */
  212. inline int calc_time_akt(int next_time, int time_start)
  213. {
  214. return (next_time - time_start);
  215. }
  216. inline int calc_endtime(int framenum)
  217. {
  218. // Leave the -1 or there will be a slight pause between walking
  219. // animations. If `framenum' is 0, we have to return 0 because
  220. // otherwise we would return a negative number.
  221. return framenum ? ((framenum - 1) * SIM_KONSTI) : 0;
  222. }
  223. inline int calc_keynum(int endtime)
  224. {
  225. return ((endtime / SIM_KONSTI) + 1);
  226. }
  227. inline int calc_framenum(int endtime)
  228. {
  229. return ((endtime / SIM_KONSTI) + 1);
  230. }
  231. inline int endtime2framenum(int endtime)
  232. {
  233. return ((endtime / SIM_KONSTI) + 1);
  234. }
  235. inline int time2frame(int time)
  236. {
  237. return (time / SIM_KONSTI);
  238. }
  239. inline float frame2sec(int frame)
  240. {
  241. return (frame * 0.05f);
  242. }
  243. inline int frame2time(int frame)
  244. {
  245. return (frame * SIM_KONSTI);
  246. }
  247. inline float time2sec(int time)
  248. {
  249. return (time / 1000.0f);
  250. }
  251. inline void key_mesh_recalc_normal_anim(GAME_MESH_OLD * p_mesh)
  252. {
  253. BOD *p_vertex;
  254. BOD *p_vertex_norm;
  255. BOD n, up(0, 1, 0);
  256. int o, i, kflag, vr;
  257. float last, akt, num;
  258. kflag = p_mesh->p_data->kflag;
  259. if (kflag & KONT_NORMAL_ANIM) {
  260. vr = kflag & KONT_NORMAL_ANIM_POS;
  261. for (o = 0; o < p_mesh->objektu; o++) {
  262. if ((last = p_mesh->p_normal_scale_last[o]) == (akt =
  263. p_mesh->p_normal_scale[o]))
  264. continue;
  265. p_vertex = p_mesh->p_vertex_pos + p_mesh->objektstart[o];
  266. p_vertex_norm = p_mesh->p_vertex_norm + p_mesh->objektstart[o];
  267. num = p_mesh->objektnum[o];
  268. for (i = 0; i < num; i++, p_vertex++, p_vertex_norm++) {
  269. vektor_add(p_vertex, vektor_mult_skalar(p_vertex_norm, (last - akt),
  270. &n), p_vertex);
  271. if (vr) {
  272. vektor_add(p_vertex, vektor_mult_skalar(&up, (akt - last), &n),
  273. p_vertex);
  274. }
  275. }
  276. p_mesh->p_normal_scale_last[o] = akt;
  277. p_mesh->p_data->k2flag |= KONT2_UPDATE_POS;
  278. }
  279. }
  280. }
  281. JOINT_KEYS *key_kost_spline_vyrob(JOINT * p_joint);
  282. void key_kosti_updatuj_vertexy(EDIT_OBJEKT * p_obj,
  283. JOINT_ANIMACE * p_animace);
  284. void key_kosti_interpoluj(JOINT_ANIMACE * p_animace);
  285. void key_kosti_animuj(JOINT_ANIMACE * p_animace);
  286. void key_kosti_serad_klice(byte * p_hodnoty, KEY_POINT_BRS * p_skeys,
  287. int keynum, int size_of_hodnota);
  288. void key_kosti_stream_animuj_rec(JOINT_ANIMACE * p_anim, JOINT * p_joint,
  289. GLMATRIX * p_top, int time, int keynum);
  290. JOINT_ANIMACE *key_kosti_kopiruj(JOINT_ANIMACE * p_src);
  291. JOINT_ANIMACE *key_kosti_kopiruj_animace(JOINT_ANIMACE * p_prvni);
  292. JOINT *key_joint_vyrob(void);
  293. inline void key_kosti_reanimuj_kont(EDIT_KONTEJNER * p_kont)
  294. {
  295. EDIT_OBJEKT *p_obj;
  296. int i;
  297. if (p_kont->k2flag & KONT2_JOINT_ANIM) {
  298. for (i = 0; i < MAX_KONT_OBJEKTU; i++) {
  299. p_obj = p_kont->p_obj[i];
  300. if (p_obj && p_obj->p_joit_animace) {
  301. key_kosti_interpoluj(p_obj->p_joit_animace);
  302. key_kosti_updatuj_vertexy(p_obj, p_obj->p_joit_animace);
  303. }
  304. }
  305. }
  306. }
  307. void kprintf_matrix(GLMATRIX * m);
  308. inline void key_kosti_stream_animuj(JOINT_ANIMACE * p_animace)
  309. {
  310. if (p_animace) {
  311. key_kosti_stream_animuj_rec(p_animace, p_animace->p_child, NULL,
  312. p_animace->time, p_animace->framenum);
  313. *p_animace->p_k2flag |= KONT2_UPDATE_POS | KONT2_UPDATE_NORM;
  314. }
  315. }
  316. inline void key_track_quat_zkontroluj(QUAT * p_quat, int keynum)
  317. {
  318. int i;
  319. for (i = 0; i < keynum; i++) {
  320. if (p_quat[i].x == 0 && p_quat[i].y == 0 && p_quat[i].z == 0
  321. && p_quat[i].w == 0)
  322. p_quat[i].w = 1;
  323. }
  324. }
  325. #endif