PhysicsMotionState.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef PHYSICSMOTIONSTATE_H_
  2. #define PHYSICSMOTIONSTATE_H_
  3. #include "Vector3.h"
  4. namespace gameplay
  5. {
  6. class Node;
  7. /**
  8. * Interface between GamePlay and Bullet to keep object transforms synchronized properly.
  9. *
  10. * @see btMotionState
  11. */
  12. class PhysicsMotionState : public btMotionState
  13. {
  14. friend class PhysicsCollisionObject;
  15. friend class PhysicsRigidBody;
  16. friend class PhysicsGhostObject;
  17. friend class PhysicsCharacter;
  18. friend class PhysicsConstraint;
  19. protected:
  20. /**
  21. * Creates a physics motion state for a rigid body.
  22. *
  23. * @param node The node that owns the rigid body that the motion state is being created for.
  24. * @param centerOfMassOffset The translation offset to the center of mass of the rigid body.
  25. */
  26. PhysicsMotionState(Node* node, const Vector3* centerOfMassOffset = NULL);
  27. /**
  28. * Destructor.
  29. */
  30. virtual ~PhysicsMotionState();
  31. /**
  32. * @see btMotionState#getWorldTransform
  33. */
  34. virtual void getWorldTransform(btTransform &transform) const;
  35. /**
  36. * @see btMotionState#setWorldTransform
  37. */
  38. virtual void setWorldTransform(const btTransform &transform);
  39. private:
  40. // Updates the motion state's world transform from the GamePlay Node object's world transform.
  41. void updateTransformFromNode() const;
  42. Node* _node;
  43. btTransform _centerOfMassOffset;
  44. mutable btTransform _worldTransform;
  45. };
  46. }
  47. #endif