Plasma Engine  2.0
Loading...
Searching...
No Matches
JoltConstraintComponent.h
1#pragma once
2
3#include <Core/World/ComponentManager.h>
4#include <JoltPlugin/Declarations.h>
5
7
8namespace JPH
9{
10 class Body;
11}
12
13namespace JPH
14{
15 class Constraint;
16}
17
20{
21 using StorageType = plInt8;
22
23 enum Enum
24 {
27 // SoftLimit,
28
29 Default = NoLimit
30 };
31};
32
33PL_DECLARE_REFLECTABLE_TYPE(PL_JOLTPLUGIN_DLL, plJoltConstraintLimitMode);
34
37{
38 using StorageType = plInt8;
39
40 enum Enum
41 {
45
46 Default = NoDrive
47 };
48};
49
50PL_DECLARE_REFLECTABLE_TYPE(PL_JOLTPLUGIN_DLL, plJoltConstraintDriveMode);
51
53
72class PL_JOLTPLUGIN_DLL plJoltConstraintComponent : public plComponent
73{
74 PL_DECLARE_ABSTRACT_COMPONENT_TYPE(plJoltConstraintComponent, plComponent);
75
77 // plComponent
78
79public:
80 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
81 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
82
83protected:
84 virtual void OnSimulationStarted() override;
85 virtual void OnDeactivated() override;
86
88 // plJoltConstraintComponent
89
90public:
93
95 void BreakConstraint();
96
98 void SetBreakForce(float value); // [ property ]
99 float GetBreakForce() const { return m_fBreakForce; } // [ property ]
100
102 void SetBreakTorque(float value); // [ property ]
103 float GetBreakTorque() const { return m_fBreakTorque; } // [ property ]
104
106 void SetPairCollision(bool value); // [ property ]
107 bool GetPairCollision() const { return m_bPairCollision; } // [ property ]
108
109 void SetParentActorReference(const char* szReference); // [ property ]
110 void SetChildActorReference(const char* szReference); // [ property ]
111 void SetChildActorAnchorReference(const char* szReference); // [ property ]
112
114 void SetParentActor(plGameObjectHandle hActor);
116 void SetChildActor(plGameObjectHandle hActor);
118 void SetChildActorAnchor(plGameObjectHandle hActor);
119
121 void SetActors(plGameObjectHandle hActorA, const plTransform& localFrameA, plGameObjectHandle hActorB, const plTransform& localFrameB);
122
124 void OnJoltMsgDisconnectConstraints(plJoltMsgDisconnectConstraints& ref_msg); // [ msg handler ]
125
126protected:
127 friend class plJoltWorldModule;
128
129 virtual bool ExceededBreakingPoint() = 0;
130 virtual void ApplySettings() = 0;
131
132 plResult FindParentBody(plUInt32& out_uiJoltBodyID, plJoltDynamicActorComponent*& pRbComp);
133 plResult FindChildBody(plUInt32& out_uiJoltBodyID, plJoltDynamicActorComponent*& pRbComp);
134
135 virtual void CreateContstraintType(JPH::Body* pBody0, JPH::Body* pBody1) = 0;
136
137 plTransform ComputeParentBodyGlobalFrame() const;
138 plTransform ComputeChildBodyGlobalFrame() const;
139
140 void QueueApplySettings();
141
142 plGameObjectHandle m_hActorA;
143 plGameObjectHandle m_hActorB;
144 plGameObjectHandle m_hActorBAnchor;
145
146 // UserFlag0 specifies whether m_localFrameA is already set
147 plTransform m_LocalFrameA;
148 // UserFlag1 specifies whether m_localFrameB is already set
149 plTransform m_LocalFrameB;
150
151 JPH::Constraint* m_pConstraint = nullptr;
152
153 float m_fBreakForce = 0.0f;
154 float m_fBreakTorque = 0.0f;
155 bool m_bPairCollision = true;
156
157private:
158 const char* DummyGetter() const { return nullptr; }
159};
Base class of all component types.
Definition Component.h:25
virtual void SerializeComponent(plWorldWriter &inout_stream) const
Override this to save the current state of the component to the given stream.
Definition Component.cpp:54
virtual void OnDeactivated()
This method is called when the component gets deactivated.
Definition Component.cpp:142
virtual void OnSimulationStarted()
This method is called once for active components, at the start of the next world update,...
Definition Component.cpp:144
virtual void DeserializeComponent(plWorldReader &inout_stream)
Override this to load the current state of the component from the given stream.
Definition Component.cpp:58
Base class for all Jolt physics joints (constraints).
Definition JoltConstraintComponent.h:73
Turns an object into a fully physically simulated movable object.
Definition JoltDynamicActorComponent.h:35
Definition JoltWorldModule.h:29
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
A handle to a game object.
Definition Declarations.h:76
Configures how a drive on a constraint works.
Definition JoltConstraintComponent.h:37
Enum
Definition JoltConstraintComponent.h:41
@ DrivePosition
The drive attempts to reach a target position (or angle).
Definition JoltConstraintComponent.h:44
@ DriveVelocity
The drive attempts to reach a target velocity (of rotation or motion).
Definition JoltConstraintComponent.h:43
@ NoDrive
The constraint has no drive.
Definition JoltConstraintComponent.h:42
Configures how a physics constraint's limit acts.
Definition JoltConstraintComponent.h:20
Enum
Definition JoltConstraintComponent.h:24
@ NoLimit
The constraint has no limit.
Definition JoltConstraintComponent.h:25
@ HardLimit
The constraint has a hard limit, no soft spring is used to prevent further movement.
Definition JoltConstraintComponent.h:26
This message can be sent to a constraint component to break the constraint.
Definition Declarations.h:90
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54