public void AddSelectedNode(Node node) { if (MaxSelectedNodeCount <= SelectedNodeCount) return; selectedNodes[SelectedNodeCount++] = new SelectedNode { X = node.X, Y = node.Y, MinHeight = node.MinHeight, MaxHeight = node.MaxHeight, Size = node.Size, Level = node.Level }; }
public Node(int x, int y, int size, ref CreateDescription createDescription) { this.x = x; this.y = y; this.size = size; if (size == createDescription.Settings.LeafNodeSize) { int limitX = Math.Min(createDescription.HeightMap.Width, x + size + 1); int limitY = Math.Min(createDescription.HeightMap.Height, y + size + 1); // this is a leaf node. createDescription.HeightMap.GetAreaMinMaxHeight(x, y, limitX - x, limitY - y, out minHeight, out maxHeight); } else { int childSize = size / 2; childTopLeft = new Node(x, y, childSize, ref createDescription); minHeight = childTopLeft.minHeight; maxHeight = childTopLeft.maxHeight; if (x + childSize < createDescription.HeightMap.Width - 1) { childTopRight = new Node(x + childSize, y, childSize, ref createDescription); minHeight = MathHelper.Min(minHeight, childTopRight.minHeight); maxHeight = MathHelper.Max(maxHeight, childTopRight.maxHeight); } if (y + childSize < createDescription.HeightMap.Height - 1) { childBottomLeft = new Node(x, y + childSize, childSize, ref createDescription); minHeight = MathHelper.Min(minHeight, childBottomLeft.minHeight); maxHeight = MathHelper.Max(maxHeight, childBottomLeft.maxHeight); } if (x + childSize < createDescription.HeightMap.Width - 1 && y + childSize < createDescription.HeightMap.Height - 1) { childBottomRight = new Node(x + childSize, y + childSize, childSize, ref createDescription); minHeight = MathHelper.Min(minHeight, childBottomRight.minHeight); maxHeight = MathHelper.Max(maxHeight, childBottomRight.maxHeight); } level = childTopLeft.level + 1; } }
public void Build(ref CreateDescription createDescription) { var topNodeSize = createDescription.Settings.LeafNodeSize; for (int i = 1; i < createDescription.Settings.LevelCount; i++) topNodeSize *= 2; topNodeCountX = (int) Math.Ceiling((createDescription.HeightMap.Width - 1) / (float) topNodeSize); topNodeCountY = (int) Math.Ceiling((createDescription.HeightMap.Height - 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 createDescription); } } }