public bool Init(int maxAgents, float maxAgentRadius, NavMesh nav) { Purge(); _maxAgents = maxAgents; _maxAgentRadius = maxAgentRadius; Helper.VSet(ref _ext, _maxAgentRadius * 2.0f, _maxAgentRadius * 1.5f, _maxAgentRadius * 2.0f); _grid = new ProximityGrid(); _grid.Init(_maxAgents * 4, maxAgentRadius * 3); _obstacleQuery = new ObstacleAvoidanceQuery(); _obstacleQuery.Init(6, 8); for (int i = 0; i < _obstacleQueryParams.Length; i++) { _obstacleQueryParams[i] = new ObstacleAvoidanceParams { velBias = 0.4f, weightDesVel = 2.0f, weightCurVel = 0.75f, weightSide = 0.75f, weightToi = 2.5f, horizTime = 2.5f, gridSize = 33, adaptiveDivs = 7, adaptiveRings = 2, adaptiveDepth = 5 }; } _maxPathResult = 256; _pathResult = new long[_maxPathResult]; _pathq = new PathQueue(); _pathq.Init(_maxPathResult, MaxPathQueueNodes, nav); _agents = new CrowdAgent[_maxAgents]; _activeAgents = new CrowdAgent[_maxAgents]; _agentAnims = new CrowdAgentAnimation[_maxAgents]; for (int i = 0; i < _maxAgents; i++) { _agents[i] = new CrowdAgent(); _agents[i].Active = false; _agents[i].Corridor.Init(_maxPathResult); } for (int i = 0; i < _maxAgents; i++) { _agentAnims[i] = new CrowdAgentAnimation(); _agentAnims[i].Active = false; } _navQuery = new NavMeshQuery(); _navQuery.Init(nav, MaxCommonNodes); return(true); }
private void Purge() { _agents = null; _maxAgents = 0; _activeAgents = null; _agentAnims = null; _pathResult = null; _grid = null; _obstacleQuery = null; _navQuery = null; }
public Crowd() { _maxAgents = 0; _agents = null; _activeAgents = null; _agentAnims = null; _obstacleQuery = null; _grid = null; _pathResult = null; _maxPathResult = 0; _maxAgentRadius = 0; _velocitySampleCount = 0; _navQuery = null; _filter = new QueryFilter(); }
public static int GetNeighbors(float[] pos, float height, float range, CrowdAgent skip, ref CrowdNeighbor[] result, int maxResult, CrowdAgent[] agents, int nagents, ProximityGrid grid) { int n = 0; int MaxNeis = 32; int[] ids = new int[MaxNeis]; int nids = grid.QueryItems(pos[0] - range, pos[2] - range, pos[0] + range, pos[2] + range, ref ids, MaxNeis); for (int i = 0; i < nids; i++) { CrowdAgent ag = agents[ids[i]]; if (ag == skip) { continue; } float[] diff = Helper.VSub(pos[0], pos[1], pos[2], ag.npos[0], ag.npos[1], ag.npos[2]); if (Math.Abs(diff[1]) >= (height + ag.Param.Height) / 2.0f) { continue; } diff[1] = 0; float distSqr = Helper.VLenSqr(diff); if (distSqr > range * range) { continue; } if (nids >= CrowdAgent.CrowdAgentMaxNeighbors) { continue; } n = AddNeighbor(ids[i], distSqr, ref result, n, maxResult); } return(n); }