btDefaultMotionState.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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) btDefaultMotionState : public btMotionState
  6. {
  7. btTransform m_graphicsWorldTrans;
  8. btTransform m_centerOfMassOffset;
  9. btTransform m_startWorldTrans;
  10. void* m_userPointer;
  11. BT_DECLARE_ALIGNED_ALLOCATOR();
  12. btDefaultMotionState(const btTransform& startTrans = btTransform::getIdentity(),const btTransform& centerOfMassOffset = btTransform::getIdentity())
  13. : m_graphicsWorldTrans(startTrans),
  14. m_centerOfMassOffset(centerOfMassOffset),
  15. m_startWorldTrans(startTrans),
  16. m_userPointer(0)
  17. {
  18. }
  19. ///synchronizes world transform from user to physics
  20. virtual void getWorldTransform(btTransform& centerOfMassWorldTrans ) const
  21. {
  22. centerOfMassWorldTrans = m_graphicsWorldTrans * m_centerOfMassOffset.inverse() ;
  23. }
  24. ///synchronizes world transform from physics to user
  25. ///Bullet only calls the update of worldtransform for active objects
  26. virtual void setWorldTransform(const btTransform& centerOfMassWorldTrans)
  27. {
  28. m_graphicsWorldTrans = centerOfMassWorldTrans * m_centerOfMassOffset;
  29. }
  30. };
  31. #endif //BT_DEFAULT_MOTION_STATE_H