PhysicsJoint.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. PhysicsJoint::PhysicsJoint(PhysicsWorld* world, JointType type)
  10. : PhysicsObject(CLASS_TYPE, world)
  11. , m_type(type)
  12. {
  13. }
  14. void PhysicsJoint::registerToWorld()
  15. {
  16. getWorld().getBtWorld().addConstraint(getJoint());
  17. }
  18. void PhysicsJoint::unregisterFromWorld()
  19. {
  20. getWorld().getBtWorld().removeConstraint(getJoint());
  21. }
  22. PhysicsPoint2PointJoint::PhysicsPoint2PointJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPos)
  23. : PhysicsJoint(world, JointType::P2P)
  24. {
  25. m_bodyA = bodyA;
  26. m_p2p.init(*m_bodyA->getBtBody(), toBt(relPos));
  27. getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
  28. }
  29. PhysicsPoint2PointJoint::PhysicsPoint2PointJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPosA,
  30. PhysicsBodyPtr bodyB, const Vec3& relPosB)
  31. : PhysicsJoint(world, JointType::P2P)
  32. {
  33. ANKI_ASSERT(bodyA != bodyB);
  34. m_bodyA = bodyA;
  35. m_bodyB = bodyB;
  36. m_p2p.init(*m_bodyA->getBtBody(), *m_bodyB->getBtBody(), toBt(relPosA), toBt(relPosB));
  37. getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
  38. }
  39. PhysicsPoint2PointJoint::~PhysicsPoint2PointJoint()
  40. {
  41. m_p2p.destroy();
  42. }
  43. PhysicsHingeJoint::PhysicsHingeJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPos, const Vec3& axis)
  44. : PhysicsJoint(world, JointType::HINGE)
  45. {
  46. m_bodyA = bodyA;
  47. m_hinge.init(*m_bodyA->getBtBody(), toBt(relPos), toBt(axis));
  48. getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
  49. }
  50. PhysicsHingeJoint::~PhysicsHingeJoint()
  51. {
  52. m_hinge.destroy();
  53. }
  54. } // end namespace anki