| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma once
- #include <AnKi/Physics/PhysicsObject.h>
- #include <AnKi/Util/ClassWrapper.h>
- namespace anki {
- /// @addtogroup physics
- /// @{
- /// Joint base class. Joints connect two (or a single one) rigid bodies together.
- class PhysicsJoint : public PhysicsObject
- {
- ANKI_PHYSICS_OBJECT(PhysicsObjectType::JOINT)
- public:
- /// Set the breaking impulse.
- void setBreakingImpulseThreshold(F32 impulse)
- {
- getJoint()->setBreakingImpulseThreshold(impulse);
- }
- /// Return true if the joint broke.
- Bool isBroken() const
- {
- return !getJoint()->isEnabled();
- }
- /// Break the joint.
- void brake()
- {
- getJoint()->setEnabled(false);
- }
- protected:
- union
- {
- ClassWrapper<btPoint2PointConstraint> m_p2p;
- ClassWrapper<btHingeConstraint> m_hinge;
- };
- PhysicsBodyPtr m_bodyA;
- PhysicsBodyPtr m_bodyB;
- enum class JointType : U8
- {
- P2P,
- HINGE,
- };
- JointType m_type;
- PhysicsJoint(PhysicsWorld* world, JointType type);
- void registerToWorld() override;
- void unregisterFromWorld() override;
- const btTypedConstraint* getJoint() const
- {
- return getJointInternal();
- }
- btTypedConstraint* getJoint()
- {
- return const_cast<btTypedConstraint*>(getJointInternal());
- }
- const btTypedConstraint* getJointInternal() const
- {
- switch(m_type)
- {
- case JointType::P2P:
- return m_p2p.get();
- case JointType::HINGE:
- return m_hinge.get();
- default:
- ANKI_ASSERT(0);
- return nullptr;
- }
- }
- };
- /// Point to point joint.
- class PhysicsPoint2PointJoint : public PhysicsJoint
- {
- ANKI_PHYSICS_OBJECT(PhysicsObjectType::JOINT)
- private:
- PhysicsPoint2PointJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPos);
- PhysicsPoint2PointJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPosA, PhysicsBodyPtr bodyB,
- const Vec3& relPosB);
- ~PhysicsPoint2PointJoint();
- };
- /// Hinge joint.
- class PhysicsHingeJoint : public PhysicsJoint
- {
- ANKI_PHYSICS_OBJECT(PhysicsObjectType::JOINT)
- private:
- PhysicsHingeJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPos, const Vec3& axis);
- PhysicsHingeJoint(PhysicsWorld* world, PhysicsBodyPtr bodyA, const Vec3& relPosA, const Vec3& axisA,
- PhysicsBodyPtr bodyB, const Vec3& relPosB, const Vec3& axisB);
- ~PhysicsHingeJoint();
- };
- /// @}
- } // end namespace anki
|