PhysicsHingeConstraint.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "Base.h"
  2. #include "PhysicsHingeConstraint.h"
  3. #include "Node.h"
  4. namespace gameplay
  5. {
  6. void PhysicsHingeConstraint::setLimits(float minAngle, float maxAngle, float bounciness)
  7. {
  8. // Use the defaults for softness (0.9) and biasFactor (0.3).
  9. GP_ASSERT(_constraint);
  10. ((btHingeConstraint*)_constraint)->setLimit(minAngle, maxAngle, 0.9f, 0.3f, bounciness);
  11. }
  12. PhysicsHingeConstraint::PhysicsHingeConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
  13. PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB)
  14. : PhysicsConstraint(a, b)
  15. {
  16. GP_ASSERT(a && a->_body && a->getNode());
  17. // Take scale into account for the first node's translation offset.
  18. Vector3 sA;
  19. a->getNode()->getWorldMatrix().getScale(&sA);
  20. Vector3 tA(translationOffsetA.x * sA.x, translationOffsetA.y * sA.y, translationOffsetA.z * sA.z);
  21. if (b)
  22. {
  23. GP_ASSERT(b->_body && b->getNode());
  24. // Take scale into account for the second node's translation offset.
  25. Vector3 sB;
  26. b->getNode()->getWorldMatrix().getScale(&sB);
  27. Vector3 tB(translationOffsetB.x * sB.x, translationOffsetB.y * sB.y, translationOffsetB.z * sB.z);
  28. btTransform frameInA(BQ(rotationOffsetA), BV(tA));
  29. btTransform frameInB(BQ(rotationOffsetB), BV(tB));
  30. _constraint = new btHingeConstraint(*a->_body, *b->_body, frameInA, frameInB);
  31. }
  32. else
  33. {
  34. btTransform frameInA(BQ(rotationOffsetA), BV(tA));
  35. _constraint = new btHingeConstraint(*a->_body, frameInA);
  36. }
  37. }
  38. PhysicsHingeConstraint::~PhysicsHingeConstraint()
  39. {
  40. // Unused
  41. }
  42. }