private void BuildQuadtree() { this.quadtree.Clear(); if (this.agents.Count > 0) { IntRect1 bounds = IntRect1.MinMaxRect(this.agents[0].position.x, this.agents[0].position.y, this.agents[0].position.x, this.agents[0].position.y); for (int i = 1; i < this.agents.Count; i++) { Int3 position = this.agents[i].position; bounds = IntRect1.MinMaxRect(Mathf.Min(bounds.xMin, position.x), Mathf.Min(bounds.yMin, position.z), Mathf.Max(bounds.xMax, position.x), Mathf.Max(bounds.yMax, position.z)); } this.quadtree.SetBounds(bounds); for (int j = 0; j < this.agents.Count; j++) { this.quadtree.Insert(this.agents[j]); } } }
public void Insert(Agent agent) { int num = 0; IntRect1 r = this.bounds; Int2 xz = agent.position.xz; agent.next = null; this.maxRadius = IntMath.Max((long)agent.radius.i, this.maxRadius); int num2 = 0; while (true) { num2++; if (this.nodes[num].child00 == num) { if (this.nodes[num].count < 15 || num2 > 10) { break; } RVOQuadtree.Node node = this.nodes[num]; node.child00 = this.GetNodeIndex(); node.child01 = this.GetNodeIndex(); node.child10 = this.GetNodeIndex(); node.child11 = this.GetNodeIndex(); this.nodes[num] = node; this.nodes[num].Distribute(this.nodes, r); } if (this.nodes[num].child00 != num) { Int2 center = r.center; if (xz.x > center.x) { if (xz.y > center.y) { num = this.nodes[num].child11; r = IntRect1.MinMaxRect(center.x, center.y, r.xMax, r.yMax); } else { num = this.nodes[num].child10; r = IntRect1.MinMaxRect(center.x, r.yMin, r.xMax, center.y); } } else if (xz.y > center.y) { num = this.nodes[num].child01; r = IntRect1.MinMaxRect(r.xMin, center.y, center.x, r.yMax); } else { num = this.nodes[num].child00; r = IntRect1.MinMaxRect(r.xMin, r.yMin, center.x, center.y); } } } this.nodes[num].Add(agent); RVOQuadtree.Node[] expr_94_cp_0 = this.nodes; int expr_94_cp_1 = num; expr_94_cp_0[expr_94_cp_1].count = (byte)(expr_94_cp_0[expr_94_cp_1].count + 1); }
private long QueryRec(int i, Int2 p, long radius, Agent agent, IntRect1 r) { if (this.nodes[i].child00 == i) { for (Agent agent2 = this.nodes[i].linkedList; agent2 != null; agent2 = agent2.next) { long num = agent.InsertAgentNeighbour(agent2, radius * radius); if (num < radius * radius) { radius = (long)IntMath.Sqrt(num); } } } else { Int2 center = r.center; if ((long)p.x - radius < (long)center.x) { if ((long)p.y - radius < (long)center.y) { radius = this.QueryRec(this.nodes[i].child00, p, radius, agent, IntRect1.MinMaxRect(r.xMin, r.yMin, center.x, center.y)); } if ((long)p.y + radius > (long)center.y) { radius = this.QueryRec(this.nodes[i].child01, p, radius, agent, IntRect1.MinMaxRect(r.xMin, center.y, center.x, r.yMax)); } } if ((long)p.x + radius > (long)center.x) { if ((long)p.y - radius < (long)center.y) { radius = this.QueryRec(this.nodes[i].child10, p, radius, agent, IntRect1.MinMaxRect(center.x, r.yMin, r.xMax, center.y)); } if ((long)p.y + radius > (long)center.y) { radius = this.QueryRec(this.nodes[i].child11, p, radius, agent, IntRect1.MinMaxRect(center.x, center.y, r.xMax, r.yMax)); } } } return(radius); }