Recast Navigation
Navigation-mesh Toolset for Games
|
Provides local steering behaviors for a group of agents. More...
#include <DetourCrowd.h>
Public Member Functions | |
dtCrowd () | |
~dtCrowd () | |
bool | init (const int maxAgents, const float maxAgentRadius, dtNavMesh *nav) |
Initializes the crowd. | |
void | setObstacleAvoidanceParams (const int idx, const dtObstacleAvoidanceParams *params) |
Sets the shared avoidance configuration for the specified index. | |
const dtObstacleAvoidanceParams * | getObstacleAvoidanceParams (const int idx) const |
Gets the shared avoidance configuration for the specified index. | |
const dtCrowdAgent * | getAgent (const int idx) |
Gets the specified agent from the pool. | |
dtCrowdAgent * | getEditableAgent (const int idx) |
Gets the specified agent from the pool. | |
int | getAgentCount () const |
The maximum number of agents that can be managed by the object. | |
int | addAgent (const float *pos, const dtCrowdAgentParams *params) |
Adds a new agent to the crowd. | |
void | updateAgentParameters (const int idx, const dtCrowdAgentParams *params) |
Updates the specified agent's configuration. | |
void | removeAgent (const int idx) |
Removes the agent from the crowd. | |
bool | requestMoveTarget (const int idx, dtPolyRef ref, const float *pos) |
Submits a new move request for the specified agent. | |
bool | requestMoveVelocity (const int idx, const float *vel) |
Submits a new move request for the specified agent. | |
bool | resetMoveTarget (const int idx) |
Resets any request for the specified agent. | |
int | getActiveAgents (dtCrowdAgent **agents, const int maxAgents) |
Gets the active agents int the agent pool. | |
void | update (const float dt, dtCrowdAgentDebugInfo *debug) |
Updates the steering and positions of all agents. | |
const dtQueryFilter * | getFilter (const int i) const |
Gets the filter used by the crowd. | |
dtQueryFilter * | getEditableFilter (const int i) |
Gets the filter used by the crowd. | |
const float * | getQueryHalfExtents () const |
Gets the search halfExtents [(x, y, z)] used by the crowd for query operations. | |
const float * | getQueryExtents () const |
Same as getQueryHalfExtents. | |
int | getVelocitySampleCount () const |
Gets the velocity sample count. | |
const dtProximityGrid * | getGrid () const |
Gets the crowd's proximity grid. | |
const dtPathQueue * | getPathQueue () const |
Gets the crowd's path request queue. | |
const dtNavMeshQuery * | getNavMeshQuery () const |
Gets the query object used by the crowd. | |
Provides local steering behaviors for a group of agents.
This is the core class of the Crowd module. See the Crowd documentation for a summary of the crowd features.
A common method for setting up the crowd is as follows:
A common process for managing the crowd is as follows:
Some agent configuration settings can be updated using updateAgentParameters(). But the crowd owns the agent position. So it is not possible to update an active agent's position. If agent position must be fed back into the crowd, the agent must be removed and re-added.
Notes:
dtCrowd::dtCrowd | ( | ) |
dtCrowd::~dtCrowd | ( | ) |
int dtCrowd::addAgent | ( | const float * | pos, |
const dtCrowdAgentParams * | params | ||
) |
Adds a new agent to the crowd.
[in] | pos | The requested position of the agent. [(x, y, z)] |
[in] | params | The configuration of the agent. |
The agent's position will be constrained to the surface of the navigation mesh.
int dtCrowd::getActiveAgents | ( | dtCrowdAgent ** | agents, |
const int | maxAgents | ||
) |
Gets the active agents int the agent pool.
[out] | agents | An array of agent pointers. [(dtCrowdAgent *) * maxAgents] |
[in] | maxAgents | The size of the crowd agent array. |
agents
. const dtCrowdAgent * dtCrowd::getAgent | ( | const int | idx | ) |
Gets the specified agent from the pool.
[in] | idx | The agent index. [Limits: 0 <= value < getAgentCount()] |
Agents in the pool may not be in use. Check dtCrowdAgent.active before using the returned object.
int dtCrowd::getAgentCount | ( | ) | const |
The maximum number of agents that can be managed by the object.
dtCrowdAgent * dtCrowd::getEditableAgent | ( | const int | idx | ) |
Gets the specified agent from the pool.
Agents in the pool may not be in use.
[in] | idx | The agent index. [Limits: 0 <= value < getAgentCount()] |
Check dtCrowdAgent.active before using the returned object.
|
inline |
Gets the filter used by the crowd.
|
inline |
Gets the filter used by the crowd.
|
inline |
Gets the crowd's proximity grid.
|
inline |
Gets the query object used by the crowd.
const dtObstacleAvoidanceParams * dtCrowd::getObstacleAvoidanceParams | ( | const int | idx | ) | const |
Gets the shared avoidance configuration for the specified index.
[in] | idx | The index of the configuration to retreive. [Limits: 0 <= value < DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS] |
|
inline |
Gets the crowd's path request queue.
|
inline |
Same as getQueryHalfExtents.
Left to maintain backwards compatibility.
|
inline |
Gets the search halfExtents [(x, y, z)] used by the crowd for query operations.
|
inline |
Gets the velocity sample count.
bool dtCrowd::init | ( | const int | maxAgents, |
const float | maxAgentRadius, | ||
dtNavMesh * | nav | ||
) |
Initializes the crowd.
[in] | maxAgents | The maximum number of agents the crowd can manage. [Limit: >= 1] |
[in] | maxAgentRadius | The maximum radius of any agent that will be added to the crowd. [Limit: > 0] |
[in] | nav | The navigation mesh to use for planning. |
May be called more than once to purge and re-initialize the crowd.
void dtCrowd::removeAgent | ( | const int | idx | ) |
Removes the agent from the crowd.
[in] | idx | The agent index. [Limits: 0 <= value < getAgentCount()] |
The agent is deactivated and will no longer be processed. Its dtCrowdAgent object is not removed from the pool. It is marked as inactive so that it is available for reuse.
bool dtCrowd::requestMoveTarget | ( | const int | idx, |
dtPolyRef | ref, | ||
const float * | pos | ||
) |
Submits a new move request for the specified agent.
[in] | idx | The agent index. [Limits: 0 <= value < getAgentCount()] |
[in] | ref | The position's polygon reference. |
[in] | pos | The position within the polygon. [(x, y, z)] |
This method is used when a new target is set.
The position will be constrained to the surface of the navigation mesh.
The request will be processed during the next update().
bool dtCrowd::requestMoveVelocity | ( | const int | idx, |
const float * | vel | ||
) |
Submits a new move request for the specified agent.
[in] | idx | The agent index. [Limits: 0 <= value < getAgentCount()] |
[in] | vel | The movement velocity. [(x, y, z)] |
bool dtCrowd::resetMoveTarget | ( | const int | idx | ) |
Resets any request for the specified agent.
[in] | idx | The agent index. [Limits: 0 <= value < getAgentCount()] |
void dtCrowd::setObstacleAvoidanceParams | ( | const int | idx, |
const dtObstacleAvoidanceParams * | params | ||
) |
Sets the shared avoidance configuration for the specified index.
[in] | idx | The index. [Limits: 0 <= value < DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS] |
[in] | params | The new configuration. |
void dtCrowd::update | ( | const float | dt, |
dtCrowdAgentDebugInfo * | debug | ||
) |
Updates the steering and positions of all agents.
[in] | dt | The time, in seconds, to update the simulation. [Limit: > 0] |
[out] | debug | A debug object to load with debug information. [Opt] |
void dtCrowd::updateAgentParameters | ( | const int | idx, |
const dtCrowdAgentParams * | params | ||
) |
Updates the specified agent's configuration.
[in] | idx | The agent index. [Limits: 0 <= value < getAgentCount()] |
[in] | params | The new agent configuration. |