Recast Navigation
Navigation-mesh Toolset for Games
Loading...
Searching...
No Matches
DetourCrowd.h
Go to the documentation of this file.
1//
2// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
3//
4// This software is provided 'as-is', without any express or implied
5// warranty. In no event will the authors be held liable for any damages
6// arising from the use of this software.
7// Permission is granted to anyone to use this software for any purpose,
8// including commercial applications, and to alter it and redistribute it
9// freely, subject to the following restrictions:
10// 1. The origin of this software must not be misrepresented; you must not
11// claim that you wrote the original software. If you use this software
12// in a product, an acknowledgment in the product documentation would be
13// appreciated but is not required.
14// 2. Altered source versions must be plainly marked as such, and must not be
15// misrepresented as being the original software.
16// 3. This notice may not be removed or altered from any source distribution.
17//
18
19#ifndef DETOURCROWD_H
20#define DETOURCROWD_H
21
22#include "DetourNavMeshQuery.h"
24#include "DetourLocalBoundary.h"
25#include "DetourPathCorridor.h"
26#include "DetourProximityGrid.h"
27#include "DetourPathQueue.h"
28
32static const int DT_CROWDAGENT_MAX_NEIGHBOURS = 6;
33
39static const int DT_CROWDAGENT_MAX_CORNERS = 4;
40
47
52static const int DT_CROWD_MAX_QUERY_FILTER_TYPE = 16;
53
58{
59 int idx;
60 float dist;
61};
62
71
75{
76 float radius;
77 float height;
79 float maxSpeed;
80
83
85
88
90 unsigned char updateFlags;
91
94 unsigned char obstacleAvoidanceType;
95
97 unsigned char queryFilterType;
98
100 void* userData;
101};
102
113
173
175{
176 bool active;
177 float initPos[3], startPos[3], endPos[3];
179 float t, tmax;
180};
181
193
200
204{
205 int m_maxAgents;
206 dtCrowdAgent* m_agents;
207 dtCrowdAgent** m_activeAgents;
208 dtCrowdAgentAnimation* m_agentAnims;
209
210 dtPathQueue m_pathq;
211
213 dtObstacleAvoidanceQuery* m_obstacleQuery;
214
215 dtProximityGrid* m_grid;
216
217 dtPolyRef* m_pathResult;
218 int m_maxPathResult;
219
220 float m_agentPlacementHalfExtents[3];
221
223
224 float m_maxAgentRadius;
225
226 int m_velocitySampleCount;
227
228 dtNavMeshQuery* m_navquery;
229
230 void updateTopologyOptimization(dtCrowdAgent** agents, const int nagents, const float dt);
231 void updateMoveRequest(const float dt);
232 void checkPathValidity(dtCrowdAgent** agents, const int nagents, const float dt);
233
234 inline int getAgentIndex(const dtCrowdAgent* agent) const { return (int)(agent - m_agents); }
235
236 bool requestMoveTargetReplan(const int idx, dtPolyRef ref, const float* pos);
237
238 void purge();
239
240public:
241 dtCrowd();
242 ~dtCrowd();
243
249 bool init(const int maxAgents, const float maxAgentRadius, dtNavMesh* nav);
250
254 void setObstacleAvoidanceParams(const int idx, const dtObstacleAvoidanceParams* params);
255
260 const dtObstacleAvoidanceParams* getObstacleAvoidanceParams(const int idx) const;
261
265 const dtCrowdAgent* getAgent(const int idx);
266
270 dtCrowdAgent* getEditableAgent(const int idx);
271
274 int getAgentCount() const;
275
280 int addAgent(const float* pos, const dtCrowdAgentParams* params);
281
285 void updateAgentParameters(const int idx, const dtCrowdAgentParams* params);
286
289 void removeAgent(const int idx);
290
296 bool requestMoveTarget(const int idx, dtPolyRef ref, const float* pos);
297
302 bool requestMoveVelocity(const int idx, const float* vel);
303
307 bool resetMoveTarget(const int idx);
308
313 int getActiveAgents(dtCrowdAgent** agents, const int maxAgents);
314
318 void update(const float dt, dtCrowdAgentDebugInfo* debug);
319
322 inline const dtQueryFilter* getFilter(const int i) const { return (i >= 0 && i < DT_CROWD_MAX_QUERY_FILTER_TYPE) ? &m_filters[i] : 0; }
323
326 inline dtQueryFilter* getEditableFilter(const int i) { return (i >= 0 && i < DT_CROWD_MAX_QUERY_FILTER_TYPE) ? &m_filters[i] : 0; }
327
330 const float* getQueryHalfExtents() const { return m_agentPlacementHalfExtents; }
331
334 const float* getQueryExtents() const { return m_agentPlacementHalfExtents; }
335
338 inline int getVelocitySampleCount() const { return m_velocitySampleCount; }
339
342 const dtProximityGrid* getGrid() const { return m_grid; }
343
346 const dtPathQueue* getPathQueue() const { return &m_pathq; }
347
349 const dtNavMeshQuery* getNavMeshQuery() const { return m_navquery; }
350
351private:
352 // Explicitly disabled copy constructor and copy assignment operator.
353 dtCrowd(const dtCrowd&);
354 dtCrowd& operator=(const dtCrowd&);
355};
356
361
365void dtFreeCrowd(dtCrowd* ptr);
366
367
368#endif // DETOURCROWD_H
369
371
372// This section contains detailed documentation for members that don't have
373// a source file. It reduces clutter in the main section of the header.
374
MoveRequestState
Definition DetourCrowd.h:104
@ DT_CROWDAGENT_TARGET_WAITING_FOR_PATH
Definition DetourCrowd.h:110
@ DT_CROWDAGENT_TARGET_NONE
Definition DetourCrowd.h:105
@ DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE
Definition DetourCrowd.h:109
@ DT_CROWDAGENT_TARGET_VALID
Definition DetourCrowd.h:107
@ DT_CROWDAGENT_TARGET_REQUESTING
Definition DetourCrowd.h:108
@ DT_CROWDAGENT_TARGET_VELOCITY
Definition DetourCrowd.h:111
@ DT_CROWDAGENT_TARGET_FAILED
Definition DetourCrowd.h:106
unsigned int dtPathQueueRef
Definition DetourPathQueue.h:27
Provides local steering behaviors for a group of agents.
Definition DetourCrowd.h:204
const dtProximityGrid * getGrid() const
Gets the crowd's proximity grid.
Definition DetourCrowd.h:342
int getActiveAgents(dtCrowdAgent **agents, const int maxAgents)
Gets the active agents int the agent pool.
Definition DetourCrowd.cpp:664
dtCrowd()
Definition DetourCrowd.cpp:331
int getVelocitySampleCount() const
Gets the velocity sample count.
Definition DetourCrowd.h:338
bool init(const int maxAgents, const float maxAgentRadius, dtNavMesh *nav)
Initializes the crowd.
Definition DetourCrowd.cpp:381
const dtObstacleAvoidanceParams * getObstacleAvoidanceParams(const int idx) const
Gets the shared avoidance configuration for the specified index.
Definition DetourCrowd.cpp:470
bool requestMoveVelocity(const int idx, const float *vel)
Submits a new move request for the specified agent.
Definition DetourCrowd.cpp:629
void updateAgentParameters(const int idx, const dtCrowdAgentParams *params)
Updates the specified agent's configuration.
Definition DetourCrowd.cpp:501
const dtQueryFilter * getFilter(const int i) const
Gets the filter used by the crowd.
Definition DetourCrowd.h:322
dtQueryFilter * getEditableFilter(const int i)
Gets the filter used by the crowd.
Definition DetourCrowd.h:326
bool resetMoveTarget(const int idx)
Resets any request for the specified agent.
Definition DetourCrowd.cpp:646
int getAgentCount() const
The maximum number of agents that can be managed by the object.
Definition DetourCrowd.cpp:477
const float * getQueryExtents() const
Same as getQueryHalfExtents.
Definition DetourCrowd.h:334
void setObstacleAvoidanceParams(const int idx, const dtObstacleAvoidanceParams *params)
Sets the shared avoidance configuration for the specified index.
Definition DetourCrowd.cpp:464
~dtCrowd()
Definition DetourCrowd.cpp:346
const float * getQueryHalfExtents() const
Gets the search halfExtents [(x, y, z)] used by the crowd for query operations.
Definition DetourCrowd.h:330
bool requestMoveTarget(const int idx, dtPolyRef ref, const float *pos)
Submits a new move request for the specified agent.
Definition DetourCrowd.cpp:607
dtCrowdAgent * getEditableAgent(const int idx)
Gets the specified agent from the pool.
Definition DetourCrowd.cpp:494
const dtPathQueue * getPathQueue() const
Gets the crowd's path request queue.
Definition DetourCrowd.h:346
const dtNavMeshQuery * getNavMeshQuery() const
Gets the query object used by the crowd.
Definition DetourCrowd.h:349
void update(const float dt, dtCrowdAgentDebugInfo *debug)
Updates the steering and positions of all agents.
Definition DetourCrowd.cpp:1046
int addAgent(const float *pos, const dtCrowdAgentParams *params)
Adds a new agent to the crowd.
Definition DetourCrowd.cpp:511
void removeAgent(const int idx)
Removes the agent from the crowd.
Definition DetourCrowd.cpp:572
const dtCrowdAgent * getAgent(const int idx)
Gets the specified agent from the pool.
Definition DetourCrowd.cpp:485
Definition DetourLocalBoundary.h:26
Provides the ability to perform pathfinding related queries against a navigation mesh.
Definition DetourNavMeshQuery.h:166
A navigation mesh based on tiles of convex polygons.
Definition DetourNavMesh.h:339
Definition DetourObstacleAvoidance.h:39
Definition DetourObstacleAvoidance.h:98
Represents a dynamic polygon corridor used to plan agent movement.
Definition DetourPathCorridor.h:27
Definition DetourPathQueue.h:30
Definition DetourProximityGrid.h:23
Defines polygon filtering and traversal costs for navigation mesh query operations.
Definition DetourNavMeshQuery.h:36
static const int DT_CROWD_MAX_QUERY_FILTER_TYPE
The maximum number of query filter types supported by the crowd manager.
Definition DetourCrowd.h:52
CrowdAgentState
The type of navigation mesh polygon the agent is currently traversing.
Definition DetourCrowd.h:66
static const int DT_CROWDAGENT_MAX_NEIGHBOURS
The maximum number of neighbors that a crowd agent can take into account for steering decisions.
Definition DetourCrowd.h:32
void dtFreeCrowd(dtCrowd *ptr)
Frees the specified crowd object using the Detour allocator.
Definition DetourCrowd.cpp:40
UpdateFlags
Crowd agent update flags.
Definition DetourCrowd.h:186
static const int DT_CROWDAGENT_MAX_CORNERS
The maximum number of corners a crowd agent will look ahead in the path.
Definition DetourCrowd.h:39
dtCrowd * dtAllocCrowd()
Allocates a crowd object using the Detour allocator.
Definition DetourCrowd.cpp:33
static const int DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS
The maximum number of crowd avoidance configurations supported by the crowd manager.
Definition DetourCrowd.h:46
@ DT_CROWDAGENT_STATE_OFFMESH
The agent is traversing an off-mesh connection.
Definition DetourCrowd.h:69
@ DT_CROWDAGENT_STATE_WALKING
The agent is traversing a normal navigation mesh polygon.
Definition DetourCrowd.h:68
@ DT_CROWDAGENT_STATE_INVALID
The agent is not in a valid state.
Definition DetourCrowd.h:67
@ DT_CROWD_SEPARATION
Definition DetourCrowd.h:189
@ DT_CROWD_OPTIMIZE_TOPO
Use dtPathCorridor::optimizePathTopology() to optimize the agent path.
Definition DetourCrowd.h:191
@ DT_CROWD_OPTIMIZE_VIS
Use dtPathCorridor::optimizePathVisibility() to optimize the agent path.
Definition DetourCrowd.h:190
@ DT_CROWD_OBSTACLE_AVOIDANCE
Definition DetourCrowd.h:188
@ DT_CROWD_ANTICIPATE_TURNS
Definition DetourCrowd.h:187
unsigned int dtPolyRef
A handle to a polygon within a navigation mesh tile.
Definition DetourNavMesh.h:48
Definition DetourCrowd.h:175
bool active
Definition DetourCrowd.h:176
float initPos[3]
Definition DetourCrowd.h:177
float tmax
Definition DetourCrowd.h:179
float startPos[3]
Definition DetourCrowd.h:177
dtPolyRef polyRef
Definition DetourCrowd.h:178
float t
Definition DetourCrowd.h:179
float endPos[3]
Definition DetourCrowd.h:177
Definition DetourCrowd.h:195
float optEnd[3]
Definition DetourCrowd.h:197
dtObstacleAvoidanceDebugData * vod
Definition DetourCrowd.h:198
float optStart[3]
Definition DetourCrowd.h:197
int idx
Definition DetourCrowd.h:196
Configuration parameters for a crowd agent.
Definition DetourCrowd.h:75
void * userData
User defined data attached to the agent.
Definition DetourCrowd.h:100
float maxSpeed
Maximum allowed speed. [Limit: >= 0].
Definition DetourCrowd.h:79
float maxAcceleration
Maximum allowed acceleration. [Limit: >= 0].
Definition DetourCrowd.h:78
float collisionQueryRange
Defines how close a collision element must be before it is considered for steering behaviors....
Definition DetourCrowd.h:82
float separationWeight
How aggresive the agent manager should be at avoiding collisions with this agent. [Limit: >= 0].
Definition DetourCrowd.h:87
unsigned char updateFlags
Flags that impact steering behavior. (See: UpdateFlags)
Definition DetourCrowd.h:90
float height
Agent height. [Limit: > 0].
Definition DetourCrowd.h:77
float radius
Agent radius. [Limit: >= 0].
Definition DetourCrowd.h:76
float pathOptimizationRange
The path visibility optimization range. [Limit: > 0].
Definition DetourCrowd.h:84
unsigned char obstacleAvoidanceType
The index of the avoidance configuration to use for the agent.
Definition DetourCrowd.h:94
unsigned char queryFilterType
The index of the query filter used by this agent.
Definition DetourCrowd.h:97
Represents an agent managed by a dtCrowd object.
Definition DetourCrowd.h:117
unsigned char state
The type of mesh polygon the agent is traversing. (See: CrowdAgentState)
Definition DetourCrowd.h:122
unsigned char cornerFlags[DT_CROWDAGENT_MAX_CORNERS]
The local path corridor corner flags. (See: dtStraightPathFlags) [(flags) * ncorners].
Definition DetourCrowd.h:158
dtPolyRef targetRef
Target polyref of the movement request.
Definition DetourCrowd.h:167
float targetPos[3]
Target position of the movement request (or velocity in case of DT_CROWDAGENT_TARGET_VELOCITY).
Definition DetourCrowd.h:168
dtPathQueueRef targetPathqRef
Path finder ref.
Definition DetourCrowd.h:169
unsigned char targetState
State of the movement request.
Definition DetourCrowd.h:166
int nneis
The number of neighbors.
Definition DetourCrowd.h:140
float vel[3]
The actual velocity of the agent. The change from nvel -> vel is constrained by max acceleration....
Definition DetourCrowd.h:149
float targetReplanTime
Definition DetourCrowd.h:171
bool targetReplan
Flag indicating that the current path is being replanned.
Definition DetourCrowd.h:170
bool active
True if the agent is active, false if the agent is in an unused slot in the agent pool.
Definition DetourCrowd.h:119
dtPathCorridor corridor
The path corridor the agent is using.
Definition DetourCrowd.h:128
dtLocalBoundary boundary
The local boundary data for the agent.
Definition DetourCrowd.h:131
float disp[3]
A temporary value used to accumulate agent displacement during iterative collision resolution....
Definition DetourCrowd.h:146
float topologyOptTime
Time since the agent's path corridor was optimized.
Definition DetourCrowd.h:134
int ncorners
The number of corners.
Definition DetourCrowd.h:164
dtCrowdNeighbour neis[DT_CROWDAGENT_MAX_NEIGHBOURS]
The known neighbors of the agent.
Definition DetourCrowd.h:137
float nvel[3]
The desired velocity adjusted by obstacle avoidance, calculated from scratch each frame....
Definition DetourCrowd.h:148
dtPolyRef cornerPolys[DT_CROWDAGENT_MAX_CORNERS]
The reference id of the polygon being entered at the corner. [(polyRef) * ncorners].
Definition DetourCrowd.h:161
float cornerVerts[DT_CROWDAGENT_MAX_CORNERS *3]
The local path corridor corners for the agent. (Staight path.) [(x, y, z) * ncorners].
Definition DetourCrowd.h:155
float npos[3]
The current agent position. [(x, y, z)].
Definition DetourCrowd.h:145
float desiredSpeed
The desired speed.
Definition DetourCrowd.h:143
dtCrowdAgentParams params
The agent's configuration parameters.
Definition DetourCrowd.h:152
float dvel[3]
The desired velocity of the agent. Based on the current path, calculated from scratch each frame....
Definition DetourCrowd.h:147
bool partial
True if the agent has valid path (targetState == DT_CROWDAGENT_TARGET_VALID) and the path does not le...
Definition DetourCrowd.h:125
Provides neighbor data for agents managed by the crowd.
Definition DetourCrowd.h:58
int idx
The index of the neighbor in the crowd.
Definition DetourCrowd.h:59
float dist
The distance between the current agent and the neighbor.
Definition DetourCrowd.h:60
Definition DetourObstacleAvoidance.h:84