//update environment function public void update() { //add agents in these lists if (addAgents.Count() > 0) { foreach (var a in addAgents) { pop.Add(a); } } foreach (var a in removeAgents) { pop.Remove(a); } //clear lists addAgents.Clear(); removeAgents.Clear(); //octree if (pop.Count() > 0) { pts = new AgentOctree(null, new Vector3d(-bounds, -bounds, -bounds), bounds * 2); foreach (var a in pop) { pts.addPoint(a); } } }
//return copy of child node array - not sure if copy function is correct public AgentOctree[] getChildren() { if (children != null) { AgentOctree[] clones = new AgentOctree[8]; Array.Copy(children, 0, clones, 0, 8); return(clones); } return(null); }
//constructor public Environment(double _bounds, List <Plane> _container) { pop = new List <Agent>(); removeAgents = new List <Agent>(); addAgents = new List <Agent>(); bounds = _bounds; pts = new AgentOctree(null, new Vector3d(-bounds, -bounds, -bounds), bounds * 2); container = _container; //note - we might not use this once planes implemented //construct generic bbox boundary = new AABB(new Vector3d(-bounds, -bounds, -bounds), new Vector3d(bounds * 2, bounds * 2, bounds * 2)); //reconstruct to specific bounds boundary = boundary.fromMinMax(new Vector3d(-bounds, -bounds, -bounds), new Vector3d(bounds * 2, bounds * 2, bounds * 2)); }
//private bool isAutoReducing = false; //constructor // :base is the same as super to pass down to AABB constructor public AgentOctree(AgentOctree p, Vector3d o, double halfSize) : base(Vector3d.Add(o, new Vector3d(halfSize, halfSize, halfSize)), new Vector3d(halfSize, halfSize, halfSize)) { this.parent = p; this.halfSize = halfSize; this.size = halfSize + halfSize; this.offset = o; this.numChildren = 0; if (parent != null) { depth = parent.depth + 1; minNodeSize = parent.minNodeSize; } }
public bool addPoint(Agent p) { //check if pt is inside cube - write code for contains point if (containsPoint(p)) { if (halfSize <= minNodeSize) { if (points == null) { points = new List <Agent>(); } points.Add(p); return(true); } else { Vector3d plocal = Vector3d.Subtract(p.position, offset); if (children == null) { children = new AgentOctree[8]; } int octant = getOctantID(plocal); if (children[octant] == null) { Vector3d off = Vector3d.Add(offset, new Vector3d( (octant & 1) != 0 ? halfSize : 0, (octant & 2) != 0 ? halfSize : 0, (octant & 4) != 0 ? halfSize : 0)); children[octant] = new AgentOctree(this, off, halfSize * 0.5); numChildren++; } return(children[octant].addPoint(p)); } } return(false); }