TerrainDemo.CDLOD.Node.Node C# (CSharp) Method

Node() public method

public Node ( int x, int y, int size, CreateDescription &createDescription ) : System
x int
y int
size int
createDescription CreateDescription
return System
        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;
            }
        }