BsCCollider.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 "BsBoxCollider.h"
  6. #include "BsComponent.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Components-Core
  10. * @{
  11. */
  12. /**
  13. * @copydoc Collider
  14. *
  15. * Wraps Collider as a Component.
  16. */
  17. class BS_CORE_EXPORT CCollider : public Component
  18. {
  19. public:
  20. CCollider(const HSceneObject& parent);
  21. /** @copydoc Collider::setIsTrigger */
  22. inline void setIsTrigger(bool value);
  23. /** @copydoc Collider::getIsTrigger */
  24. bool getIsTrigger() const { return mIsTrigger; }
  25. /** @copydoc Collider::setMass */
  26. inline void setMass(float mass);
  27. /** @copydoc Collider::getMass */
  28. float getMass() const { return mMass; }
  29. /** @copydoc Collider::setMaterial */
  30. inline void setMaterial(const HPhysicsMaterial& material);
  31. /** @copydoc Collider::getMaterial */
  32. HPhysicsMaterial getMaterial() const { return mMaterial; }
  33. /** @copydoc Collider::setContactOffset */
  34. inline void setContactOffset(float value);
  35. /** @copydoc Collider::getContactOffset */
  36. float getContactOffset() const { return mContactOffset; }
  37. /** @copydoc Collider::setRestOffset */
  38. inline void setRestOffset(float value);
  39. /** @copydoc Collider::getRestOffset */
  40. float getRestOffset() const { return mRestOffset; }
  41. /** @copydoc Collider::setLayer */
  42. inline void setLayer(UINT64 layer);
  43. /** @copydoc Collider::getLayer */
  44. UINT64 getLayer() const { return mLayer; }
  45. /** @copydoc Collider::getRigidbody */
  46. HRigidbody getRigidbody() const { return mParent; }
  47. /** @copydoc Collider::onCollisionBegin */
  48. Event<void(const CollisionData&)> onCollisionBegin;
  49. /** @copydoc Collider::onCollisionStay */
  50. Event<void(const CollisionData&)> onCollisionStay;
  51. /** @copydoc Collider::onCollisionEnd */
  52. Event<void(const CollisionData&)> onCollisionEnd;
  53. /** @cond INTERNAL */
  54. /** Changes the rigidbody parent of the collider. Meant to be called from the Rigidbody itself. */
  55. void _setRigidbody(const HRigidbody& rigidbody);
  56. /** @endcond */
  57. /************************************************************************/
  58. /* COMPONENT OVERRIDES */
  59. /************************************************************************/
  60. protected:
  61. friend class SceneObject;
  62. /** @copydoc Component::onInitialized() */
  63. void onInitialized() override;
  64. /** @copydoc Component::onDestroyed() */
  65. void onDestroyed() override;
  66. /** @copydoc Component::onDisabled() */
  67. void onDisabled() override;
  68. /** @copydoc Component::onEnabled() */
  69. void onEnabled() override;
  70. /** @copydoc Component::onTransformChanged() */
  71. void onTransformChanged(TransformChangedFlags flags) override;
  72. protected:
  73. /** Creates the internal representation of the Collider for use by the component. */
  74. virtual SPtr<Collider> createInternal() = 0;
  75. /** Creates the internal representation of the Collider and restores the values saved by the Component. */
  76. virtual void restoreInternal();
  77. /**
  78. * Updates the transform of the internal Collider representation from the transform of the component's Scene Object.
  79. */
  80. void updateTransform();
  81. /** Searches the parent scene object hierarchy to find a parent Rigidbody component. */
  82. void updateParentRigidbody();
  83. /** Triggered when the internal collider begins touching another object. */
  84. void triggerOnCollisionBegin(const CollisionData& data);
  85. /** Triggered when the internal collider continues touching another object. */
  86. void triggerOnCollisionStay(const CollisionData& data);
  87. /** Triggered when the internal collider ends touching another object. */
  88. void triggerOnCollisionEnd(const CollisionData& data);
  89. SPtr<Collider> mInternal;
  90. UINT64 mLayer = 1;
  91. float mRestOffset = 0.0f;
  92. float mContactOffset = 0.0f;
  93. HPhysicsMaterial mMaterial;
  94. float mMass = 0.0f;
  95. bool mIsTrigger = false;
  96. Vector3 mLocalPosition;
  97. Quaternion mLocalRotation;
  98. HRigidbody mParent;
  99. /************************************************************************/
  100. /* RTTI */
  101. /************************************************************************/
  102. public:
  103. friend class CColliderRTTI;
  104. static RTTITypeBase* getRTTIStatic();
  105. RTTITypeBase* getRTTI() const override;
  106. protected:
  107. CCollider() {} // Serialization only
  108. };
  109. /** @} */
  110. }