BsFCollider.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /** @cond INTERNAL */
  11. /** @addtogroup Physics
  12. * @{
  13. */
  14. /** Provides common functionality used by all Collider types. */
  15. class BS_CORE_EXPORT FCollider
  16. {
  17. public:
  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 (i.e. objects will pass
  27. * through it), but collision events will still be reported.
  28. */
  29. virtual void setIsTrigger(bool value) = 0;
  30. /** Checks is the collider a trigger. */
  31. virtual bool getIsTrigger() const = 0;
  32. /**
  33. * Changes whether the collider is a part of a rigidbody (non-static), or is on its own (static). You should change
  34. * this whenever you are attaching or detaching a collider from a rigidbody.
  35. */
  36. virtual void setIsStatic(bool value) = 0;
  37. /** Checks whether the collider is a part of a rigidbody (non-static), or is on its own (static). */
  38. virtual bool getIsStatic() const = 0;
  39. /**
  40. * Sets 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. /** Returns the mass of the collider. */
  46. virtual float getMass() const { return mMass; }
  47. /** Sets the material of the collider. The material determines how objects hitting the collider behave. */
  48. virtual void setMaterial(const HPhysicsMaterial& material);
  49. /** Gets the material of the collider. The material determines how objects hitting the collider behave. */
  50. virtual HPhysicsMaterial getMaterial() const { return mMaterial; }
  51. /**
  52. * Determines how far apart do two shapes need to be away from each other before the physics runtime starts
  53. * generating repelling impulse for them. This distance will be the sum of contact offsets of the two interacting
  54. * objects. If objects are moving fast you can increase this value to start generating the impulse earlier and
  55. * potentially prevent the objects from interpenetrating. This value is in meters.
  56. *
  57. * Also see setRestOffset().
  58. */
  59. virtual void setContactOffset(float value) = 0;
  60. /** Returns shape's contact offset in meters. See setContactOffset() to learn contact offset is. */
  61. virtual float getContactOffset() const = 0;
  62. /**
  63. * Sets at what distance should two objects resting on one another come to an equilibrium. The value used in the
  64. * runtime will be the sum of rest offsets for both interacting objects. This value is in meters.
  65. */
  66. virtual void setRestOffset(float value) = 0;
  67. /** Returns shepe's rest offset in meters. See setRestOffset() to learn what contact offset is. */
  68. virtual float getRestOffset() const = 0;
  69. /** Sets the layer of the collider. Layer controls with which objects will the collider collide. */
  70. virtual void setLayer(UINT64 layer) = 0;
  71. /** Gets the layer of the collider. Layer controls with which objects will the collider collide. */
  72. virtual UINT64 getLayer() const = 0;
  73. /** Sets a value that determines which (if any) collision events are reported. */
  74. virtual void setCollisionReportMode(CollisionReportMode mode) = 0;
  75. /** Gets a value that determines which (if any) collision events are reported. */
  76. virtual CollisionReportMode getCollisionReportMode() const = 0;
  77. /** Enables continous collision detect for this collider. Only valid if the collider is a part of a rigidbody. */
  78. virtual void _setCCD(bool enabled) = 0;
  79. protected:
  80. float mMass = 1.0f;
  81. HPhysicsMaterial mMaterial;
  82. };
  83. /** @} */
  84. /** @endcond */
  85. }