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

/brlcad/branches/STABLE/src/anim/anim_keyread.c

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git
C | 167 lines | 92 code | 26 blank | 49 comment | 23 complexity | 5a99df015a7d1ed9312abbab11fa2f08 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. * BRL-CAD
  3. *
  4. * Copyright (c) 1993-2012 United States Government as represented by
  5. * the U.S. Army Research Laboratory.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * version 2.1 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this file; see the file named COPYING for more
  18. * information.
  19. *
  20. */
  21. /** @file anim_keyread.c
  22. *
  23. * Convert an list of mged-style 'savekey' keyframes into an animation
  24. * table
  25. *
  26. * The output table specifies the orientation in one of three ways:
  27. *
  28. * default - quaternions in the order x, y, z, w.
  29. *
  30. * -z option - Eulers angles, in the order xyz. The model axes are
  31. * considered to be rotated about the camera's z, y, and x axes (in
  32. * that order).
  33. *
  34. * -y option - Eulers angles in the form yaw, pitch, roll.
  35. *
  36. * This is more or less a special case of anim_orient.c
  37. *
  38. */
  39. #include "common.h"
  40. #include <stdio.h>
  41. #include <math.h>
  42. #include "bu.h"
  43. #include "bn.h"
  44. #include "vmath.h"
  45. #include "anim.h"
  46. #define OPT_STR "yzqr"
  47. #define YPR 0
  48. #define XYZ 1
  49. #define QUATERNION 2
  50. #define DEGREES 0
  51. #define RADIANS 1
  52. #define NORMAL 0
  53. #define ERROR1 1
  54. #define ERROR2 2
  55. int mode;
  56. int units;
  57. int
  58. get_args(int argc, char **argv)
  59. {
  60. int c;
  61. mode = QUATERNION; /* default */
  62. units = DEGREES;
  63. while ((c=bu_getopt(argc, argv, OPT_STR)) != -1) {
  64. switch (c) {
  65. case 'y':
  66. mode = YPR;
  67. break;
  68. case 'z':
  69. mode = XYZ;
  70. break;
  71. case 'q':
  72. mode = QUATERNION;
  73. break;
  74. case 'r':
  75. units = RADIANS;
  76. break;
  77. default:
  78. fprintf(stderr, "Unknown option: -%c\n", c);
  79. return 0;
  80. }
  81. }
  82. return 1;
  83. }
  84. int
  85. main(int argc, char *argv[])
  86. {
  87. int c;
  88. fastf_t time, viewsize;
  89. int count;
  90. fastf_t eyept[3] = {0.0}, viewrot[16] = {0.0}, angle[3] = {0.0}, quat[4] = {0.0};
  91. if (!get_args(argc, argv))
  92. fprintf(stderr, "anim_keyread: get_args error");
  93. while (!feof(stdin)) {
  94. /* read one keyframe */
  95. count = 0;
  96. count += scanf("%lf", &time);
  97. count += scanf("%lf", &viewsize);
  98. count += scanf("%lf %lf %lf", eyept, eyept+1, eyept+2);
  99. /* read in transposed matrix */
  100. count += scanf("%lf %lf %lf %lf", viewrot+0, viewrot+4, viewrot+8, viewrot+12);
  101. count += scanf("%lf %lf %lf %lf", viewrot+1, viewrot+5, viewrot+9, viewrot+13);
  102. count += scanf("%lf %lf %lf %lf", viewrot+2, viewrot+6, viewrot+10, viewrot+14);
  103. count += scanf("%lf %lf %lf %lf", viewrot+3, viewrot+7, viewrot+11, viewrot+15);
  104. if (feof(stdin) || count != 21)
  105. break;
  106. printf("%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t", time, viewsize, eyept[0], eyept[1], eyept[2]);
  107. if (mode==YPR) {
  108. anim_v_unpermute(viewrot);
  109. c = anim_mat2ypr(viewrot, angle);
  110. if (c==ERROR1)
  111. fprintf(stderr, "Warning: yaw and roll arbitrarily defined at time = %f.\n", time);
  112. else if (c==ERROR2)
  113. fprintf(stderr, "Keyread: can't interpret matrix at time = %f.\n", time);
  114. if (units == DEGREES)
  115. VSCALE(angle, angle, RAD2DEG);
  116. printf("%.10g\t%.10g\t%.10g\n", angle[0], angle[1], angle[2]);
  117. } else if (mode==XYZ) {
  118. c = anim_mat2zyx(viewrot, angle);
  119. if (c==ERROR1)
  120. fprintf(stderr, "Warning: x and z rotations arbitrarily defined at time = %f.\n", time);
  121. else if (c==ERROR2)
  122. fprintf(stderr, "Keyread: can't interpret matrix at time = %f\n.", time);
  123. if (units == DEGREES)
  124. VSCALE(angle, angle, RAD2DEG);
  125. printf("%.10g\t%.10g\t%.10g\n", angle[X], angle[Y], angle[Z]);
  126. } else if (mode==QUATERNION) {
  127. anim_mat2quat(quat, viewrot);
  128. printf("%.10g\t%.10g\t%.10g\t%.10g\n", quat[X], quat[Y], quat[Z], quat[W]);
  129. }
  130. }
  131. return 0;
  132. }
  133. /*
  134. * Local Variables:
  135. * mode: C
  136. * tab-width: 8
  137. * indent-tabs-mode: t
  138. * c-file-style: "stroustrup"
  139. * End:
  140. * ex: shiftwidth=4 tabstop=8
  141. */