SimpleTreeCreator.cpp 1.8 KB

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