BsCJoint.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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);
  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::setBreakToque */
  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. /** Creates the internal representation of the Joint for use by the component. */
  70. virtual SPtr<Joint> createInternal() = 0;
  71. /** Creates the internal representation of the Joint and restores the values saved by the Component. */
  72. virtual void restoreInternal();
  73. /** Destroys the internal joint representation. */
  74. void destroyInternal();
  75. /** Notifies the joint that one of the attached rigidbodies moved and that its transform needs updating. */
  76. void notifyRigidbodyMoved(const HRigidbody& body);
  77. /** Updates the local transform for the specified body attached to the joint. */
  78. void updateTransform(JointBody body);
  79. /** Triggered when the joint constraint gets broken. */
  80. void triggerOnJointBroken();
  81. SPtr<Joint> mInternal;
  82. HRigidbody mBodies[2];
  83. Vector3 mPositions[2];
  84. Quaternion mRotations[2];
  85. float mBreakForce = FLT_MAX;
  86. float mBreakTorque = FLT_MAX;
  87. bool mEnableCollision = false;
  88. /************************************************************************/
  89. /* RTTI */
  90. /************************************************************************/
  91. public:
  92. friend class CJointRTTI;
  93. static RTTITypeBase* getRTTIStatic();
  94. RTTITypeBase* getRTTI() const override;
  95. protected:
  96. CJoint() {} // Serialization only
  97. };
  98. /** @} */
  99. }