PhysicsSocketConstraint.cpp 1.7 KB

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