Plasma Engine  2.0
Loading...
Searching...
No Matches
PhysicsWorldModule.h
1#pragma once
2
3#include <Core/Messages/EventMessage.h>
4#include <Core/ResourceManager/ResourceHandle.h>
5#include <Core/World/WorldModule.h>
6#include <Foundation/Communication/Message.h>
7
10
12
14enum class plPhysicsHitType : int8_t
15{
16 Undefined = -1,
17 TriangleFrontFace = 0,
18 TriangleBackFace = 1,
19};
20
23{
24 plVec3 m_vPosition;
25 plVec3 m_vNormal;
26 float m_fDistance;
27
31 plUInt32 m_uiObjectFilterID = plInvalidIndex;
32 plPhysicsHitType m_hitType = plPhysicsHitType::Undefined;
33
34 // Physics-engine specific information, may be available or not.
35 void* m_pInternalPhysicsShape = nullptr;
36 void* m_pInternalPhysicsActor = nullptr;
37};
38
39PL_DECLARE_REFLECTABLE_TYPE(PL_CORE_DLL, plPhysicsCastResult);
40
41
46
49{
50 PL_DECLARE_POD_TYPE();
51
54 plUInt32 m_uiObjectFilterID = plInvalidIndex;
56
57 // Physics-engine specific information, may be available or not.
58 void* m_pInternalPhysicsShape = nullptr;
59 void* m_pInternalPhysicsActor = nullptr;
60};
61
66
72PL_DECLARE_FLAGS_WITH_DEFAULT(plUInt32, plPhysicsShapeType, 0xFFFFFFFF,
73 Static,
74 Dynamic,
75 Query,
76 Trigger,
77 Character,
78 Ragdoll,
79 Rope,
80 Cloth
81);
82
83PL_DECLARE_REFLECTABLE_TYPE(PL_CORE_DLL, plPhysicsShapeType);
84
86{
87 plPhysicsQueryParameters() = default;
88 explicit plPhysicsQueryParameters(plUInt32 uiCollisionLayer,
89 plBitflags<plPhysicsShapeType> shapeTypes = plPhysicsShapeType::Default, plUInt32 uiIgnoreObjectFilterID = plInvalidIndex)
90 : m_uiCollisionLayer(uiCollisionLayer)
91 , m_ShapeTypes(shapeTypes)
92 , m_uiIgnoreObjectFilterID(uiIgnoreObjectFilterID)
93 {
94 }
95
96 plUInt32 m_uiCollisionLayer = 0;
97 plBitflags<plPhysicsShapeType> m_ShapeTypes = plPhysicsShapeType::Default;
98 plUInt32 m_uiIgnoreObjectFilterID = plInvalidIndex;
99 bool m_bIgnoreInitialOverlap = false;
100};
101
102enum class plPhysicsHitCollection
103{
104 Closest,
105 Any
106};
107
109{
110 PL_ADD_DYNAMIC_REFLECTION(plPhysicsWorldModuleInterface, plWorldModule);
111
112protected:
114 : plWorldModule(pWorld)
115 {
116 }
117
118public:
122 virtual plUInt32 GetCollisionLayerByName(plStringView sName) const = 0;
123
124 virtual bool Raycast(plPhysicsCastResult& out_result, const plVec3& vStart, const plVec3& vDir, float fDistance, const plPhysicsQueryParameters& params, plPhysicsHitCollection collection = plPhysicsHitCollection::Closest) const = 0;
125
126 virtual bool RaycastAll(plPhysicsCastResultArray& out_results, const plVec3& vStart, const plVec3& vDir, float fDistance, const plPhysicsQueryParameters& params) const = 0;
127
128 virtual bool SweepTestSphere(plPhysicsCastResult& out_result, float fSphereRadius, const plVec3& vStart, const plVec3& vDir, float fDistance, const plPhysicsQueryParameters& params, plPhysicsHitCollection collection = plPhysicsHitCollection::Closest) const = 0;
129
130 virtual bool SweepTestBox(plPhysicsCastResult& out_result, plVec3 vBoxExtends, const plTransform& transform, const plVec3& vDir, float fDistance, const plPhysicsQueryParameters& params, plPhysicsHitCollection collection = plPhysicsHitCollection::Closest) const = 0;
131
132 virtual bool SweepTestCapsule(plPhysicsCastResult& out_result, float fCapsuleRadius, float fCapsuleHeight, const plTransform& transform, const plVec3& vDir, float fDistance, const plPhysicsQueryParameters& params, plPhysicsHitCollection collection = plPhysicsHitCollection::Closest) const = 0;
133
134 virtual bool OverlapTestSphere(float fSphereRadius, const plVec3& vPosition, const plPhysicsQueryParameters& params) const = 0;
135
136 virtual bool OverlapTestCapsule(float fCapsuleRadius, float fCapsuleHeight, const plTransform& transform, const plPhysicsQueryParameters& params) const = 0;
137
138 virtual void QueryShapesInSphere(plPhysicsOverlapResultArray& out_results, float fSphereRadius, const plVec3& vPosition, const plPhysicsQueryParameters& params) const = 0;
139
140 virtual plVec3 GetGravity() const = 0;
141
143 // ABSTRACTION HELPERS
144 //
145 // These functions are used to be able to use certain physics functionality, without having a direct dependency on the exact implementation (Jolt / PhysX).
146 // If no physics module is available, they simply do nothing.
147 // Add functions on demand.
148
150 virtual void AddStaticCollisionBox(plGameObject* pOwner, plVec3 vBoxSize) {}
151
153 {
154 plGameObjectHandle m_hActorA;
155 plGameObjectHandle m_hActorB;
156 plTransform m_LocalFrameA = plTransform::MakeIdentity();
157 plTransform m_LocalFrameB = plTransform::MakeIdentity();
158 };
159
161 {
162 };
163
166
168 virtual plBoundingBoxSphere GetWorldSpaceBounds(plGameObject* pOwner, plUInt32 uiCollisionLayer, plBitflags<plPhysicsShapeType> shapeTypes, bool bIncludeChildObjects) const { return plBoundingBoxSphere::MakeInvalid(); }
169};
170
172
175{
176public:
178 static plPhysicsCastResult* Raycast(const plWorld* pWorld, const plVec3& vStart, const plVec3& vDir, float fDistance, plUInt32 uiCollisionLayer, plBitflags<plPhysicsShapeType> shapeTypes, plUInt32 uiIgnoreObjectFilterID);
179};
180
182
183PL_DECLARE_REFLECTABLE_TYPE(PL_CORE_DLL, plScriptExtensionClass_Physics);
184
186struct PL_CORE_DLL plMsgPhysicsAddImpulse : public plMessage
187{
188 PL_DECLARE_MESSAGE_TYPE(plMsgPhysicsAddImpulse, plMessage);
189
190 plVec3 m_vGlobalPosition;
191 plVec3 m_vImpulse;
192 plUInt32 m_uiObjectFilterID = plInvalidIndex;
193
194 // Physics-engine specific information, may be available or not.
195 void* m_pInternalPhysicsShape = nullptr;
196 void* m_pInternalPhysicsActor = nullptr;
197};
198
200struct PL_CORE_DLL plMsgPhysicsAddForce : public plMessage
201{
202 PL_DECLARE_MESSAGE_TYPE(plMsgPhysicsAddForce, plMessage);
203
204 plVec3 m_vGlobalPosition;
205 plVec3 m_vForce;
206
207 // Physics-engine specific information, may be available or not.
208 void* m_pInternalPhysicsShape = nullptr;
209 void* m_pInternalPhysicsActor = nullptr;
210};
211
212struct PL_CORE_DLL plMsgPhysicsJointBroke : public plEventMessage
213{
214 PL_DECLARE_MESSAGE_TYPE(plMsgPhysicsJointBroke, plEventMessage);
215
216 plGameObjectHandle m_hJointObject;
217};
218
220struct PL_CORE_DLL plMsgObjectGrabbed : public plMessage
221{
222 PL_DECLARE_MESSAGE_TYPE(plMsgObjectGrabbed, plMessage);
223
224 plGameObjectHandle m_hGrabbedBy;
225 bool m_bGotGrabbed = true;
226};
227
229struct PL_CORE_DLL plMsgReleaseObjectGrab : public plMessage
230{
231 PL_DECLARE_MESSAGE_TYPE(plMsgReleaseObjectGrab, plMessage);
232
233 plGameObjectHandle m_hGrabbedObjectToRelease;
234};
235
237
238struct PL_CORE_DLL plSmcTriangle
239{
240 PL_DECLARE_POD_TYPE();
241
242 plUInt32 m_uiVertexIndices[3];
243};
244
245struct PL_CORE_DLL plSmcSubMesh
246{
247 PL_DECLARE_POD_TYPE();
248
249 plUInt32 m_uiFirstTriangle = 0;
250 plUInt32 m_uiNumTriangles = 0;
251 plUInt16 m_uiSurfaceIndex = 0;
252};
253
254struct PL_CORE_DLL plSmcDescription
255{
256 plDeque<plVec3> m_Vertices;
257 plDeque<plSmcTriangle> m_Triangles;
258 plDeque<plSmcSubMesh> m_SubMeshes;
259 plDeque<plString> m_Surfaces;
260};
261
262struct PL_CORE_DLL plMsgBuildStaticMesh : public plMessage
263{
264 PL_DECLARE_MESSAGE_TYPE(plMsgBuildStaticMesh, plMessage);
265
267 plSmcDescription* m_pStaticMeshDescription = nullptr;
268};
static plBoundingBoxSphereTemplate< float > MakeInvalid()
Definition BoundingBoxSphere_inl.h:58
Definition Deque.h:270
This class represents an object inside the world.
Definition GameObject.h:32
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Base class for all message types. Each message type has it's own id which is used to dispatch message...
Definition Message.h:22
Definition PhysicsWorldModule.h:109
virtual void AddStaticCollisionBox(plGameObject *pOwner, plVec3 vBoxSize)
Adds a static actor with a box shape to pOwner.
Definition PhysicsWorldModule.h:150
virtual plUInt32 GetCollisionLayerByName(plStringView sName) const =0
Searches for a collision layer with the given name and returns its index.
virtual plBoundingBoxSphere GetWorldSpaceBounds(plGameObject *pOwner, plUInt32 uiCollisionLayer, plBitflags< plPhysicsShapeType > shapeTypes, bool bIncludeChildObjects) const
Gets world space bounds of a physics object if its shape type is included in shapeTypes and its colli...
Definition PhysicsWorldModule.h:168
virtual void AddFixedJointComponent(plGameObject *pOwner, const plPhysicsWorldModuleInterface::FixedJointConfig &cfg)
Adds a fixed joint to pOwner.
Definition PhysicsWorldModule.h:165
Helper class to expose physics to scripting.
Definition PhysicsWorldModule.h:175
static plPhysicsCastResult * Raycast(const plWorld *pWorld, const plVec3 &vStart, const plVec3 &vDir, float fDistance, plUInt32 uiCollisionLayer, plBitflags< plPhysicsShapeType > shapeTypes, plUInt32 uiIgnoreObjectFilterID)
The result object is allocated with the frame allocator and thus must be processed within the same fr...
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
static plTransformTemplate< float > MakeIdentity()
Definition Transform_inl.h:25
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
Definition WorldModule.h:10
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Base class for all messages that are sent as 'events'.
Definition EventMessage.h:8
A handle to a game object.
Definition Declarations.h:76
Definition PhysicsWorldModule.h:263
Sent by components such as plJoltGrabObjectComponent to indicate that the object has been grabbed or ...
Definition PhysicsWorldModule.h:221
Used to apply a physical force on the object.
Definition PhysicsWorldModule.h:201
Used to apply a physical impulse on the object.
Definition PhysicsWorldModule.h:187
Definition PhysicsWorldModule.h:213
Send this to components such as plJoltGrabObjectComponent to demand that m_hGrabbedObjectToRelease sh...
Definition PhysicsWorldModule.h:230
Definition PhysicsWorldModule.h:43
Used for raycast and sweep tests.
Definition PhysicsWorldModule.h:23
plPhysicsHitType m_hitType
Classification of the triangle face, see plPhysicsHitType.
Definition PhysicsWorldModule.h:32
plGameObjectHandle m_hActorObject
The game object to which the parent actor of the hit physics shape is attached.
Definition PhysicsWorldModule.h:29
plUInt32 m_uiObjectFilterID
An ID either per object (rigid-body / ragdoll) or per shape (implementation specific) that can be use...
Definition PhysicsWorldModule.h:31
plSurfaceResourceHandle m_hSurface
The type of surface that was hit (if available)
Definition PhysicsWorldModule.h:30
plGameObjectHandle m_hShapeObject
The game object to which the hit physics shape is attached.
Definition PhysicsWorldModule.h:28
Definition PhysicsWorldModule.h:63
Used to report overlap query results.
Definition PhysicsWorldModule.h:49
plGameObjectHandle m_hActorObject
The game object to which the parent actor of the hit physics shape is attached.
Definition PhysicsWorldModule.h:53
plUInt32 m_uiObjectFilterID
The shape id of the hit physics shape.
Definition PhysicsWorldModule.h:54
plVec3 m_vCenterPosition
The center position of the reported object in world space.
Definition PhysicsWorldModule.h:55
plGameObjectHandle m_hShapeObject
The game object to which the hit physics shape is attached.
Definition PhysicsWorldModule.h:52
Definition PhysicsWorldModule.h:86
Definition PhysicsWorldModule.h:161
Definition PhysicsWorldModule.h:153
Definition SkeletonResource.h:24
Definition PhysicsWorldModule.h:255
Definition PhysicsWorldModule.h:246
Definition PhysicsWorldModule.h:239