private UpdatingHeightTree GetUpdateTree(HeightQuadTree parent, int parentIdx, MatrixBounds suggestedBounds) { if (_subTrees != null) { for (int i = 0; i < 4; i++) { if (_subTrees[i]._bounds.Contains(suggestedBounds)) { return(_subTrees[i].GetUpdateTree(this, i, suggestedBounds)); } } } if (parent != null) { var freshStart = new HeightQuadTree(_bounds, _depth, _maxDepth); return(new UpdatingHeightTree(freshStart, parent, parentIdx)); } return(null); }
private void SplitToSubTrees(int newX, int newZ, float newHeight) { _subTrees = new HeightQuadTree[4]; var sizeXLeft = _bounds.columns / 2; var sizeXRight = _bounds.columns - sizeXLeft; var sizeZBottom = _bounds.rows / 2; var sizeZTop = _bounds.rows - sizeZBottom; var subDepth = _depth + 1; _subTrees[0] = new HeightQuadTree(_bounds.minColumn, _bounds.minRow, sizeXLeft, sizeZBottom, subDepth, _maxDepth); _subTrees[1] = new HeightQuadTree(_bounds.minColumn + sizeXLeft, _bounds.minRow, sizeXRight, sizeZBottom, subDepth, _maxDepth); _subTrees[2] = new HeightQuadTree(_bounds.minColumn, _bounds.minRow + sizeZBottom, sizeXLeft, sizeZTop, subDepth, _maxDepth); _subTrees[3] = new HeightQuadTree(_bounds.minColumn + sizeXLeft, _bounds.minRow + sizeZBottom, sizeXRight, sizeZTop, subDepth, _maxDepth); var indexCount = _indexes.count; for (int i = 0; i < indexCount; i++) { var entry = _indexes[i]; for (int j = 0; j < 4; j++) { if (_subTrees[j].Add(entry.x, entry.z, _height)) { break; } } } for (int j = 0; j < 4; j++) { if (_subTrees[j].Add(newX, newZ, newHeight)) { break; } } _indexes = null; _height = 0f; }
public UpdatingHeightTree(HeightQuadTree target, HeightQuadTree parent, int parentIdx) { _target = target; _parent = parent; _parentIdx = parentIdx; }
private UpdatingHeightTree GetUpdateTree(HeightQuadTree parent, int parentIdx, MatrixBounds suggestedBounds) { if (_subTrees != null) { for (int i = 0; i < 4; i++) { if (_subTrees[i]._bounds.Contains(suggestedBounds)) { return _subTrees[i].GetUpdateTree(this, i, suggestedBounds); } } } if (parent != null) { var freshStart = new HeightQuadTree(_bounds, _depth, _maxDepth); return new UpdatingHeightTree(freshStart, parent, parentIdx); } return null; }