PhysicsSocketConstraint.cpp 1.7 KB

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