PhysicsSocketConstraint.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. GP_ASSERT(a && a->_body && a->getNode());
  10. if (b)
  11. {
  12. GP_ASSERT(b->_body && b->getNode());
  13. Vector3 origin = centerOfMassMidpoint(a->getNode(), b->getNode());
  14. btTransform frameInA = getTransformOffset(a->getNode(), origin);
  15. btTransform frameInB = getTransformOffset(b->getNode(), origin);
  16. _constraint = bullet_new<btPoint2PointConstraint>(*a->_body, *b->_body, frameInA.getOrigin(), frameInB.getOrigin());
  17. }
  18. else
  19. {
  20. _constraint = bullet_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. GP_ASSERT(a && a->_body && a->getNode());
  28. // Take scale into account for the first node's translation offset.
  29. Vector3 sA;
  30. a->getNode()->getWorldMatrix().getScale(&sA);
  31. Vector3 tA(translationOffsetA.x * sA.x, translationOffsetA.y * sA.y, translationOffsetA.z * sA.z);
  32. if (b)
  33. {
  34. GP_ASSERT(b->_body && b->getNode());
  35. // Take scale into account for the second node's translation offset.
  36. Vector3 sB;
  37. b->getNode()->getWorldMatrix().getScale(&sB);
  38. Vector3 tB(translationOffsetB.x * sB.x, translationOffsetB.y * sB.y, translationOffsetB.z * sB.z);
  39. _constraint = bullet_new<btPoint2PointConstraint>(*a->_body, *b->_body, BV(tA), BV(tB));
  40. }
  41. else
  42. {
  43. _constraint = bullet_new<btPoint2PointConstraint>(*a->_body, BV(tA));
  44. }
  45. }
  46. PhysicsSocketConstraint::~PhysicsSocketConstraint()
  47. {
  48. // Used
  49. }
  50. }