/// <summary> /// Create internal octree node (eg not the root octree node). /// </summary> internal OctreeCullingNode(OctreeCullingNode parent, Vector3 index, BoundingBox boundingBox, uint divisionsLeft) { // store octree data and init _parentOctree = parent; _indexInParent = index; _octreeData = parent._octreeData; _divisionsLeft = divisionsLeft; InitOctreeBox(boundingBox); }
/// <summary> /// Add a new child node into one of the subdivision branches. /// This also create the subdivision octree if needed. /// </summary> protected void AddToSubTree(Node node, int x, int y, int z) { // create the subdivision branch if needed if (_childOctrees[x, y, z] == null) { _childOctrees[x, y, z] = new OctreeCullingNode(this, new Vector3(x, y, z), _childBoundingBoxes[x, y, z], _divisionsLeft - 1); } // add child node to branch _childOctrees[x, y, z].PushToTree(node); }
/// <summary> /// Called whenever we need to remove a node from the octree. /// </summary> /// <param name="node">Node to push into tree.</param> protected void RemoveFromTree(Node node) { // remove from all octree nodes foreach (Node linked in node.LinkedNodes) { OctreeCullingNode octreeNode = linked as OctreeCullingNode; if (octreeNode != null) { octreeNode.RemoveFromSelf(node); } } }