BsCollider.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "BsPhysicsCommon.h"
  6. #include "BsVector3.h"
  7. #include "BsQuaternion.h"
  8. namespace BansheeEngine
  9. {
  10. class BS_CORE_EXPORT Collider
  11. {
  12. public:
  13. virtual ~Collider() { }
  14. inline Vector3 getPosition() const;
  15. inline Quaternion getRotation() const;
  16. inline void setTransform(const Vector3& pos, const Quaternion& rot);
  17. virtual void setScale(const Vector3& scale);
  18. inline Vector3 getScale() const;
  19. inline void setIsTrigger(bool value);
  20. inline bool getIsTrigger() const;
  21. inline void setRigidbody(Rigidbody* value);
  22. Rigidbody* getRigidbody() const { return mRigidbody; }
  23. inline void setMass(float mass);
  24. inline float getMass() const;
  25. inline void setMaterial(const HPhysicsMaterial& material);
  26. inline HPhysicsMaterial getMaterial() const;
  27. inline void setContactOffset(float value);
  28. inline float getContactOffset();
  29. inline void setRestOffset(float value);
  30. inline float getRestOffset();
  31. inline void setLayer(UINT64 layer);
  32. inline UINT64 getLayer() const;
  33. /** Sets a value that determines which (if any) collision events are reported. */
  34. inline void setCollisionReportMode(CollisionReportMode mode);
  35. /** Gets a value that determines which (if any) collision events are reported. */
  36. inline CollisionReportMode getCollisionReportMode() const;
  37. /**
  38. * Checks does the ray hit this collider.
  39. *
  40. * @param[in] ray Ray to check.
  41. * @param[out] hit Information about the hit. Valid only if the method returns true.
  42. * @param[in] maxDist Maximum distance from the ray origin to search for hits.
  43. * @return True if the ray has hit the collider.
  44. */
  45. inline bool rayCast(const Ray& ray, PhysicsQueryHit& hit, float maxDist = FLT_MAX) const;
  46. /**
  47. * Checks does the ray hit this collider.
  48. *
  49. * @param[in] origin Origin of the ray to check.
  50. * @param[in] unitDir Unit direction of the ray to check.
  51. * @param[out] hit Information about the hit. Valid only if the method returns true.
  52. * @param[in] maxDist Maximum distance from the ray origin to search for hits.
  53. * @return True if the ray has hit the collider.
  54. */
  55. inline bool rayCast(const Vector3& origin, const Vector3& unitDir, PhysicsQueryHit& hit,
  56. float maxDist = FLT_MAX) const;
  57. Event<void(const CollisionData&)> onCollisionBegin;
  58. Event<void(const CollisionData&)> onCollisionStay;
  59. Event<void(const CollisionData&)> onCollisionEnd;
  60. /** @cond INTERNAL */
  61. FCollider* _getInternal() const { return mInternal; }
  62. /**
  63. * Sets the object that owns this physics object, if any. Used for high level systems so they can easily map their
  64. * high level physics objects from the low level ones returned by various queries and events.
  65. */
  66. void _setOwner(PhysicsOwnerType type, void* owner) { mOwner.type = type; mOwner.ownerData = owner; }
  67. /**
  68. * Gets the object that owns this physics object, if any. Used for high level systems so they can easily map their
  69. * high level physics objects from the low level ones returned by various queries and events.
  70. */
  71. void* _getOwner(PhysicsOwnerType type) const { return mOwner.type == type ? mOwner.ownerData : nullptr; }
  72. /** @endcond */
  73. protected:
  74. FCollider* mInternal = nullptr;
  75. PhysicsObjectOwner mOwner;
  76. Rigidbody* mRigidbody = nullptr;
  77. Vector3 mScale = Vector3::ONE;
  78. };
  79. }