From c5e1abb08cff426d25b820d6beb0051142de5a70 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sat, 30 Mar 2024 22:29:43 +0100 Subject: [PATCH] Add setter for crword agent position and velocity --- Source/Engine/Navigation/NavCrowd.cpp | 18 ++++++++++++++++++ Source/Engine/Navigation/NavCrowd.h | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Source/Engine/Navigation/NavCrowd.cpp b/Source/Engine/Navigation/NavCrowd.cpp index f933ea12f..9cadabc5c 100644 --- a/Source/Engine/Navigation/NavCrowd.cpp +++ b/Source/Engine/Navigation/NavCrowd.cpp @@ -104,6 +104,15 @@ Vector3 NavCrowd::GetAgentPosition(int32 id) const return result; } +void NavCrowd::SetAgentPosition(int32 id, const Vector3& position) +{ + dtCrowdAgent* agent = _crowd->getEditableAgent(id); + if (agent) + { + *(Float3*)agent->npos = Float3(position); + } +} + Vector3 NavCrowd::GetAgentVelocity(int32 id) const { Vector3 result = Vector3::Zero; @@ -115,6 +124,15 @@ Vector3 NavCrowd::GetAgentVelocity(int32 id) const return result; } +void NavCrowd::SetAgentVelocity(int32 id, const Vector3& velocity) +{ + dtCrowdAgent* agent = _crowd->getEditableAgent(id); + if (agent) + { + *(Float3*)agent->nvel = Float3(velocity); + } +} + void NavCrowd::SetAgentProperties(int32 id, const NavAgentProperties& properties) { dtCrowdAgentParams agentParams; diff --git a/Source/Engine/Navigation/NavCrowd.h b/Source/Engine/Navigation/NavCrowd.h index c69f789be..135a23eba 100644 --- a/Source/Engine/Navigation/NavCrowd.h +++ b/Source/Engine/Navigation/NavCrowd.h @@ -63,6 +63,13 @@ public: /// The agent current position. API_FUNCTION() Vector3 GetAgentPosition(int32 id) const; + /// + /// Sets the agent current position. + /// + /// The agent ID. + /// The agent position. + API_FUNCTION() void SetAgentPosition(int32 id, const Vector3& position); + /// /// Gets the agent current velocity (direction * speed). /// @@ -70,6 +77,13 @@ public: /// The agent current velocity (direction * speed). API_FUNCTION() Vector3 GetAgentVelocity(int32 id) const; + /// + /// Sets the agent current velocity (direction * speed). + /// + /// The agent ID. + /// The agent velocity (direction * speed). + API_FUNCTION() void SetAgentVelocity(int32 id, const Vector3& velocity); + /// /// Updates the agent properties. ///