Plasma Engine  2.0
Loading...
Searching...
No Matches
JoltContacts.h
1#pragma once
2
3#include <Core/World/Declarations.h>
4#include <Physics/Collision/ContactListener.h>
5
6class plWorld;
9
10namespace JPH
11{
12 class SubShapeIDPair;
13 class ContactSettings;
14 class ContactManifold;
15 class Body;
16} // namespace JPH
17
19{
20public:
22 {
23 plVec3 m_vPosition;
24 plVec3 m_vNormal;
25 const plSurfaceResource* m_pSurface;
26 plTempHashedString m_sInteraction;
27 float m_fImpulseSqr;
28 float m_fDistanceSqr;
29 };
30
32 {
33 const JPH::Body* m_pBody = nullptr;
34 bool m_bStillSliding = false;
35 bool m_bStillRolling = false;
36
37 float m_fDistanceSqr;
38 plVec3 m_vContactPosition;
39 plGameObjectHandle m_hSlidePrefab;
40 plGameObjectHandle m_hRollPrefab;
41 plHashedString m_sSlideInteractionPrefab;
42 plHashedString m_sRollInteractionPrefab;
43 };
44
45 plMutex m_Mutex;
46 plWorld* m_pWorld = nullptr;
47 plVec3 m_vMainCameraPosition = plVec3::MakeZero();
48 plHybridArray<InteractionContact, 8> m_InteractionContacts; // these are spawned PER FRAME, so only a low number is necessary
49 plHybridArray<SlideAndRollInfo, 4> m_SlidingOrRollingActors;
50
51 SlideAndRollInfo* FindSlideOrRollInfo(const JPH::Body* pBody, const plVec3& vAvgPos);
52
53 void OnContact_SlideReaction(const JPH::Body& body0, const JPH::Body& body1, const JPH::ContactManifold& manifold, plBitflags<plOnJoltContact> onContact0, plBitflags<plOnJoltContact> onContact1, const plVec3& vAvgPos, const plVec3& vAvgNormal);
54
55 void OnContact_RollReaction(const JPH::Body& body0, const JPH::Body& body1, const JPH::ContactManifold& manifold, plBitflags<plOnJoltContact> onContact0, plBitflags<plOnJoltContact> onContact1, const plVec3& vAvgPos, const plVec3& vAvgNormal0);
56
57 void OnContact_ImpactReaction(const plVec3& vAvgPos, const plVec3& vAvgNormal, float fMaxImpactSqr, const plSurfaceResource* pSurface1, const plSurfaceResource* pSurface2, bool bActor1StaticOrKinematic);
58 void OnContact_SlideAndRollReaction(const JPH::Body& body0, const JPH::Body& body1, const JPH::ContactManifold& manifold, plBitflags<plOnJoltContact> onContact0, plBitflags<plOnJoltContact> onContact1, const plVec3& vAvgPos, const plVec3& vAvgNormal, plBitflags<plOnJoltContact> combinedContactFlags);
59
60 void SpawnPhysicsImpactReactions();
61 void UpdatePhysicsSlideReactions();
62 void UpdatePhysicsRollReactions();
63};
64
65class plJoltContactListener : public JPH::ContactListener
66{
67public:
68 plWorld* m_pWorld = nullptr;
69 plJoltContactEvents m_ContactEvents;
70
72 {
73 const plJoltTriggerComponent* m_pTrigger = nullptr;
74 plGameObjectHandle m_hTarget;
75 };
76
77 plMutex m_TriggerMutex;
79
80 void RemoveTrigger(const plJoltTriggerComponent* pTrigger);
81
82 virtual void OnContactAdded(const JPH::Body& body1, const JPH::Body& body2, const JPH::ContactManifold& manifold, JPH::ContactSettings& ref_settings) override;
83 virtual void OnContactPersisted(const JPH::Body& body1, const JPH::Body& body2, const JPH::ContactManifold& manifold, JPH::ContactSettings& ref_settings) override;
84
85 virtual void OnContactRemoved(const JPH::SubShapeIDPair& subShapePair) override;
86
87 void OnContact(const JPH::Body& body0, const JPH::Body& body1, const JPH::ContactManifold& manifold, JPH::ContactSettings& ref_settings, bool bPersistent);
88
89 bool ActivateTrigger(const JPH::Body& body1, const JPH::Body& body2, plUInt64 uiBody1id, plUInt64 uiBody2id);
90
91 void DeactivateTrigger(plUInt64 uiBody1id, plUInt64 uiBody2id);
92};
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition JoltContacts.h:19
Definition JoltContacts.h:66
Turns an object into a trigger that is capable of detecting when other physics objects enter its volu...
Definition JoltTriggerComponent.h:39
Definition Map.h:408
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Definition SurfaceResource.h:27
A class to use together with plHashedString for quick comparisons with temporary strings that need no...
Definition HashedString.h:151
static plVec3Template< float > MakeZero()
Definition Vec3.h:38
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
A handle to a game object.
Definition Declarations.h:76
Definition JoltContacts.h:22
Definition JoltContacts.h:32
Definition JoltContacts.h:72