BsFCollider.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 "Physics/BsPhysicsCommon.h"
  6. #include "Math/BsVector3.h"
  7. #include "Math/BsQuaternion.h"
  8. namespace bs
  9. {
  10. /** @addtogroup Physics-Internal
  11. * @{
  12. */
  13. /** Provides common functionality used by all Collider types. */
  14. class BS_CORE_EXPORT FCollider
  15. {
  16. public:
  17. FCollider() { }
  18. virtual ~FCollider();
  19. /** Returns the position of the collider. */
  20. virtual Vector3 getPosition() const = 0;
  21. /** Returns the rotation of the collider. */
  22. virtual Quaternion getRotation() const = 0;
  23. /** Sets the position and rotation of the collider. */
  24. virtual void setTransform(const Vector3& pos, const Quaternion& rotation) = 0;
  25. /**
  26. * Enables/disables a collider as a trigger. A trigger will not be used for collisions (objects will pass
  27. * through it), but collision events will still be reported.
  28. */
  29. virtual void setIsTrigger(bool value) = 0;
  30. /** @copydoc setIsTrigger() */
  31. virtual bool getIsTrigger() const = 0;
  32. /**
  33. * Determines whether the collider is a part of a rigidbody (non-static), or is on its own (static). You should
  34. * change this whenever you are attaching or detaching a collider from a rigidbody.
  35. */
  36. virtual void setIsStatic(bool value) = 0;
  37. /** @copydoc setIsStatic() */
  38. virtual bool getIsStatic() const = 0;
  39. /**
  40. * Determines the mass of the collider. Only relevant if the collider is part of a rigidbody. Ultimately this will
  41. * determine the total mass, center of mass and inertia tensors of the parent rigidbody (if they're being calculated
  42. * automatically).
  43. */
  44. virtual void setMass(float mass) { mMass = mass; }
  45. /** @copydoc setMass() */
  46. virtual float getMass() const { return mMass; }
  47. /**
  48. * Determines the physical material of the collider. The material determines how objects hitting the collider
  49. * behave.
  50. */
  51. virtual void setMaterial(const HPhysicsMaterial& material);
  52. /** @copydoc setMaterial() */
  53. virtual HPhysicsMaterial getMaterial() const { return mMaterial; }
  54. /**
  55. * Determines how far apart do two shapes need to be away from each other before the physics runtime starts
  56. * generating repelling impulse for them. This distance will be the sum of contact offsets of the two interacting
  57. * objects. If objects are moving fast you can increase this value to start generating the impulse earlier and
  58. * potentially prevent the objects from interpenetrating. This value is in meters. Must be positive and greater
  59. * than rest offset.
  60. *
  61. * Also see setRestOffset().
  62. */
  63. virtual void setContactOffset(float value) = 0;
  64. /** @copydoc setContactOffset() */
  65. virtual float getContactOffset() const = 0;
  66. /**
  67. * Determines at what distance should two objects resting on one another come to an equilibrium. The value used in
  68. * the runtime will be the sum of rest offsets for both interacting objects. This value is in meters. Cannot be
  69. * larger than contact offset.
  70. *
  71. * Also see setContactOffset().
  72. */
  73. virtual void setRestOffset(float value) = 0;
  74. /** @copydoc setRestOffset() */
  75. virtual float getRestOffset() const = 0;
  76. /** Determines the layer of the collider. Layer controls with which objects will the collider collide. */
  77. virtual void setLayer(UINT64 layer) = 0;
  78. /** @copydoc setLayer() */
  79. virtual UINT64 getLayer() const = 0;
  80. /** Determines which (if any) collision events are reported. */
  81. virtual void setCollisionReportMode(CollisionReportMode mode) = 0;
  82. /** @copydoc setCollisionReportMode() */
  83. virtual CollisionReportMode getCollisionReportMode() const = 0;
  84. /** Enables continous collision detect for this collider. Only valid if the collider is a part of a rigidbody. */
  85. virtual void _setCCD(bool enabled) = 0;
  86. protected:
  87. float mMass = 1.0f;
  88. HPhysicsMaterial mMaterial;
  89. };
  90. /** @} */
  91. }