Plasma Engine  2.0
Loading...
Searching...
No Matches
JoltGrabObjectComponent.h
1#pragma once
2
3#include <Foundation/Communication/Message.h>
4#include <JoltPlugin/Actors/JoltDynamicActorComponent.h>
5
6namespace JPH
7{
8 class SixDOFConstraint;
9}
10
12
21class PL_JOLTPLUGIN_DLL plJoltGrabObjectComponent : public plComponent
22{
24
26 // plComponent
27
28public:
29 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
30 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
31
32protected:
33 virtual void OnSimulationStarted() override;
34 virtual void OnDeactivated() override;
35
37 // plJoltGrabObjectComponent
38
39public:
42
45 bool FindNearbyObject(plGameObject*& out_pObject, plTransform& out_localGrabPoint) const;
46
48 bool GrabObject(plGameObject* pObjectToGrab, const plTransform& localGrabPoint);
49
51 bool GrabNearbyObject(); // [ scriptable ]
52
54 bool HasObjectGrabbed() const; // [ scriptable ]
55
57 plComponentHandle GetGrabbedActor() const { return m_hGrabbedActor; }
58
60 float GetGrabbedActorMass() const { return m_fGrabbedActorInverseMass > 0.0f ? 1.0f / m_fGrabbedActorInverseMass : 0.0f; }
61
63 void DropGrabbedObject(); // [ scriptable ]
64
66 void ThrowGrabbedObject(const plVec3& vRelativeDir); // [ scriptable ]
67
71 void BreakObjectGrab(); // [ scriptable ]
72
74 float m_fBreakDistance = 0.5f; // [ property ]
75
78 float m_fSpringStiffness = 50.0f; // [ property ]
79
81 float m_fSpringDamping = 10.0f; // [ property ]
82
84 float m_fMaxGrabPointDistance = 2.0f; // [ property ]
85
88 float m_fCastRadius = 0.0f; // [ property ]
89
91 plUInt8 m_uiCollisionLayer = 0; // [ property ]
92
94 float m_fAllowGrabAnyObjectWithSize = 0.75f; // [ property ]
95
96 void SetAttachToReference(const char* szReference); // [ property ]
97
101
102protected:
103 void Update();
104 void ReleaseGrabbedObject();
105
106 plJoltDynamicActorComponent* GetAttachToActor();
107 plResult DetermineGrabPoint(const plComponent* pActor, plTransform& out_LocalGrabPoint) const;
108 void CreateJoint(plJoltDynamicActorComponent* pParent, plJoltDynamicActorComponent* pChild);
109 void DetectDistanceViolation(plJoltDynamicActorComponent* pGrabbedActor);
110 bool IsCharacterStandingOnObject(plGameObjectHandle hActorToGrab) const;
111
112 void OnMsgReleaseObjectGrab(plMsgReleaseObjectGrab& msg); // [ message handler ]
113
114 plComponentHandle m_hGrabbedActor;
115 float m_fGrabbedActorGravity = 1.0f;
116 float m_fGrabbedActorInverseMass = 0.0f;
117
118 plTime m_LastValidTime;
119 plTransform m_ChildAnchorLocal;
120 plComponentHandle m_hCharacterControllerComponent;
121 JPH::SixDOFConstraint* m_pConstraint = nullptr;
122
123private:
124 const char* DummyGetter() const { return nullptr; }
125};
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
Simple component manager implementation that calls an update method on all components every frame.
Definition ComponentManager.h:142
This class represents an object inside the world.
Definition GameObject.h:32
Turns an object into a fully physically simulated movable object.
Definition JoltDynamicActorComponent.h:35
Used to 'grab' physical objects and attach them to an object. For player objects to pick up objects.
Definition JoltGrabObjectComponent.h:22
float GetGrabbedActorMass() const
Returns the grabbed object's mass.
Definition JoltGrabObjectComponent.h:60
plComponentHandle GetGrabbedActor() const
Returns the grabbed object's actor component.
Definition JoltGrabObjectComponent.h:57
plGameObjectHandle m_hAttachTo
Definition JoltGrabObjectComponent.h:100
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 component.
Definition Declarations.h:138
A handle to a game object.
Definition Declarations.h:76
Send this to components such as plJoltGrabObjectComponent to demand that m_hGrabbedObjectToRelease sh...
Definition PhysicsWorldModule.h:230
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12