PageRenderTime 28ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/brlcad/tags/rel-4-4/anim/anim_keyread.c

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git
C | 156 lines | 99 code | 23 blank | 34 comment | 20 complexity | 774d5ae97392d89a2ffb99fbe1857d68 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 _ 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 by the United States Army
  32. * in all countries except the USA. All rights reserved.
  33. */
  34. #include "conf.h"
  35. #include <stdio.h>
  36. #include <math.h>
  37. #include "machine.h"
  38. #include "vmath.h"
  39. #ifndef M_PI
  40. #define M_PI 3.14159265358979323846
  41. #endif
  42. #define YPR 0
  43. #define XYZ 1
  44. #define QUATERNION 2
  45. #define DEGREES 0
  46. #define RADIANS 1
  47. #define NORMAL 0
  48. #define ERROR1 1
  49. #define ERROR2 2
  50. #define DTOR M_PI/180.0
  51. #define RTOD 180.0/M_PI
  52. int mode;
  53. int units;
  54. extern int optind;
  55. extern char *optarg;
  56. main(argc,argv)
  57. int argc;
  58. char **argv;
  59. {
  60. int c;
  61. fastf_t time, viewsize;
  62. fastf_t eyept[3], viewrot[16], angle[3], quat[4];
  63. int mat2ypr(), mat2zyx(), mat2quat();
  64. if (!get_args(argc,argv))
  65. fprintf(stderr,"anim_keyread: get_args error");
  66. while (!feof(stdin)){ /* read one keyframe */
  67. scanf("%lf", &time);
  68. scanf("%lf", &viewsize);
  69. scanf("%lf %lf %lf", eyept, eyept+1, eyept+2);
  70. /* read in transposed matrix */
  71. scanf("%lf %lf %lf %lf", viewrot+0, viewrot+4, viewrot+8, viewrot+12);
  72. scanf("%lf %lf %lf %lf", viewrot+1, viewrot+5, viewrot+9, viewrot+13);
  73. scanf("%lf %lf %lf %lf", viewrot+2, viewrot+6, viewrot+10, viewrot+14);
  74. scanf("%lf %lf %lf %lf", viewrot+3, viewrot+7, viewrot+11, viewrot+15);
  75. if (feof(stdin)) break;
  76. printf("%f\t%f\t%f\t%f\t%f\t", time, viewsize,
  77. eyept[0], eyept[1], eyept[2]);
  78. if (mode==YPR) {
  79. un_v_permute(viewrot);
  80. c = mat2ypr(angle,viewrot);
  81. if (c==ERROR1)
  82. fprintf(stderr,"Warning: yaw and roll arbitrarily defined at time = %f.\n",time);
  83. else if (c==ERROR2)
  84. fprintf(stderr,"Keyread: can't interpret matrix at time = %f.\n",time);
  85. if (units == DEGREES)
  86. VSCALE(angle,angle,RTOD);
  87. printf("%f\t%f\t%f\n",angle[0],angle[1],angle[2]);
  88. }
  89. else if (mode==XYZ) {
  90. c = mat2zyx(angle,viewrot);
  91. if (c==ERROR1)
  92. fprintf(stderr,"Warning: x and z rotations arbitrarily defined at time = %f.\n",time);
  93. else if (c==ERROR2)
  94. fprintf(stderr,"Keyread: can't interpret matrix at time = %f\n.",time);
  95. if (units == DEGREES)
  96. VSCALE(angle,angle,RTOD);
  97. printf("%f\t%f\t%f\n",angle[X],angle[Y],angle[Z]);
  98. }
  99. else if (mode==QUATERNION){
  100. mat2quat(quat,viewrot);
  101. printf("%f\t%f\t%f\t%f\n",quat[X],quat[Y],quat[Z],quat[W]);
  102. }
  103. }
  104. }
  105. #define OPT_STR "yzqr"
  106. int get_args(argc,argv)
  107. int argc;
  108. char **argv;
  109. {
  110. int c;
  111. mode = QUATERNION; /* default */
  112. units = DEGREES;
  113. while ( (c=getopt(argc,argv,OPT_STR)) != EOF) {
  114. switch(c){
  115. case 'y':
  116. mode = YPR;
  117. break;
  118. case 'z':
  119. mode = XYZ;
  120. break;
  121. case 'q':
  122. mode = QUATERNION;
  123. break;
  124. case 'r':
  125. units = RADIANS;
  126. break;
  127. default:
  128. fprintf(stderr,"Unknown option: -%c\n",c);
  129. return(0);
  130. }
  131. }
  132. return(1);
  133. }