2
0

MultiBodyTreeCreator.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "MultiBodyTreeCreator.hpp"
  2. namespace btInverseDynamics
  3. {
  4. MultiBodyTree* CreateMultiBodyTree(const MultiBodyTreeCreator& creator)
  5. {
  6. int num_bodies;
  7. int parent_index;
  8. JointType joint_type;
  9. vec3 body_r_parent_body_ref;
  10. mat33 body_R_parent_ref;
  11. vec3 body_axis_of_motion;
  12. idScalar mass;
  13. vec3 body_r_body_com;
  14. mat33 body_I_body;
  15. int user_int;
  16. void* user_ptr;
  17. MultiBodyTree* tree = new MultiBodyTree();
  18. if (0x0 == tree)
  19. {
  20. bt_id_error_message("cannot allocate tree\n");
  21. return 0x0;
  22. }
  23. // TODO: move to some policy argument
  24. tree->setAcceptInvalidMassParameters(false);
  25. // get number of bodies in the system
  26. if (-1 == creator.getNumBodies(&num_bodies))
  27. {
  28. bt_id_error_message("getting body indices\n");
  29. delete tree;
  30. return 0x0;
  31. }
  32. // get data for all bodies
  33. for (int index = 0; index < num_bodies; index++)
  34. {
  35. // get body parameters from user callbacks
  36. if (-1 ==
  37. creator.getBody(index, &parent_index, &joint_type, &body_r_parent_body_ref,
  38. &body_R_parent_ref, &body_axis_of_motion, &mass, &body_r_body_com,
  39. &body_I_body, &user_int, &user_ptr))
  40. {
  41. bt_id_error_message("getting data for body %d\n", index);
  42. delete tree;
  43. return 0x0;
  44. }
  45. // add body to system
  46. if (-1 ==
  47. tree->addBody(index, parent_index, joint_type, body_r_parent_body_ref,
  48. body_R_parent_ref, body_axis_of_motion, mass, body_r_body_com,
  49. body_I_body, user_int, user_ptr))
  50. {
  51. bt_id_error_message("adding body %d\n", index);
  52. delete tree;
  53. return 0x0;
  54. }
  55. }
  56. // finalize initialization
  57. if (-1 == tree->finalize())
  58. {
  59. bt_id_error_message("building system\n");
  60. delete tree;
  61. return 0x0;
  62. }
  63. return tree;
  64. }
  65. } // namespace btInverseDynamics