JointComponent.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #pragma once
  6. #include <AnKi/Scene/Components/SceneComponent.h>
  7. #include <AnKi/Physics/PhysicsJoint.h>
  8. namespace anki
  9. {
  10. /// @addtogroup scene
  11. /// @{
  12. /// Contains a list of joints.
  13. class JointComponent : public SceneComponent
  14. {
  15. ANKI_SCENE_COMPONENT(JointComponent)
  16. public:
  17. JointComponent(SceneNode* node)
  18. : SceneComponent(node, getStaticClassId())
  19. , m_node(node)
  20. {
  21. ANKI_ASSERT(node);
  22. }
  23. ~JointComponent();
  24. /// Create a point 2 point joint on the BodyComponent of the SceneNode.
  25. void newPoint2PointJoint(const Vec3& relPosFactor, F32 brakingImpulse = MAX_F32);
  26. /// Create a point 2 point joint on the BodyComponents of the SceneNode and its child node.
  27. void newPoint2PointJoint2(const Vec3& relPosFactorA, const Vec3& relPosFactorB, F32 brakingImpulse = MAX_F32);
  28. /// Create a hinge joint on the BodyComponent of the SceneNode.
  29. void newHingeJoint(const Vec3& relPosFactor, const Vec3& axis, F32 brakingImpulse = MAX_F32);
  30. ANKI_USE_RESULT Error update(SceneNode& node, Second prevTime, Second crntTime, Bool& updated) override;
  31. private:
  32. class JointNode;
  33. SceneNode* m_node;
  34. IntrusiveList<JointNode> m_jointList;
  35. /// Given a 3 coodrinates that lie in [-1.0, +1.0] compute a pivot point that lies into the AABB of the collision
  36. /// shape of the body.
  37. static Vec3 computeLocalPivotFromFactors(const PhysicsBodyPtr& body, const Vec3& factors);
  38. void removeAllJoints();
  39. template<typename TJoint, typename... TArgs>
  40. void newJoint(const Vec3& relPosFactor, F32 brakingImpulse, TArgs&&... args);
  41. };
  42. /// @}
  43. } // end namespace anki