/brlcad/tags/rel-7-0/src/anim/anim_keyread.c

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git · C · 160 lines · 100 code · 26 blank · 34 comment · 21 complexity · baf4684f1f97d9ab6d416f9d6a18223a MD5 · raw file

  1. /* A N I M _ K E Y R E A D . C
  2. *
  3. * Convert an list of mged-style 'savekey' keyframes into an
  4. * animation table
  5. *
  6. * The output table specifies the orientation in one of three ways:
  7. *
  8. * default - quaternions in the order x, y, z, w.
  9. *
  10. * -z option - Eulers angles, in the order xyz. The model axes are
  11. * considered to be rotated about the camera's z, y, and
  12. * x axes (in that order).
  13. *
  14. * -y option - Eulers angles in the form yaw, pitch, roll.
  15. *
  16. * This is more or less a special case of anim_orient.c
  17. *
  18. * Author -
  19. * Carl J. Nuzman
  20. *
  21. * Source -
  22. * The U. S. Army Research Laboratory
  23. * Aberdeen Proving Ground, Maryland 21005-5068 USA
  24. *
  25. * Distribution Notice -
  26. * Re-distribution of this software is restricted, as described in
  27. * your "Statement of Terms and Conditions for the Release of
  28. * The BRL-CAD Pacakge" agreement.
  29. *
  30. * Copyright Notice -
  31. * This software is Copyright (C) 1993-2004 by the United States Army
  32. * in all countries except the USA. All rights reserved.
  33. */
  34. #include "common.h"
  35. #include <stdio.h>
  36. #include <math.h>
  37. #include "machine.h"
  38. #include "vmath.h"
  39. #include "bu.h"
  40. #ifndef M_PI
  41. #define M_PI 3.14159265358979323846
  42. #endif
  43. #define YPR 0
  44. #define XYZ 1
  45. #define QUATERNION 2
  46. #define DEGREES 0
  47. #define RADIANS 1
  48. #define NORMAL 0
  49. #define ERROR1 1
  50. #define ERROR2 2
  51. #define DTOR M_PI/180.0
  52. #define RTOD 180.0/M_PI
  53. int mode;
  54. int units;
  55. extern int bu_optind;
  56. extern char *bu_optarg;
  57. int get_args(int argc, char **argv);
  58. extern void anim_v_unpermute(fastf_t *);
  59. int
  60. main(int argc, char **argv)
  61. {
  62. int c;
  63. fastf_t time, viewsize;
  64. fastf_t eyept[3], viewrot[16], angle[3], quat[4];
  65. int anim_mat2ypr(fastf_t *, fastf_t *), anim_mat2zyx(const fastf_t *, fastf_t *), anim_mat2quat(fastf_t *, const fastf_t *);
  66. if (!get_args(argc,argv))
  67. fprintf(stderr,"anim_keyread: get_args error");
  68. while (!feof(stdin)){ /* read one keyframe */
  69. scanf("%lf", &time);
  70. scanf("%lf", &viewsize);
  71. scanf("%lf %lf %lf", eyept, eyept+1, eyept+2);
  72. /* read in transposed matrix */
  73. scanf("%lf %lf %lf %lf", viewrot+0, viewrot+4, viewrot+8, viewrot+12);
  74. scanf("%lf %lf %lf %lf", viewrot+1, viewrot+5, viewrot+9, viewrot+13);
  75. scanf("%lf %lf %lf %lf", viewrot+2, viewrot+6, viewrot+10, viewrot+14);
  76. scanf("%lf %lf %lf %lf", viewrot+3, viewrot+7, viewrot+11, viewrot+15);
  77. if (feof(stdin)) break;
  78. printf("%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t", time, viewsize,
  79. eyept[0], eyept[1], eyept[2]);
  80. if (mode==YPR) {
  81. anim_v_unpermute(viewrot);
  82. c = anim_mat2ypr(angle,viewrot);
  83. if (c==ERROR1)
  84. fprintf(stderr,"Warning: yaw and roll arbitrarily defined at time = %f.\n",time);
  85. else if (c==ERROR2)
  86. fprintf(stderr,"Keyread: can't interpret matrix at time = %f.\n",time);
  87. if (units == DEGREES)
  88. VSCALE(angle,angle,RTOD);
  89. printf("%.10g\t%.10g\t%.10g\n",angle[0],angle[1],angle[2]);
  90. }
  91. else if (mode==XYZ) {
  92. c = anim_mat2zyx(angle,viewrot);
  93. if (c==ERROR1)
  94. fprintf(stderr,"Warning: x and z rotations arbitrarily defined at time = %f.\n",time);
  95. else if (c==ERROR2)
  96. fprintf(stderr,"Keyread: can't interpret matrix at time = %f\n.",time);
  97. if (units == DEGREES)
  98. VSCALE(angle,angle,RTOD);
  99. printf("%.10g\t%.10g\t%.10g\n",angle[X],angle[Y],angle[Z]);
  100. }
  101. else if (mode==QUATERNION){
  102. anim_mat2quat(quat,viewrot);
  103. printf("%.10g\t%.10g\t%.10g\t%.10g\n",quat[X],quat[Y],quat[Z],quat[W]);
  104. }
  105. }
  106. return( 0 );
  107. }
  108. #define OPT_STR "yzqr"
  109. int get_args(int argc, char **argv)
  110. {
  111. int c;
  112. mode = QUATERNION; /* default */
  113. units = DEGREES;
  114. while ( (c=bu_getopt(argc,argv,OPT_STR)) != EOF) {
  115. switch(c){
  116. case 'y':
  117. mode = YPR;
  118. break;
  119. case 'z':
  120. mode = XYZ;
  121. break;
  122. case 'q':
  123. mode = QUATERNION;
  124. break;
  125. case 'r':
  126. units = RADIANS;
  127. break;
  128. default:
  129. fprintf(stderr,"Unknown option: -%c\n",c);
  130. return(0);
  131. }
  132. }
  133. return(1);
  134. }