BsCollider.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /**
  34. * Checks does the ray hit this collider.
  35. *
  36. * @param[in] ray Ray to check.
  37. * @param[out] hit Information about the hit. Valid only if the method returns true.
  38. * @param[in] maxDist Maximum distance from the ray origin to search for hits.
  39. * @return True if the ray has hit the collider.
  40. */
  41. inline bool rayCast(const Ray& ray, PhysicsQueryHit& hit, float maxDist = FLT_MAX) const;
  42. /**
  43. * Checks does the ray hit this collider.
  44. *
  45. * @param[in] origin Origin of the ray to check.
  46. * @param[in] unitDir Unit direction of the ray to check.
  47. * @param[out] hit Information about the hit. Valid only if the method returns true.
  48. * @param[in] maxDist Maximum distance from the ray origin to search for hits.
  49. * @return True if the ray has hit the collider.
  50. */
  51. inline bool rayCast(const Vector3& origin, const Vector3& unitDir, PhysicsQueryHit& hit,
  52. float maxDist = FLT_MAX) const;
  53. Event<void(const CollisionData&)> onCollisionBegin;
  54. Event<void(const CollisionData&)> onCollisionStay;
  55. Event<void(const CollisionData&)> onCollisionEnd;
  56. /** @cond INTERNAL */
  57. FCollider* _getInternal() const { return mInternal; }
  58. /**
  59. * Sets the object that owns this physics object, if any. Used for high level systems so they can easily map their
  60. * high level physics objects from the low level ones returned by various queries and events.
  61. */
  62. void _setOwner(PhysicsOwnerType type, void* owner) { mOwner.type = type; mOwner.ownerData = owner; }
  63. /**
  64. * Gets the object that owns this physics object, if any. Used for high level systems so they can easily map their
  65. * high level physics objects from the low level ones returned by various queries and events.
  66. */
  67. void* _getOwner(PhysicsOwnerType type) const { return mOwner.type == type ? mOwner.ownerData : nullptr; }
  68. /** @endcond */
  69. protected:
  70. FCollider* mInternal = nullptr;
  71. PhysicsObjectOwner mOwner;
  72. Rigidbody* mRigidbody = nullptr;
  73. Vector3 mScale = Vector3::ONE;
  74. };
  75. }