Plasma Engine  2.0
Loading...
Searching...
No Matches
JoltRopeComponent.h
1#pragma once
2
3#include <Core/ResourceManager/ResourceHandle.h>
4#include <JoltPlugin/JoltPluginDLL.h>
5
8namespace JPH
9{
10 class Constraint;
11}
12
14
17{
18 using StorageType = plInt8;
19
20 enum Enum
21 {
26
27 Default = Point
28 };
29};
30
31PL_DECLARE_REFLECTABLE_TYPE(PL_JOLTPLUGIN_DLL, plJoltRopeAnchorConstraintMode);
32
34
35class PL_JOLTPLUGIN_DLL plJoltRopeComponentManager : public plComponentManager<class plJoltRopeComponent, plBlockStorageType::Compact>
36{
37public:
40
41 virtual void Initialize() override;
42
43private:
44 void Update(const plWorldModule::UpdateContext& context);
45};
46
48
56class PL_JOLTPLUGIN_DLL plJoltRopeComponent : public plComponent
57{
59
61 // plComponent
62
63public:
64 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
65 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
66
67protected:
68 virtual void OnSimulationStarted() override;
69 virtual void OnActivated() override;
70 virtual void OnDeactivated() override;
71
73 // plJoltRopeComponent
74
75public:
78
80 void SetGravityFactor(float fGravity); // [ property ]
81 float GetGravityFactor() const { return m_fGravityFactor; } // [ property ]
82
84 void SetSurfaceFile(const char* szFile); // [ property ]
85 const char* GetSurfaceFile() const; // [ property ]
86
88 plUInt8 m_uiCollisionLayer = 0; // [ property ]
89
91 plUInt16 m_uiPieces = 16; // [ property ]
92
94 float m_fThickness = 0.05f; // [ property ]
95
97 float m_fSlack = 0.3f; // [ property ]
98
101 bool m_bCCD = false; // [ property ]
102
104 plAngle m_MaxBend = plAngle::MakeFromDegree(30); // [ property ]
105
107 plAngle m_MaxTwist = plAngle::MakeFromDegree(15); // [ property ]
108
110 void SetAnchor1Reference(const char* szReference); // [ property ]
111
113 void SetAnchor2Reference(const char* szReference); // [ property ]
114
116 void SetAnchor1(plGameObjectHandle hActor);
117
119 void SetAnchor2(plGameObjectHandle hActor);
120
122 void AddForceAtPos(plMsgPhysicsAddForce& ref_msg);
123
125 void AddImpulseAtPos(plMsgPhysicsAddImpulse& ref_msg);
126
128 void SetAnchor1ConstraintMode(plEnum<plJoltRopeAnchorConstraintMode> mode); // [ property ]
129 plEnum<plJoltRopeAnchorConstraintMode> GetAnchor1ConstraintMode() const { return m_Anchor1ConstraintMode; } // [ property ]
130
132 void SetAnchor2ConstraintMode(plEnum<plJoltRopeAnchorConstraintMode> mode); // [ property ]
133 plEnum<plJoltRopeAnchorConstraintMode> GetAnchor2ConstraintMode() const { return m_Anchor2ConstraintMode; } // [ property ]
134
136 void OnJoltMsgDisconnectConstraints(plJoltMsgDisconnectConstraints& ref_msg); // [ msg handler ]
137
138private:
139 void CreateRope();
140 plResult CreateSegmentTransforms(plDynamicArray<plTransform>& transforms, float& out_fPieceLength, plGameObjectHandle hAnchor1, plGameObjectHandle hAnchor2);
141 void DestroyPhysicsShapes();
142 void Update();
143 void SendPreviewPose();
144 const plJoltMaterial* GetJoltMaterial();
145 JPH::Constraint* CreateConstraint(const plGameObjectHandle& hTarget, const plTransform& dstLoc, plUInt32 uiBodyID, plJoltRopeAnchorConstraintMode::Enum mode, plUInt32& out_uiConnectedToBodyID);
146 void UpdatePreview();
147
148 plSurfaceResourceHandle m_hSurface;
149
150 plGameObjectHandle m_hAnchor1;
151 plGameObjectHandle m_hAnchor2;
152
153 plEnum<plJoltRopeAnchorConstraintMode> m_Anchor1ConstraintMode; // [ property ]
154 plEnum<plJoltRopeAnchorConstraintMode> m_Anchor2ConstraintMode; // [ property ]
155
156 float m_fTotalMass = 1.0f;
157 float m_fMaxForcePerFrame = 0.0f;
158 float m_fBendStiffness = 0.0f;
159 plUInt32 m_uiObjectFilterID = plInvalidIndex;
160 plUInt32 m_uiUserDataIndex = plInvalidIndex;
161 bool m_bSelfCollision = false;
162 float m_fGravityFactor = 1.0f;
163 plUInt32 m_uiPreviewHash = 0;
164
165 JPH::Ragdoll* m_pRagdoll = nullptr;
166 JPH::Constraint* m_pConstraintAnchor1 = nullptr;
167 JPH::Constraint* m_pConstraintAnchor2 = nullptr;
168 plUInt32 m_uiAnchor1BodyID = plInvalidIndex;
169 plUInt32 m_uiAnchor2BodyID = plInvalidIndex;
170
171
172private:
173 const char* DummyGetter() const { return nullptr; }
174};
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
static constexpr plAngle MakeFromDegree(float fDegree)
Creates an instance of plAngle that was initialized from degree. (Performs a conversion)
Definition Angle_inl.h:33
Base class of all component types.
Definition Component.h:25
Definition ComponentManager.h:88
Definition DynamicArray.h:81
Definition JoltMaterial.h:7
Creates a physically simulated rope that is made up of multiple segments.
Definition JoltRopeComponent.h:57
Definition JoltRopeComponent.h:36
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
virtual void OnSimulationStarted()
This method is called at the start of the next world update when the world is simulated....
Definition WorldModule.h:105
virtual void Initialize()
This method is called after the constructor. A derived type can override this method to do initializa...
Definition WorldModule.h:98
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 custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
A handle to a game object.
Definition Declarations.h:76
This message can be sent to a constraint component to break the constraint.
Definition Declarations.h:90
How a rope end gets attached to the anchor point.
Definition JoltRopeComponent.h:17
Enum
Definition JoltRopeComponent.h:21
@ None
The rope is not attached at this anchor and will fall down here once simulation starts.
Definition JoltRopeComponent.h:22
@ Point
The rope end can rotate freely around the anchor point.
Definition JoltRopeComponent.h:23
@ Fixed
The rope end can neither move nor rotate at the anchor point.
Definition JoltRopeComponent.h:24
@ Cone
The rope end can rotate up to a maximum angle at the anchor point.
Definition JoltRopeComponent.h:25
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
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition WorldModule.h:33