BsFCollider.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. 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. /** 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. Must be positive and greater
  56. * than rest offset.
  57. *
  58. * Also see setRestOffset().
  59. */
  60. virtual void setContactOffset(float value) = 0;
  61. /** Returns shape's contact offset in meters. See setContactOffset() to learn contact offset is. */
  62. virtual float getContactOffset() const = 0;
  63. /**
  64. * Sets at what distance should two objects resting on one another come to an equilibrium. The value used in the
  65. * runtime will be the sum of rest offsets for both interacting objects. This value is in meters. Cannot be larger
  66. * than contact offset.
  67. *
  68. * Also see setContactOffset().
  69. */
  70. virtual void setRestOffset(float value) = 0;
  71. /** Returns shepe's rest offset in meters. See setRestOffset() to learn what contact offset is. */
  72. virtual float getRestOffset() const = 0;
  73. /** Sets the layer of the collider. Layer controls with which objects will the collider collide. */
  74. virtual void setLayer(UINT64 layer) = 0;
  75. /** Gets the layer of the collider. Layer controls with which objects will the collider collide. */
  76. virtual UINT64 getLayer() const = 0;
  77. /** Sets a value that determines which (if any) collision events are reported. */
  78. virtual void setCollisionReportMode(CollisionReportMode mode) = 0;
  79. /** Gets a value that determines which (if any) collision events are reported. */
  80. virtual CollisionReportMode getCollisionReportMode() const = 0;
  81. /** Enables continous collision detect for this collider. Only valid if the collider is a part of a rigidbody. */
  82. virtual void _setCCD(bool enabled) = 0;
  83. protected:
  84. float mMass = 1.0f;
  85. HPhysicsMaterial mMaterial;
  86. };
  87. /** @} */
  88. }