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