public Node(int x, int y, int size, ref CDLODSettings settings) { this.x = x; this.y = y; this.size = size; if (settings.LeafNodeSize < size) { // if not a leaf node, then create child nodes. int childSize = size / 2; childTopLeft = new Node(x, y, childSize, ref settings); level = childTopLeft.level + 1; if (x + childSize < settings.HeightMapWidth - 1) { childTopRight = new Node(x + childSize, y, childSize, ref settings); } if (y + childSize < settings.HeightMapHeight - 1) { childBottomLeft = new Node(x, y + childSize, childSize, ref settings); } if (x + childSize < settings.HeightMapWidth - 1 && y + childSize < settings.HeightMapHeight - 1) { childBottomRight = new Node(x + childSize, y + childSize, childSize, ref settings); } } }
public QuadTree(CDLODSettings settings) { topNodeSize = settings.TopNodeSize; topNodeCountX = (int) Math.Ceiling((settings.HeightMapWidth - 1) / (float) topNodeSize); topNodeCountY = (int) Math.Ceiling((settings.HeightMapHeight - 1) / (float) topNodeSize); topNodes = new Node[topNodeCountX, topNodeCountY]; for (int y = 0; y < topNodeCountY; y++) for (int x = 0; x < topNodeCountX; x++) topNodes[x, y] = new Node(x * topNodeSize, y * topNodeSize, topNodeSize, ref settings); }
internal void AddSelectedNode(Node node) { if (MaxSelectedNodeCount <= SelectedNodeCount) return; selectedNodes[SelectedNodeCount++] = new CDLODSelectedNode { X = node.X, Y = node.Y, MinHeight = node.MinHeight, MaxHeight = node.MaxHeight, Size = node.Size, Level = node.Level }; }