btMultiBodyDynamicsWorld.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_DYNAMICS_WORLD_H
  14. #define BT_MULTIBODY_DYNAMICS_WORLD_H
  15. #include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
  16. #define BT_USE_VIRTUAL_CLEARFORCES_AND_GRAVITY
  17. class btMultiBody;
  18. class btMultiBodyConstraint;
  19. class btMultiBodyConstraintSolver;
  20. struct MultiBodyInplaceSolverIslandCallback;
  21. ///The btMultiBodyDynamicsWorld adds Featherstone multi body dynamics to Bullet
  22. ///This implementation is still preliminary/experimental.
  23. class btMultiBodyDynamicsWorld : public btDiscreteDynamicsWorld
  24. {
  25. protected:
  26. btAlignedObjectArray<btMultiBody*> m_multiBodies;
  27. btAlignedObjectArray<btMultiBodyConstraint*> m_multiBodyConstraints;
  28. btAlignedObjectArray<btMultiBodyConstraint*> m_sortedMultiBodyConstraints;
  29. btMultiBodyConstraintSolver* m_multiBodyConstraintSolver;
  30. MultiBodyInplaceSolverIslandCallback* m_solverMultiBodyIslandCallback;
  31. //cached data to avoid memory allocations
  32. btAlignedObjectArray<btQuaternion> m_scratch_world_to_local;
  33. btAlignedObjectArray<btVector3> m_scratch_local_origin;
  34. btAlignedObjectArray<btQuaternion> m_scratch_world_to_local1;
  35. btAlignedObjectArray<btVector3> m_scratch_local_origin1;
  36. btAlignedObjectArray<btScalar> m_scratch_r;
  37. btAlignedObjectArray<btVector3> m_scratch_v;
  38. btAlignedObjectArray<btMatrix3x3> m_scratch_m;
  39. virtual void calculateSimulationIslands();
  40. virtual void updateActivationState(btScalar timeStep);
  41. virtual void solveConstraints(btContactSolverInfo& solverInfo);
  42. virtual void serializeMultiBodies(btSerializer* serializer);
  43. public:
  44. btMultiBodyDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btMultiBodyConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration);
  45. virtual ~btMultiBodyDynamicsWorld ();
  46. virtual void addMultiBody(btMultiBody* body, int group= btBroadphaseProxy::DefaultFilter, int mask=btBroadphaseProxy::AllFilter);
  47. virtual void removeMultiBody(btMultiBody* body);
  48. virtual int getNumMultibodies() const
  49. {
  50. return m_multiBodies.size();
  51. }
  52. btMultiBody* getMultiBody(int mbIndex)
  53. {
  54. return m_multiBodies[mbIndex];
  55. }
  56. const btMultiBody* getMultiBody(int mbIndex) const
  57. {
  58. return m_multiBodies[mbIndex];
  59. }
  60. virtual void addMultiBodyConstraint( btMultiBodyConstraint* constraint);
  61. virtual int getNumMultiBodyConstraints() const
  62. {
  63. return m_multiBodyConstraints.size();
  64. }
  65. virtual btMultiBodyConstraint* getMultiBodyConstraint( int constraintIndex)
  66. {
  67. return m_multiBodyConstraints[constraintIndex];
  68. }
  69. virtual const btMultiBodyConstraint* getMultiBodyConstraint( int constraintIndex) const
  70. {
  71. return m_multiBodyConstraints[constraintIndex];
  72. }
  73. virtual void removeMultiBodyConstraint( btMultiBodyConstraint* constraint);
  74. virtual void integrateTransforms(btScalar timeStep);
  75. virtual void debugDrawWorld();
  76. virtual void debugDrawMultiBodyConstraint(btMultiBodyConstraint* constraint);
  77. void forwardKinematics();
  78. virtual void clearForces();
  79. virtual void clearMultiBodyConstraintForces();
  80. virtual void clearMultiBodyForces();
  81. virtual void applyGravity();
  82. virtual void serialize(btSerializer* serializer);
  83. virtual void setMultiBodyConstraintSolver(btMultiBodyConstraintSolver* solver);
  84. virtual void setConstraintSolver(btConstraintSolver* solver);
  85. };
  86. #endif //BT_MULTIBODY_DYNAMICS_WORLD_H