private void GrowTowards(int x, int y, int z) { // Add new entries to the dimension dictionaries CreateDimensionsAtLevel(root.level + 1); // Find the direction of the point relative to the root int xDirection, yDirection, zDirection; root.DirectionTowardsPoint(x, y, z, out xDirection, out yDirection, out zDirection); // Find the weights which will be used to create the OcteeChild index int xIndexMod = xDirection * OctreeConstants.X_WEIGHT; int yIndexMod = yDirection * OctreeConstants.Y_WEIGHT; int zIndexMod = zDirection * OctreeConstants.Z_WEIGHT; // The index inwhich the current root node will be placed int moveRootTo = xIndexMod + yIndexMod + zIndexMod; // Flip the direction (1 becomes 0, and 0 becomes 1) int cellsAccross = (int)halfCellsAccrossAtLevel[root.level + 1]; xDirection = Convert.ToInt32(xDirection == 0); yDirection = Convert.ToInt32(yDirection == 0); zDirection = Convert.ToInt32(zDirection == 0); int rootMinX = (int)root.cellsCovered.low.x - (xDirection * cellsAccross); //+ (int)root.bounds.min.x; int rootMinY = (int)root.cellsCovered.low.y - (yDirection * cellsAccross); //+ (int)root.bounds.min.y; int rootMinZ = (int)root.cellsCovered.low.z - (zDirection * cellsAccross); //+ (int)root.bounds.min.z; OctreeBodyNode <T> newRootNode = bodyNodePool.Catch(); newRootNode.Initialize(this, rootMinX, rootMinY, rootMinZ, root.level + 1); // CANT EXPAND INTO NEGATIVES BECASUE MIN IS ALWAYS 000 newRootNode.PlaceChild(moveRootTo, root); root = newRootNode; }
public Octree(Vector3 leafDimensions, Vector3i startPosition) { this.leafDimensions = leafDimensions; entryPool = new Pool <OctreeEntry <T> >(); bodyNodePool = new Pool <OctreeBodyNode <T> >(); leafNodePool = new Pool <OctreeLeafNode <T> >(); cellsAccrossAtLevel = new Dictionary <int, float>(); halfCellsAccrossAtLevel = new Dictionary <int, float>(); quickieDictionary = new Dictionary <int, OctreeEntry <T> >(); // Maintain dimensions in the Octree to avoid dublicating throughout the leaves CreateDimensionsAtLevel(0); CreateDimensionsAtLevel(1); root = bodyNodePool.Catch(); root.Initialize(this, startPosition.x, startPosition.y, startPosition.z, 1); }
public Octree(Vector3 leafDimensions) { this.leafDimensions = leafDimensions; entryPool = new Pool <OctreeEntry <T> >(); bodyNodePool = new Pool <OctreeBodyNode <T> >(); leafNodePool = new Pool <OctreeLeafNode <T> >(); cellsAccrossAtLevel = new Dictionary <int, float>(); halfCellsAccrossAtLevel = new Dictionary <int, float>(); quickieDictionary = new Dictionary <int, OctreeEntry <T> >(); root = bodyNodePool.Catch(); CreateDimensionsAtLevel(0); CreateDimensionsAtLevel(1); }
public override OctreeEntry <T> SetAt(int x, int y, int z, T value) { int index = ChildRelativeTo(x, y, z); if (children[index] != null) { // The cell is in the child at index return(children[index].SetAt(x, y, z, value)); } // Find the new child min int xMinimum, yMinimum, zMinimum; MinOfChildIndex(index, out xMinimum, out yMinimum, out zMinimum); if (level == OctreeConstants.BODY_NODE_BASE_LEVEL) { // Create a leaf node if the level is below BODY_NODE_BASE_LEVEL OctreeLeafNode <T> fish = treeBase.leafNodePool.Catch(); // initialize the leaf node fish.Initialize(treeBase, xMinimum, yMinimum, zMinimum); // Set the child at index to the new node SetChild(index, fish); } else // Create a body node { //Requesta new body node OctreeBodyNode <T> fish = treeBase.bodyNodePool.Catch(); // initialize the body node fish.Initialize(treeBase, xMinimum, yMinimum, zMinimum, level - 1); // Set the child at index to the new node SetChild(index, fish); } return(children[index].SetAt(x, y, z, value)); }