2
0

PhysicsJoint.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Physics/PhysicsJoint.h>
  6. #include <AnKi/Physics/PhysicsBody.h>
  7. #include <AnKi/Physics/PhysicsWorld.h>
  8. namespace anki
  9. {
  10. PhysicsJoint::PhysicsJoint(PhysicsWorld* world, JointType type)
  11. : PhysicsObject(CLASS_TYPE, world)
  12. , m_type(type)
  13. {
  14. }
  15. void PhysicsJoint::registerToWorld()
  16. {
  17. getWorld().getBtWorld().addConstraint(getJoint());
  18. }
  19. void PhysicsJoint::unregisterFromWorld()
  20. {
  21. getWorld().getBtWorld().removeConstraint(getJoint());
  22. }
  23. PhysicsPoint2PointJoint::PhysicsPoint2PointJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPos)
  24. : PhysicsJoint(world, JointType::P2P)
  25. {
  26. m_bodyA = bodyA;
  27. m_p2p.init(*m_bodyA->getBtBody(), toBt(relPos));
  28. getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
  29. }
  30. PhysicsPoint2PointJoint::PhysicsPoint2PointJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPosA,
  31. PhysicsBodyPtr bodyB, const Vec3& relPosB)
  32. : PhysicsJoint(world, JointType::P2P)
  33. {
  34. ANKI_ASSERT(bodyA != bodyB);
  35. m_bodyA = bodyA;
  36. m_bodyB = bodyB;
  37. m_p2p.init(*m_bodyA->getBtBody(), *m_bodyB->getBtBody(), toBt(relPosA), toBt(relPosB));
  38. getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
  39. }
  40. PhysicsPoint2PointJoint::~PhysicsPoint2PointJoint()
  41. {
  42. m_p2p.destroy();
  43. }
  44. PhysicsHingeJoint::PhysicsHingeJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPos, const Vec3& axis)
  45. : PhysicsJoint(world, JointType::HINGE)
  46. {
  47. m_bodyA = bodyA;
  48. m_hinge.init(*m_bodyA->getBtBody(), toBt(relPos), toBt(axis));
  49. getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
  50. }
  51. PhysicsHingeJoint::~PhysicsHingeJoint()
  52. {
  53. m_hinge.destroy();
  54. }
  55. } // end namespace anki