BsCJoint.h 4.2 KB

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