btMultiBodyLink.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_MULTIBODY_LINK_H
  14. #define BT_MULTIBODY_LINK_H
  15. #include "bullet/LinearMath/btQuaternion.h"
  16. #include "bullet/LinearMath/btVector3.h"
  17. #include "bullet/BulletCollision//CollisionDispatch/btCollisionObject.h"
  18. enum btMultiBodyLinkFlags
  19. {
  20. BT_MULTIBODYLINKFLAGS_DISABLE_PARENT_COLLISION = 1
  21. };
  22. //
  23. // Link struct
  24. //
  25. struct btMultibodyLink
  26. {
  27. BT_DECLARE_ALIGNED_ALLOCATOR();
  28. btScalar joint_pos; // qi
  29. btScalar mass; // mass of link
  30. btVector3 inertia; // inertia of link (local frame; diagonal)
  31. int parent; // index of the parent link (assumed to be < index of this link), or -1 if parent is the base link.
  32. btQuaternion zero_rot_parent_to_this; // rotates vectors in parent-frame to vectors in local-frame (when q=0). constant.
  33. // "axis" = spatial joint axis (Mirtich Defn 9 p104). (expressed in local frame.) constant.
  34. // for prismatic: axis_top = zero;
  35. // axis_bottom = unit vector along the joint axis.
  36. // for revolute: axis_top = unit vector along the rotation axis (u);
  37. // axis_bottom = u cross d_vector.
  38. btVector3 axis_top;
  39. btVector3 axis_bottom;
  40. btVector3 d_vector; // vector from the inboard joint pos to this link's COM. (local frame.) constant. set for revolute joints only.
  41. // e_vector is constant, but depends on the joint type
  42. // prismatic: vector from COM of parent to COM of this link, WHEN Q = 0. (local frame.)
  43. // revolute: vector from parent's COM to the pivot point, in PARENT's frame.
  44. btVector3 e_vector;
  45. bool is_revolute; // true = revolute, false = prismatic
  46. btQuaternion cached_rot_parent_to_this; // rotates vectors in parent frame to vectors in local frame
  47. btVector3 cached_r_vector; // vector from COM of parent to COM of this link, in local frame.
  48. btVector3 applied_force; // In WORLD frame
  49. btVector3 applied_torque; // In WORLD frame
  50. btScalar joint_torque;
  51. class btMultiBodyLinkCollider* m_collider;
  52. int m_flags;
  53. // ctor: set some sensible defaults
  54. btMultibodyLink()
  55. : joint_pos(0),
  56. mass(1),
  57. parent(-1),
  58. zero_rot_parent_to_this(1, 0, 0, 0),
  59. is_revolute(false),
  60. cached_rot_parent_to_this(1, 0, 0, 0),
  61. joint_torque(0),
  62. m_collider(0),
  63. m_flags(0)
  64. {
  65. inertia.setValue(1, 1, 1);
  66. axis_top.setValue(0, 0, 0);
  67. axis_bottom.setValue(1, 0, 0);
  68. d_vector.setValue(0, 0, 0);
  69. e_vector.setValue(0, 0, 0);
  70. cached_r_vector.setValue(0, 0, 0);
  71. applied_force.setValue( 0, 0, 0);
  72. applied_torque.setValue(0, 0, 0);
  73. }
  74. // routine to update cached_rot_parent_to_this and cached_r_vector
  75. void updateCache()
  76. {
  77. if (is_revolute)
  78. {
  79. cached_rot_parent_to_this = btQuaternion(axis_top,-joint_pos) * zero_rot_parent_to_this;
  80. cached_r_vector = d_vector + quatRotate(cached_rot_parent_to_this,e_vector);
  81. } else
  82. {
  83. // cached_rot_parent_to_this never changes, so no need to update
  84. cached_r_vector = e_vector + joint_pos * axis_bottom;
  85. }
  86. }
  87. };
  88. #endif //BT_MULTIBODY_LINK_H