btDefaultMotionState.h 1.2 KB

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