BsCJoint.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Physics/BsJoint.h"
  6. #include "Scene/BsComponent.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Components-Core
  10. * @{
  11. */
  12. /**
  13. * @copydoc Joint
  14. *
  15. * @note Wraps Joint as a Component.
  16. */
  17. class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Physics,n:Joint) CJoint : public Component
  18. {
  19. public:
  20. CJoint(const HSceneObject& parent, JOINT_DESC& desc);
  21. virtual ~CJoint() {}
  22. /** @copydoc Joint::getBody */
  23. BS_SCRIPT_EXPORT(n:GetBody)
  24. HRigidbody getBody(JointBody body) const;
  25. /** @copydoc Joint::setBody */
  26. BS_SCRIPT_EXPORT(n:SetBody)
  27. void setBody(JointBody body, const HRigidbody& value);
  28. /** @copydoc Joint::getPosition */
  29. BS_SCRIPT_EXPORT(n:GetPosition)
  30. Vector3 getPosition(JointBody body) const;
  31. /** @copydoc Joint::getRotation */
  32. BS_SCRIPT_EXPORT(n:GetRotation)
  33. Quaternion getRotation(JointBody body) const;
  34. /** @copydoc Joint::setTransform */
  35. BS_SCRIPT_EXPORT(n:SetTransform)
  36. void setTransform(JointBody body, const Vector3& position, const Quaternion& rotation);
  37. /** @copydoc Joint::getBreakForce */
  38. BS_SCRIPT_EXPORT(n:BreakForce,pr:getter)
  39. float getBreakForce() const;
  40. /** @copydoc Joint::setBreakForce */
  41. BS_SCRIPT_EXPORT(n:BreakForce,pr:setter)
  42. void setBreakForce(float force);
  43. /** @copydoc Joint::getBreakTorque */
  44. BS_SCRIPT_EXPORT(n:BreakTorque,pr:getter)
  45. float getBreakTorque() const;
  46. /** @copydoc Joint::setBreakTorque */
  47. BS_SCRIPT_EXPORT(n:BreakTorque,pr:setter)
  48. void setBreakTorque(float torque);
  49. /** @copydoc Joint::getEnableCollision */
  50. BS_SCRIPT_EXPORT(n:EnableCollision,pr:getter)
  51. bool getEnableCollision() const;
  52. /** @copydoc Joint::setEnableCollision */
  53. BS_SCRIPT_EXPORT(n:EnableCollision,pr:setter)
  54. void setEnableCollision(bool value);
  55. /** @copydoc Joint::onJointBreak */
  56. BS_SCRIPT_EXPORT(n:OnJointBreak)
  57. Event<void()> onJointBreak;
  58. /** @name Internal
  59. * @{
  60. */
  61. /** Returns the Joint implementation wrapped by this component. */
  62. Joint* _getInternal() const { return mInternal.get(); }
  63. /** @} */
  64. /************************************************************************/
  65. /* COMPONENT OVERRIDES */
  66. /************************************************************************/
  67. protected:
  68. friend class SceneObject;
  69. /** @copydoc Component::onInitialized() */
  70. void onInitialized() override;
  71. /** @copydoc Component::onDestroyed() */
  72. void onDestroyed() override;
  73. /** @copydoc Component::onDisabled() */
  74. void onDisabled() override;
  75. /** @copydoc Component::onEnabled() */
  76. void onEnabled() override;
  77. /** @copydoc Component::onTransformChanged() */
  78. void onTransformChanged(TransformChangedFlags flags) override;
  79. protected:
  80. friend class CRigidbody;
  81. using Component::destroyInternal;
  82. /** Creates the internal representation of the Joint for use by the component. */
  83. virtual SPtr<Joint> createInternal() = 0;
  84. /** Creates the internal representation of the Joint and restores the values saved by the Component. */
  85. virtual void restoreInternal();
  86. /** Calculates the local position/rotation that needs to be applied to the particular joint body. */
  87. virtual void getLocalTransform(JointBody body, Vector3& position, Quaternion& rotation);
  88. /** Destroys the internal joint representation. */
  89. void destroyInternal();
  90. /** Notifies the joint that one of the attached rigidbodies moved and that its transform needs updating. */
  91. void notifyRigidbodyMoved(const HRigidbody& body);
  92. /** Checks can the provided rigidbody be used for initializing the joint. */
  93. bool isBodyValid(const HRigidbody& body);
  94. /** Updates the local transform for the specified body attached to the joint. */
  95. void updateTransform(JointBody body);
  96. /** Triggered when the joint constraint gets broken. */
  97. void triggerOnJointBroken();
  98. SPtr<Joint> mInternal;
  99. HRigidbody mBodies[2];
  100. Vector3 mPositions[2];
  101. Quaternion mRotations[2];
  102. private:
  103. JOINT_DESC& mDesc;
  104. /************************************************************************/
  105. /* RTTI */
  106. /************************************************************************/
  107. public:
  108. friend class CJointRTTI;
  109. static RTTITypeBase* getRTTIStatic();
  110. RTTITypeBase* getRTTI() const override;
  111. CJoint(JOINT_DESC& desc); // Serialization only
  112. };
  113. /** @} */
  114. }