Planeshift
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 
32 static const int DT_CROWDAGENT_MAX_NEIGHBOURS = 6;
33 
39 static const int DT_CROWDAGENT_MAX_CORNERS = 4;
40 
46 static const int DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS = 8;
47 
52 {
53  int idx;
54  float dist;
55 };
56 
60 {
64 };
65 
69 {
70  float radius;
71  float height;
73  float maxSpeed;
74 
77 
79 
82 
84  unsigned char updateFlags;
85 
88  unsigned char obstacleAvoidanceType;
89 
91  void* userData;
92 };
93 
95 {
103 };
104 
108 {
110  unsigned char active;
111 
113  unsigned char state;
114 
117 
120 
123 
126 
128  int nneis;
129 
132 
133  float npos[3];
134  float disp[3];
135  float dvel[3];
136  float nvel[3];
137  float vel[3];
138 
141 
143  float cornerVerts[DT_CROWDAGENT_MAX_CORNERS*3];
144 
146  unsigned char cornerFlags[DT_CROWDAGENT_MAX_CORNERS];
147 
150 
152  int ncorners;
153 
154  unsigned char targetState;
156  float targetPos[3];
160 };
161 
163 {
164  unsigned char active;
165  float initPos[3], startPos[3], endPos[3];
167  float t, tmax;
168 };
169 
174 {
180 };
181 
183 {
184  int idx;
185  float optStart[3], optEnd[3];
187 };
188 
191 class dtCrowd
192 {
193  int m_maxAgents;
194  dtCrowdAgent* m_agents;
195  dtCrowdAgent** m_activeAgents;
196  dtCrowdAgentAnimation* m_agentAnims;
197 
198  dtPathQueue m_pathq;
199 
201  dtObstacleAvoidanceQuery* m_obstacleQuery;
202 
203  dtProximityGrid* m_grid;
204 
205  dtPolyRef* m_pathResult;
206  int m_maxPathResult;
207 
208  float m_ext[3];
209  dtQueryFilter m_filter;
210 
211  float m_maxAgentRadius;
212 
213  int m_velocitySampleCount;
214 
215  dtNavMeshQuery* m_navquery;
216 
217  void updateTopologyOptimization(dtCrowdAgent** agents, const int nagents, const float dt);
218  void updateMoveRequest(const float dt);
219  void checkPathValidity(dtCrowdAgent** agents, const int nagents, const float dt);
220 
221  inline int getAgentIndex(const dtCrowdAgent* agent) const { return agent - m_agents; }
222 
223  bool requestMoveTargetReplan(const int idx, dtPolyRef ref, const float* pos);
224 
225  void purge();
226 
227 public:
228  dtCrowd();
229  ~dtCrowd();
230 
236  bool init(const int maxAgents, const float maxAgentRadius, dtNavMesh* nav);
237 
241  void setObstacleAvoidanceParams(const int idx, const dtObstacleAvoidanceParams* params);
242 
247  const dtObstacleAvoidanceParams* getObstacleAvoidanceParams(const int idx) const;
248 
252  const dtCrowdAgent* getAgent(const int idx);
253 
256  const int getAgentCount() const;
257 
262  int addAgent(const float* pos, const dtCrowdAgentParams* params);
263 
267  void updateAgentParameters(const int idx, const dtCrowdAgentParams* params);
268 
271  void removeAgent(const int idx);
272 
278  bool requestMoveTarget(const int idx, dtPolyRef ref, const float* pos);
279 
284  bool requestMoveVelocity(const int idx, const float* vel);
285 
289  bool resetMoveTarget(const int idx);
290 
295  int getActiveAgents(dtCrowdAgent** agents, const int maxAgents);
296 
300  void update(const float dt, dtCrowdAgentDebugInfo* debug);
301 
304  const dtQueryFilter* getFilter() const { return &m_filter; }
305 
308  dtQueryFilter* getEditableFilter() { return &m_filter; }
309 
312  const float* getQueryExtents() const { return m_ext; }
313 
316  inline int getVelocitySampleCount() const { return m_velocitySampleCount; }
317 
320  const dtProximityGrid* getGrid() const { return m_grid; }
321 
324  const dtPathQueue* getPathQueue() const { return &m_pathq; }
325 
327  const dtNavMeshQuery* getNavMeshQuery() const { return m_navquery; }
328 };
329 
334 
338 void dtFreeCrowd(dtCrowd* ptr);
339 
340 
341 #endif // DETOURCROWD_H
342 
344 
345 // This section contains detailed documentation for members that don't have
346 // a source file. It reduces clutter in the main section of the header.
347 
float maxSpeed
Maximum allowed speed. [Limit: >= 0].
Definition: DetourCrowd.h:73
Represents an agent managed by a dtCrowd object.
Definition: DetourCrowd.h:107
dtCrowdAgentParams params
The agent's configuration parameters.
Definition: DetourCrowd.h:140
float dist
The distance between the current agent and the neighbor.
Definition: DetourCrowd.h:54
unsigned int dtPolyRef
A handle to a polygon within a navigation mesh tile.
Definition: DetourNavMesh.h:30
The agent is traversing an off-mesh connection.
Definition: DetourCrowd.h:63
int nneis
The number of neighbors.
Definition: DetourCrowd.h:128
Represents a dynamic polygon corridor used to plan agent movement. ,.
static const int DT_CROWDAGENT_MAX_CORNERS
The maximum number of corners a crowd agent will look ahead in the path. This value is used for sizin...
Definition: DetourCrowd.h:39
Provides local steering behaviors for a group of agents.
Definition: DetourCrowd.h:191
float pathOptimizationRange
The path visibility optimization range. [Limit: > 0].
Definition: DetourCrowd.h:78
int ncorners
The number of corners.
Definition: DetourCrowd.h:152
dtPathQueueRef targetPathqRef
Path finder ref.
Definition: DetourCrowd.h:157
int idx
The index of the neighbor in the crowd.
Definition: DetourCrowd.h:53
dtPolyRef targetRef
Target polyref of the movement request.
Definition: DetourCrowd.h:155
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
Provides neighbor data for agents managed by the crowd.
Definition: DetourCrowd.h:51
unsigned char targetState
State of the movement request.
Definition: DetourCrowd.h:154
The agent is traversing a normal navigation mesh polygon.
Definition: DetourCrowd.h:62
dtQueryFilter * getEditableFilter()
Gets the filter used by the crowd.
Definition: DetourCrowd.h:308
Defines polygon filtering and traversal costs for navigation mesh query operations.
const float * getQueryExtents() const
Gets the search extents [(x, y, z)] used by the crowd for query operations.
Definition: DetourCrowd.h:312
A navigation mesh based on tiles of convex polygons.
UpdateFlags
Crowd agent update flags.
Definition: DetourCrowd.h:173
unsigned char obstacleAvoidanceType
The index of the avoidance configuration to use for the agent. [Limits: 0 <= value <= DT_CROWD_MAX_OB...
Definition: DetourCrowd.h:88
The agent is not in a valid state.
Definition: DetourCrowd.h:61
float height
Agent height. [Limit: > 0].
Definition: DetourCrowd.h:71
dtCrowd * dtAllocCrowd()
Allocates a crowd object using the Detour allocator.
unsigned int dtPathQueueRef
unsigned char active
1 if the agent is active, or 0 if the agent is in an unused slot in the agent pool.
Definition: DetourCrowd.h:110
unsigned char active
Definition: DetourCrowd.h:164
const dtProximityGrid * getGrid() const
Gets the crowd&#39;s proximity grid.
Definition: DetourCrowd.h:320
Use dtPathCorridor::optimizePathVisibility() to optimize the agent path.
Definition: DetourCrowd.h:178
const dtQueryFilter * getFilter() const
Gets the filter used by the crowd.
Definition: DetourCrowd.h:304
bool targetReplan
Flag indicating that the current path is being replanned.
Definition: DetourCrowd.h:158
Use dtPathCorridor::optimizePathTopology() to optimize the agent path.
Definition: DetourCrowd.h:179
float desiredSpeed
The desired speed.
Definition: DetourCrowd.h:131
unsigned char updateFlags
Flags that impact steering behavior. (See: UpdateFlags)
Definition: DetourCrowd.h:84
MoveRequestState
Definition: DetourCrowd.h:94
float collisionQueryRange
Defines how close a collision element must be before it is considered for steering behaviors...
Definition: DetourCrowd.h:76
float separationWeight
How aggresive the agent manager should be at avoiding collisions with this agent. [Limit: >= 0]...
Definition: DetourCrowd.h:81
unsigned char state
The type of mesh polygon the agent is traversing. (See: CrowdAgentState)
Definition: DetourCrowd.h:113
const dtPathQueue * getPathQueue() const
Gets the crowd&#39;s path request queue.
Definition: DetourCrowd.h:324
float topologyOptTime
Time since the agent&#39;s path corridor was optimized.
Definition: DetourCrowd.h:122
void dtFreeCrowd(dtCrowd *ptr)
Frees the specified crowd object using the Detour allocator.
dtObstacleAvoidanceDebugData * vod
Definition: DetourCrowd.h:186
dtLocalBoundary boundary
The local boundary data for the agent.
Definition: DetourCrowd.h:119
Configuration parameters for a crowd agent.
Definition: DetourCrowd.h:68
dtPathCorridor corridor
The path corridor the agent is using.
Definition: DetourCrowd.h:116
static const int DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS
The maximum number of crowd avoidance configurations supported by the crowd manager.
Definition: DetourCrowd.h:46
void * userData
User defined data attached to the agent.
Definition: DetourCrowd.h:91
CrowdAgentState
The type of navigation mesh polygon the agent is currently traversing.
Definition: DetourCrowd.h:59
Provides the ability to perform pathfinding related queries against a navigation mesh.
float targetReplanTime
Definition: DetourCrowd.h:159
float radius
Agent radius. [Limit: >= 0].
Definition: DetourCrowd.h:70
const dtNavMeshQuery * getNavMeshQuery() const
Gets the query object used by the crowd.
Definition: DetourCrowd.h:327
float maxAcceleration
Maximum allowed acceleration. [Limit: >= 0].
Definition: DetourCrowd.h:72
int getVelocitySampleCount() const
Gets the velocity sample count.
Definition: DetourCrowd.h:316