SimpleTreeCreator.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "SimpleTreeCreator.hpp"
  2. #include <cstdio>
  3. namespace btInverseDynamics {
  4. /// minimal "tree" (chain)
  5. SimpleTreeCreator::SimpleTreeCreator(int dim) : m_num_bodies(dim) {
  6. m_mass = 1.0;
  7. m_body_T_parent_ref(0, 0) = 1;
  8. m_body_T_parent_ref(0, 1) = 0;
  9. m_body_T_parent_ref(0, 2) = 0;
  10. m_body_T_parent_ref(1, 0) = 0;
  11. m_body_T_parent_ref(1, 1) = 1;
  12. m_body_T_parent_ref(1, 2) = 0;
  13. m_body_T_parent_ref(2, 0) = 0;
  14. m_body_T_parent_ref(2, 1) = 0;
  15. m_body_T_parent_ref(2, 2) = 1;
  16. m_parent_r_parent_body_ref(0) = 1.0;
  17. m_parent_r_parent_body_ref(1) = 0.0;
  18. m_parent_r_parent_body_ref(2) = 0.0;
  19. m_body_r_body_com(0) = 0.5;
  20. m_body_r_body_com(1) = 0.0;
  21. m_body_r_body_com(2) = 0.0;
  22. m_body_I_body(0, 0) = 1;
  23. m_body_I_body(0, 1) = 0;
  24. m_body_I_body(0, 2) = 0;
  25. m_body_I_body(1, 0) = 0;
  26. m_body_I_body(1, 1) = 1;
  27. m_body_I_body(1, 2) = 0;
  28. m_body_I_body(2, 0) = 0;
  29. m_body_I_body(2, 1) = 0;
  30. m_body_I_body(2, 2) = 1;
  31. m_axis(0) = 0;
  32. m_axis(1) = 0;
  33. m_axis(2) = 1;
  34. }
  35. int SimpleTreeCreator::getNumBodies(int* num_bodies) const {
  36. *num_bodies = m_num_bodies;
  37. return 0;
  38. }
  39. int SimpleTreeCreator::getBody(const int body_index, int* parent_index, JointType* joint_type,
  40. vec3* parent_r_parent_body_ref, mat33* body_T_parent_ref,
  41. vec3* body_axis_of_motion, idScalar* mass, vec3* body_r_body_com,
  42. mat33* body_I_body, int* user_int, void** user_ptr) const {
  43. *parent_index = body_index - 1;
  44. if (body_index % 2) {
  45. *joint_type = PRISMATIC;
  46. } else {
  47. *joint_type = REVOLUTE;
  48. }
  49. *parent_r_parent_body_ref = m_parent_r_parent_body_ref;
  50. if (0 == body_index) {
  51. (*parent_r_parent_body_ref)(2) = 1.0;
  52. }
  53. *body_T_parent_ref = m_body_T_parent_ref;
  54. *body_axis_of_motion = m_axis;
  55. *mass = m_mass;
  56. *body_r_body_com = m_body_r_body_com;
  57. *body_I_body = m_body_I_body;
  58. *user_int = 0;
  59. *user_ptr = 0;
  60. return 0;
  61. }
  62. }