/// <summary> Add a OctreeLeaf into the tree at a location.</summary> /// <param name="leaf">object-location composite</param> /// <returns> true if the pution worked.</returns> public bool AddNode(OctreeLeaf leaf) { if (branch == null) { this.items.Add(leaf); if (this.items.Count == 1) { this.allTheSamePoint = true; this.firstX = leaf.X; this.firstY = leaf.Y; this.firstZ = leaf.Z; } else { if (this.firstX != leaf.X || this.firstY != leaf.Y || this.firstZ != leaf.Z) { this.allTheSamePoint = false; } } if (this.items.Count > maxItems && !this.allTheSamePoint) { split(); } return(true); } else { OctreeNode node = getChild(leaf.X, leaf.Y, leaf.Z); if (node != null) { return(node.AddNode(leaf)); } } return(false); }
/// <summary> Add a object into the tree at a location. /// </summary> /// <param name="x">up-down location in Octree Grid</param> /// <param name="y">left-right location in Octree Grid</param> /// <param name="z">front-back location in Octree Grid</param> /// <returns> true if the insertion worked. </returns> public bool AddNode(float x, float y, float z, object obj) { return(top.AddNode(x, y, z, obj)); }