PageRenderTime 27ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/brlcad/tags/rel-5-0-beta/anim/anim_script.c

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git
C | 257 lines | 198 code | 25 blank | 34 comment | 31 complexity | 518dedc01654e01b954d0ddef948e8ce MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, LGPL-2.1, Apache-2.0, AGPL-3.0, LGPL-3.0, GPL-3.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, 0BSD, BSD-3-Clause
  1. /* A N I M _ S C R I P T . C
  2. *
  3. * Turn an animation table into an animation script suitable for
  4. * use by rt. Anim_script.c makes a script for one object at a time (or the
  5. * virtual camera). Some of the available options include rotation
  6. * only, translation only, automatic steering, and specifying reference
  7. * coordinates.
  8. *
  9. * Author -
  10. * Carl J. Nuzman
  11. *
  12. * Source -
  13. * The U. S. Army Research Laboratory
  14. * Aberdeen Proving Ground, Maryland 21005-5068 USA
  15. *
  16. * Distribution Notice -
  17. * Re-distribution of this software is restricted, as described in
  18. * your "Statement of Terms and Conditions for the Release of
  19. * The BRL-CAD Pacakge" agreement.
  20. *
  21. * Copyright Notice -
  22. * This software is Copyright (C) 1993 by the United States Army
  23. * in all countries except the USA. All rights reserved.
  24. */
  25. #include "conf.h"
  26. #include <math.h>
  27. #include <stdio.h>
  28. #include "machine.h"
  29. #include "vmath.h"
  30. #include "anim.h"
  31. #ifndef M_PI
  32. #define M_PI 3.14159265358979323846
  33. #endif
  34. extern int bu_optind;
  35. extern char *bu_optarg;
  36. /* info from command line args */
  37. int relative_a, relative_c, axes, translate, quaternion, rotate;/*flags*/
  38. int steer, view, readview, permute; /* flags*/
  39. int first_frame;
  40. fastf_t viewsize;
  41. vect_t centroid, rcentroid, front;
  42. mat_t m_axes, m_rev_axes; /* rotational analogue of centroid */
  43. char mat_cmd[10]; /* default is lmul */
  44. main(argc,argv)
  45. int argc;
  46. char **argv;
  47. {
  48. void anim_dx_y_z2mat(), anim_add_trans();
  49. fastf_t yaw, pitch, roll;
  50. vect_t point, zero;
  51. quat_t quat;
  52. mat_t a, m_x;
  53. int val, go, frame, last_steer;
  54. frame=last_steer=go=view=relative_a=relative_c=axes=0;
  55. VSETALL(centroid,0);
  56. VSETALL(rcentroid,0);
  57. VSETALL(front,0);
  58. VSETALL(point,0);
  59. VSETALL(zero,0);
  60. yaw = pitch = roll = 0.0;
  61. MAT_IDN(m_axes);
  62. MAT_IDN(m_rev_axes);
  63. MAT_IDN(a);
  64. if (!get_args(argc,argv))
  65. fprintf(stderr,"anim_script: Get_args error\n");
  66. frame = (steer) ? first_frame -1 : first_frame;
  67. if (view && (viewsize > 0.0))
  68. printf("viewsize %.10g;\n", viewsize);
  69. while (1) {
  70. /* read one line of table */
  71. val = scanf("%*f"); /*ignore time */
  72. if (readview)
  73. scanf("%lf",&viewsize);
  74. if(translate)
  75. val=scanf("%lf %lf %lf", point, point+1, point+2);
  76. if(rotate&&quaternion){
  77. val = scanf("%lf %lf %lf %lf", quat,quat+1,quat+2,quat+3);
  78. val -= 1;
  79. } else if (rotate) {
  80. val=scanf("%lf %lf %lf",&yaw,&pitch,&roll);
  81. }
  82. if (val < 3){ /* ie. scanf not completely successful */
  83. /* with steering option, must go extra loop after end of file */
  84. if (steer && !last_steer)
  85. last_steer = 1;
  86. else break;
  87. }
  88. /* calculate basic rotation matrix a */
  89. if (steer)
  90. go = anim_steer_mat(a,point,last_steer); /* warning: point changed by anim_steer_mat */
  91. else if (quaternion) {
  92. anim_quat2mat(a,quat);
  93. go = 1;
  94. } else {
  95. anim_dx_y_z2mat(a,roll,-pitch,yaw);/* make ypr matrix */
  96. go = 1;
  97. }
  98. /* if input orientation (presumably from quaternion) was
  99. * designed to manipulate the view, first move the object
  100. * to the default object position */
  101. if (permute)
  102. anim_v_unpermute(a);
  103. /* make final matrix, including translation etc */
  104. if (axes){ /* add pre-rotation from original axes */
  105. mat_mul(m_x,a,m_rev_axes);
  106. MAT_MOVE(a,m_x);
  107. }
  108. anim_add_trans(a,point,rcentroid); /* add translation */
  109. if (axes && relative_a){ /* add post-rotation back to original axes */
  110. mat_mul(m_x,m_axes,a);
  111. MAT_MOVE(a,m_x);
  112. }
  113. if (relative_c)
  114. anim_add_trans(a,centroid,zero); /* final translation */
  115. /* print one frame of script */
  116. if (go && view){
  117. printf("start %d;\n", frame);
  118. printf("clean;\n");
  119. if (readview)
  120. printf("viewsize %.10g;\n", viewsize);
  121. printf("eye_pt %.10g %.10g %.10g;\n",a[3],a[7],a[11]);
  122. /* implicit anim_v_permute */
  123. printf("viewrot %.10g %.10g %.10g 0\n",-a[1],-a[5],-a[9]);
  124. printf("%.10g %.10g %.10g 0\n", a[2], a[6], a[10]);
  125. printf("%.10g %.10g %.10g 0\n", -a[0], -a[4],-a[8]);
  126. printf("0 0 0 1;\n");
  127. printf("end;\n");
  128. }
  129. else if (go){
  130. printf("start %d;\n", frame);
  131. printf("clean;\n");
  132. printf("anim %s matrix %s\n", *(argv+bu_optind), mat_cmd);
  133. anim_mat_print(stdout,a,1);
  134. printf("end;\n");
  135. }
  136. frame++;
  137. }
  138. }
  139. #define OPT_STR "a:b:c:d:f:m:pqrstv:"
  140. int get_args(argc,argv)
  141. int argc;
  142. char **argv;
  143. {
  144. int c, i, yes;
  145. double yaw,pch,rll;
  146. void anim_dx_y_z2mat(), anim_dz_y_x2mat();
  147. rotate = translate = 1; /* defaults */
  148. quaternion = permute = 0;
  149. strcpy(mat_cmd, "lmul");
  150. while ( (c=bu_getopt(argc,argv,OPT_STR)) != EOF) {
  151. i=0;
  152. switch(c){
  153. case 'a':
  154. bu_optind -= 1;
  155. sscanf(argv[bu_optind+(i++)],"%lf", &yaw );
  156. sscanf(argv[bu_optind+(i++)],"%lf", &pch );
  157. sscanf(argv[bu_optind+(i++)],"%lf", &rll );
  158. bu_optind += 3;
  159. anim_dx_y_z2mat(m_axes, rll, -pch, yaw);
  160. anim_dz_y_x2mat(m_rev_axes, -rll, pch, -yaw);
  161. axes = 1;
  162. relative_a = 1;
  163. break;
  164. case 'b':
  165. bu_optind -= 1;
  166. sscanf(argv[bu_optind+(i++)],"%lf", &yaw );
  167. sscanf(argv[bu_optind+(i++)],"%lf", &pch );
  168. sscanf(argv[bu_optind+(i++)],"%lf", &rll );
  169. bu_optind += 3;
  170. anim_dx_y_z2mat(m_axes, rll, -pch, yaw);
  171. anim_dz_y_x2mat(m_rev_axes, -rll, pch, -yaw);
  172. axes = 1;
  173. relative_a = 0;
  174. break;
  175. case 'c':
  176. bu_optind -= 1;
  177. sscanf(argv[bu_optind+(i++)],"%lf",centroid);
  178. sscanf(argv[bu_optind+(i++)],"%lf",centroid+1);
  179. sscanf(argv[bu_optind+(i++)],"%lf",centroid+2);
  180. bu_optind += 3;
  181. VREVERSE(rcentroid,centroid);
  182. relative_c = 1;
  183. break;
  184. case 'd':
  185. bu_optind -= 1;
  186. sscanf(argv[bu_optind+(i++)],"%lf",centroid);
  187. sscanf(argv[bu_optind+(i++)],"%lf",centroid+1);
  188. sscanf(argv[bu_optind+(i++)],"%lf",centroid+2);
  189. bu_optind += 3;
  190. VREVERSE(rcentroid,centroid);
  191. relative_c = 0;
  192. break;
  193. case 'f':
  194. sscanf(bu_optarg,"%d",&first_frame);
  195. break;
  196. case 'm':
  197. strncpy(mat_cmd,bu_optarg, 10);
  198. break;
  199. case 'p':
  200. permute = 1;
  201. break;
  202. case 'q':
  203. quaternion = 1;
  204. break;
  205. case 'r':
  206. rotate = 1;
  207. translate = 0;
  208. break;
  209. case 's':
  210. steer = 1;
  211. relative_a = 0;
  212. rotate = 0;
  213. translate = 1;
  214. break;
  215. case 't':
  216. translate = 1;
  217. rotate = 0;
  218. break;
  219. case 'v':
  220. yes = sscanf(bu_optarg,"%lf",&viewsize);
  221. if (!yes) viewsize = 0.0;
  222. if (viewsize < 0.0)
  223. readview = 1;
  224. view = 1;
  225. break;
  226. default:
  227. fprintf(stderr,"Unknown option: -%c\n",c);
  228. return(0);
  229. }
  230. }
  231. return(1);
  232. }