Plasma Engine  2.0
Loading...
Searching...
No Matches
DetourCrowdAgentComponent.h
1#pragma once
2
3#include <Core/World/Component.h>
4#include <Core/World/World.h>
5#include <RecastPlugin/Components/AgentSteeringComponent.h>
6#include <RecastPlugin/RecastPluginDLL.h>
7
11
13
15{
16 using StorageType = plUInt8;
17
18 enum Enum
19 {
20 LookAtNextPathCorner,
21 MatchVelocityDirection,
22
23 Default = LookAtNextPathCorner
24 };
25};
26
27PL_DECLARE_REFLECTABLE_TYPE(PL_RECASTPLUGIN_DLL, plDetourCrowdAgentRotationMode);
28
30
31class PL_RECASTPLUGIN_DLL plDetourCrowdAgentComponentManager : public plComponentManager<plDetourCrowdAgentComponent, plBlockStorageType::FreeList>
32{
34
35public:
38
39 virtual void Initialize() override;
40
41 plDetourCrowdWorldModule* GetDetourCrowdWorldModule() const { return m_pDetourCrowdModule; }
42
43private:
44 void Update(const plWorldModule::UpdateContext& ctx);
45
46 plUInt32 m_uiNextOwnerId = 1;
47 plDetourCrowdWorldModule* m_pDetourCrowdModule = nullptr;
48};
49
51
59class PL_RECASTPLUGIN_DLL plDetourCrowdAgentComponent : public plAgentSteeringComponent
60{
62
64 // plComponent
65
66protected:
67 virtual void SerializeComponent(plWorldWriter& stream) const override;
68 virtual void DeserializeComponent(plWorldReader& stream) override;
69
71 // plAgentSteeringComponent
72
73public:
76
81 virtual void SetTargetPosition(const plVec3& vPosition) override;
82 virtual plVec3 GetTargetPosition() const override { return m_vTargetPosition; }
83 virtual void ClearTargetPosition() override;
84 virtual plAgentPathFindingState::Enum GetPathToTargetState() const override { return m_PathToTargetState; }
85
87 // Properties
88protected:
89 float m_fRadius = 0.3f; // [ property ]
90 float m_fHeight = 1.8f; // [ property ]
91 float m_fMaxSpeed = 3.5f; // [ property ]
92 float m_fMaxAcceleration = 3.5f; // [property]
93 float m_fStoppingDistance = 1.0f; // [property]
94 plAngle m_MaxAngularSpeed = plAngle::MakeFromDegree(360.0f); // [property]
95 plEnum<plDetourCrowdAgentRotationMode> m_RotationMode; // [property]
96 float m_fPushiness = 2.0f; // [property]
97
98public:
99 float GetRadius() const { return m_fRadius; }
100 float GetHeight() const { return m_fHeight; }
101 float GetMaxSpeed() const { return m_fMaxSpeed; }
102 float GetMaxAcceleration() const { return m_fMaxAcceleration; }
103 float GetStoppingDistance() const { return m_fStoppingDistance; }
104 plAngle GetMaxAngularSpeed() const { return m_MaxAngularSpeed; }
107 plVec3 GetActualTargetPosition() const { return m_vActualTargetPosition; }
108 plDetourCrowdAgentRotationMode::Enum GetRotationMode() const { return m_RotationMode; }
109 float GetPushiness() const { return m_fPushiness; }
110
111 void SetRadius(float fRadius);
112 void SetHeight(float fHeight);
113 void SetMaxSpeed(float fMaxSpeed);
114 void SetMaxAcceleration(float fMaxAcceleration);
116 void SetStoppingDistance(float fStoppingDistance);
117 void SetMaxAngularSpeed(plAngle maxAngularSpeed);
118 void SetRotationMode(plDetourCrowdAgentRotationMode::Enum rotationMode) { m_RotationMode = rotationMode; }
121 void SetPushiness(float fPushiness);
122
123 plVec3 GetVelocity() const { return m_vVelocity; }
124 plAngle GetAngularSpeed() const { return m_AngularSpeed; }
125
127 // Other
128protected:
129 void FillAgentParams(plDetourCrowdAgentParams& out_params) const;
130
131 virtual void OnDeactivated() override;
132
133 plQuat RotateTowardsDirection(const plQuat& qCurrentRot, const plVec3& vTargetDir, plAngle& out_angularSpeed) const;
134 plVec3 GetDirectionToNextPathCorner(const plVec3& vCurrentPos, const struct dtCrowdAgent* pDtAgent) const;
135 bool SyncRotation(const plVec3& vPosition, plQuat& inout_qRotation, const plVec3& vVelocity, const struct dtCrowdAgent* pDtAgent);
136
137 void SyncTransform(const struct dtCrowdAgent* pDtAgent, bool bTeleport);
138
139 plUInt8 m_uiTargetDirtyBit : 1;
140 plUInt8 m_uiSteeringFailedBit : 1;
141 plUInt8 m_uiErrorBit : 1;
142 plUInt8 m_uiParamsDirtyBit : 1;
143
144 plInt32 m_iAgentId = -1;
145 plUInt32 m_uiOwnerId = 0;
146 plVec3 m_vVelocity;
147 plAngle m_AngularSpeed;
148 plVec3 m_vTargetPosition;
149 plVec3 m_vActualTargetPosition;
150 plEnum<plAgentPathFindingState> m_PathToTargetState;
151};
Base class for components that implement 'agent steering' behavior. If, moving from point A to point ...
Definition AgentSteeringComponent.h:44
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
Definition ComponentManager.h:88
Implements navigation, path following and obstacle avoidance. Requires Recast navmesh.
Definition DetourCrowdAgentComponent.h:60
plVec3 GetActualTargetPosition() const
While GetTargetPosition() returns the requested target position, this one will return the actual poin...
Definition DetourCrowdAgentComponent.h:107
Definition DetourCrowdAgentComponent.h:32
Definition DetourCrowdWorldModule.h:46
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
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
Definition DetourCrowdWorldModule.h:13
Definition DetourCrowdAgentComponent.h:15
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition WorldModule.h:33