PhysicsSocketConstraint.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * PhysicsSocketConstraint.cpp
  3. */
  4. #include "PhysicsSocketConstraint.h"
  5. #include "Node.h"
  6. namespace gameplay
  7. {
  8. PhysicsSocketConstraint::PhysicsSocketConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b)
  9. : PhysicsConstraint(a, b)
  10. {
  11. if (b)
  12. {
  13. Vector3 origin = centerOfMassMidpoint(a->getNode(), b->getNode());
  14. btTransform frameInA = getTransformOffset(a->getNode(), origin);
  15. btTransform frameInB = getTransformOffset(b->getNode(), origin);
  16. _constraint = new btPoint2PointConstraint(*a->_body, *b->_body, frameInA.getOrigin(), frameInB.getOrigin());
  17. }
  18. else
  19. {
  20. _constraint = new btPoint2PointConstraint(*a->_body, btVector3(0.0f, 0.0f, 0.0f));
  21. }
  22. }
  23. PhysicsSocketConstraint::PhysicsSocketConstraint(PhysicsRigidBody* a, const Vector3& translationOffsetA,
  24. PhysicsRigidBody* b, const Vector3& translationOffsetB)
  25. : PhysicsConstraint(a, b)
  26. {
  27. // Take scale into account for the first node's translation offset.
  28. Vector3 sA;
  29. a->getNode()->getWorldMatrix().getScale(&sA);
  30. Vector3 tA(translationOffsetA.x * sA.x, translationOffsetA.y * sA.y, translationOffsetA.z * sA.z);
  31. if (b)
  32. {
  33. // Take scale into account for the second node's translation offset.
  34. Vector3 sB;
  35. b->getNode()->getWorldMatrix().getScale(&sB);
  36. Vector3 tB(translationOffsetB.x * sB.x, translationOffsetB.y * sB.y, translationOffsetB.z * sB.z);
  37. _constraint = new btPoint2PointConstraint(*a->_body, *b->_body, btVector3(tA.x, tA.y, tA.z), btVector3(tB.x, tB.y, tB.z));
  38. }
  39. else
  40. {
  41. _constraint = new btPoint2PointConstraint(*a->_body, btVector3(tA.x, tA.y, tA.z));
  42. }
  43. }
  44. PhysicsSocketConstraint::~PhysicsSocketConstraint()
  45. {
  46. // DUMMY FUNCTION
  47. }
  48. }