JointComponent.h 1.7 KB

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