2
0

btDefaultMotionState.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef BT_DEFAULT_MOTION_STATE_H
  2. #define BT_DEFAULT_MOTION_STATE_H
  3. #include "btMotionState.h"
  4. ///The btDefaultMotionState provides a common implementation to synchronize world transforms with offsets.
  5. ATTRIBUTE_ALIGNED16(struct)
  6. btDefaultMotionState : public btMotionState
  7. {
  8. btTransform m_graphicsWorldTrans;
  9. btTransform m_centerOfMassOffset;
  10. btTransform m_startWorldTrans;
  11. void* m_userPointer;
  12. BT_DECLARE_ALIGNED_ALLOCATOR();
  13. btDefaultMotionState(const btTransform& startTrans = btTransform::getIdentity(), const btTransform& centerOfMassOffset = btTransform::getIdentity())
  14. : m_graphicsWorldTrans(startTrans),
  15. m_centerOfMassOffset(centerOfMassOffset),
  16. m_startWorldTrans(startTrans),
  17. m_userPointer(0)
  18. {
  19. }
  20. ///synchronizes world transform from user to physics
  21. virtual void getWorldTransform(btTransform & centerOfMassWorldTrans) const
  22. {
  23. centerOfMassWorldTrans = m_graphicsWorldTrans * m_centerOfMassOffset.inverse();
  24. }
  25. ///synchronizes world transform from physics to user
  26. ///Bullet only calls the update of worldtransform for active objects
  27. virtual void setWorldTransform(const btTransform& centerOfMassWorldTrans)
  28. {
  29. m_graphicsWorldTrans = centerOfMassWorldTrans * m_centerOfMassOffset;
  30. }
  31. };
  32. #endif //BT_DEFAULT_MOTION_STATE_H