| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #include <AnKi/Physics/PhysicsJoint.h>
- #include <AnKi/Physics/PhysicsBody.h>
- #include <AnKi/Physics/PhysicsWorld.h>
- namespace anki {
- PhysicsJoint::PhysicsJoint(JointType type)
- : PhysicsObject(kClassType)
- , m_type(type)
- {
- }
- void PhysicsJoint::registerToWorld()
- {
- PhysicsWorld::getSingleton().getBtWorld().addConstraint(getJoint());
- }
- void PhysicsJoint::unregisterFromWorld()
- {
- PhysicsWorld::getSingleton().getBtWorld().removeConstraint(getJoint());
- }
- PhysicsPoint2PointJoint::PhysicsPoint2PointJoint(PhysicsBodyPtr bodyA, const Vec3& relPos)
- : PhysicsJoint(JointType::kP2P)
- {
- m_bodyA = std::move(bodyA);
- m_p2p.construct(*m_bodyA->getBtBody(), toBt(relPos));
- getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
- }
- PhysicsPoint2PointJoint::PhysicsPoint2PointJoint(PhysicsBodyPtr bodyA, const Vec3& relPosA, PhysicsBodyPtr bodyB, const Vec3& relPosB)
- : PhysicsJoint(JointType::kP2P)
- {
- ANKI_ASSERT(bodyA != bodyB);
- m_bodyA = std::move(bodyA);
- m_bodyB = std::move(bodyB);
- m_p2p.construct(*m_bodyA->getBtBody(), *m_bodyB->getBtBody(), toBt(relPosA), toBt(relPosB));
- getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
- }
- PhysicsPoint2PointJoint::~PhysicsPoint2PointJoint()
- {
- m_p2p.destroy();
- }
- PhysicsHingeJoint::PhysicsHingeJoint(PhysicsBodyPtr bodyA, const Vec3& relPos, const Vec3& axis)
- : PhysicsJoint(JointType::kHinge)
- {
- m_bodyA = std::move(bodyA);
- m_hinge.construct(*m_bodyA->getBtBody(), toBt(relPos), toBt(axis));
- getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
- }
- PhysicsHingeJoint::PhysicsHingeJoint(PhysicsBodyPtr bodyA, const Vec3& relPosA, const Vec3& axisA, PhysicsBodyPtr bodyB, const Vec3& relPosB,
- const Vec3& axisB)
- : PhysicsJoint(JointType::kHinge)
- {
- m_bodyA = std::move(bodyA);
- m_bodyB = std::move(bodyB);
- m_hinge.construct(*m_bodyA->getBtBody(), *m_bodyB->getBtBody(), toBt(relPosA), toBt(relPosB), toBt(axisA), toBt(axisB));
- getJoint()->setUserConstraintPtr(static_cast<PhysicsObject*>(this));
- }
- PhysicsHingeJoint::~PhysicsHingeJoint()
- {
- m_hinge.destroy();
- }
- } // end namespace anki
|