// // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages // arising from the use of this software. // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it // freely, subject to the following restrictions: // 1. The origin of this software must not be misrepresented; you must not // claim that you wrote the original software. If you use this software // in a product, an acknowledgment in the product documentation would be // appreciated but is not required. // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. // #ifndef DETOURCROWD_H #define DETOURCROWD_H #include "DetourNavMeshQuery.h" #include "DetourObstacleAvoidance.h" #include "DetourLocalBoundary.h" #include "DetourPathCorridor.h" #include "DetourProximityGrid.h" #include "DetourPathQueue.h" /// The maximum number of neighbors that a crowd agent can take into account /// for steering decisions. /// @ingroup crowd static const int DT_CROWDAGENT_MAX_NEIGHBOURS = 6; /// The maximum number of corners a crowd agent will look ahead in the path. /// This value is used for sizing the crowd agent corner buffers. /// Due to the behavior of the crowd manager, the actual number of useful /// corners will be one less than this number. /// @ingroup crowd static const int DT_CROWDAGENT_MAX_CORNERS = 4; /// The maximum number of crowd avoidance configurations supported by the /// crowd manager. /// @ingroup crowd /// @see dtObstacleAvoidanceParams, dtCrowd::setObstacleAvoidanceParams(), dtCrowd::getObstacleAvoidanceParams(), /// dtCrowdAgentParams::obstacleAvoidanceType static const int DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS = 8; /// The maximum number of query filter types supported by the crowd manager. /// @ingroup crowd /// @see dtQueryFilter, dtCrowd::getFilter() dtCrowd::getEditableFilter(), /// dtCrowdAgentParams::queryFilterType static const int DT_CROWD_MAX_QUERY_FILTER_TYPE = 16; /// Provides neighbor data for agents managed by the crowd. /// @ingroup crowd /// @see dtCrowdAgent::neis, dtCrowd struct dtCrowdNeighbour { int idx; ///< The index of the neighbor in the crowd. float dist; ///< The distance between the current agent and the neighbor. }; /// The type of navigation mesh polygon the agent is currently traversing. /// @ingroup crowd enum CrowdAgentState { DT_CROWDAGENT_STATE_INVALID, ///< The agent is not in a valid state. DT_CROWDAGENT_STATE_WALKING, ///< The agent is traversing a normal navigation mesh polygon. DT_CROWDAGENT_STATE_OFFMESH, ///< The agent is traversing an off-mesh connection. }; /// Configuration parameters for a crowd agent. /// @ingroup crowd struct dtCrowdAgentParams { float radius; ///< Agent radius. [Limit: >= 0] float height; ///< Agent height. [Limit: > 0] float maxAcceleration; ///< Maximum allowed acceleration. [Limit: >= 0] float maxSpeed; ///< Maximum allowed speed. [Limit: >= 0] /// Defines how close a collision element must be before it is considered for steering behaviors. [Limits: > 0] float collisionQueryRange; float pathOptimizationRange; ///< The path visibility optimization range. [Limit: > 0] /// How aggresive the agent manager should be at avoiding collisions with this agent. [Limit: >= 0] float separationWeight; /// Flags that impact steering behavior. (See: #UpdateFlags) unsigned char updateFlags; /// The index of the avoidance configuration to use for the agent. /// [Limits: 0 <= value <= #DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS] unsigned char obstacleAvoidanceType; /// The index of the query filter used by this agent. unsigned char queryFilterType; /// User defined data attached to the agent. void* userData; }; enum MoveRequestState { DT_CROWDAGENT_TARGET_NONE = 0, DT_CROWDAGENT_TARGET_FAILED, DT_CROWDAGENT_TARGET_VALID, DT_CROWDAGENT_TARGET_REQUESTING, DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE, DT_CROWDAGENT_TARGET_WAITING_FOR_PATH, DT_CROWDAGENT_TARGET_VELOCITY, }; /// Represents an agent managed by a #dtCrowd object. /// @ingroup crowd struct dtCrowdAgent { /// True if the agent is active, false if the agent is in an unused slot in the agent pool. bool active; /// The type of mesh polygon the agent is traversing. (See: #CrowdAgentState) unsigned char state; /// True if the agent has valid path (targetState == DT_CROWDAGENT_TARGET_VALID) and the path does not lead to the requested position, else false. bool partial; /// The path corridor the agent is using. dtPathCorridor corridor; /// The local boundary data for the agent. dtLocalBoundary boundary; /// Time since the agent's path corridor was optimized. float topologyOptTime; /// The known neighbors of the agent. dtCrowdNeighbour neis[DT_CROWDAGENT_MAX_NEIGHBOURS]; /// The number of neighbors. int nneis; /// The desired speed. float desiredSpeed; float npos[3]; ///< The current agent position. [(x, y, z)] float disp[3]; ///< A temporary value used to accumulate agent displacement during iterative collision resolution. [(x, y, z)] float dvel[3]; ///< The desired velocity of the agent. Based on the current path, calculated from scratch each frame. [(x, y, z)] float nvel[3]; ///< The desired velocity adjusted by obstacle avoidance, calculated from scratch each frame. [(x, y, z)] float vel[3]; ///< The actual velocity of the agent. The change from nvel -> vel is constrained by max acceleration. [(x, y, z)] /// The agent's configuration parameters. dtCrowdAgentParams params; /// The local path corridor corners for the agent. (Staight path.) [(x, y, z) * #ncorners] float cornerVerts[DT_CROWDAGENT_MAX_CORNERS*3]; /// The local path corridor corner flags. (See: #dtStraightPathFlags) [(flags) * #ncorners] unsigned char cornerFlags[DT_CROWDAGENT_MAX_CORNERS]; /// The reference id of the polygon being entered at the corner. [(polyRef) * #ncorners] dtPolyRef cornerPolys[DT_CROWDAGENT_MAX_CORNERS]; /// The number of corners. int ncorners; unsigned char targetState; ///< State of the movement request. dtPolyRef targetRef; ///< Target polyref of the movement request. float targetPos[3]; ///< Target position of the movement request (or velocity in case of DT_CROWDAGENT_TARGET_VELOCITY). dtPathQueueRef targetPathqRef; ///< Path finder ref. bool targetReplan; ///< Flag indicating that the current path is being replanned. float targetReplanTime; ///