BsFCollider.h 4.5 KB

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