/// <summary> /// Initializes a new instance of the <see cref="QuadNode" /> class. /// </summary> /// <param name="type">Type of node.</param> /// <param name="size">Width/Height of node (# of vertices across - 1).</param> /// <param name="depth">Depth of current node</param> /// <param name="parent">Parent QuadNode</param> /// <param name="parentTree">Top level Tree.</param> /// <param name="positionIndex">Index of top left Vertex in the parent tree Vertices array</param> public QuadNode( NodeType type, int size, int depth, QuadNode parent, Tanks3DFPP.Terrain.QuadTree parentTree, int positionIndex) { Type = type; this.size = size; this.depth = depth; parentNode = parent; this.parentTree = parentTree; this.positionIndex = positionIndex; AddVertices(); /* * The bounding box is used to determine where the tree * should be split and where to look for nodes that are within view. * * In a production system it would make more sense to use the maximum height value of the tree as a guide to define the bounds of the bounding box. * Even the maximum height within each individual quad may be used to define the bounds which would make culling away invisible quads much more efficient when standing on a mountain. * In fact, a more efficient method would be to use bounding shapes instead of volumes, using a rectangle as the bounding object. * The view frustrum could then be projected onto the terrain as a 2D shape. * Intersection checks for LOD would be much more efficient. */ Bounds = new BoundingBox( this.parentTree.Vertices[VertexTopLeft.Index].Position, this.parentTree.Vertices[VertexBottomRight.Index].Position) { Min = { Y = 0 }, Max = { Y = limY } }; //If node does not belong to the highest LOD if (this.size >= minSizeToContainChildren) { AddChildren(); } // If this is the root node if (this.depth == 1) { /* * Create the neighbors. * This is essentially the bootstrap point for the whole tree. */ AddNeighbors(); VertexTopLeft.Activated = true; VertexTopRight.Activated = true; VertexCenter.Activated = true; VertexBottomLeft.Activated = true; VertexBottomRight.Activated = true; VertexTop.Activated = true; VertexLeft.Activated = true; VertexRight.Activated = true; VertexBottom.Activated = true; } }
/// <summary> /// Initializes a new instance of the <see cref="QuadNode" /> class. /// </summary> /// <param name="type">Type of node.</param> /// <param name="size">Width/Height of node (# of vertices across - 1).</param> /// <param name="depth">Depth of current node</param> /// <param name="parent">Parent QuadNode</param> /// <param name="parentTree">Top level Tree.</param> /// <param name="positionIndex">Index of top left Vertex in the parent tree Vertices array</param> public QuadNode( NodeType type, int size, int depth, QuadNode parent, Tanks3DFPP.Terrain.QuadTree parentTree, int positionIndex) { Type = type; this.size = size; this.depth = depth; parentNode = parent; this.parentTree = parentTree; this.positionIndex = positionIndex; AddVertices(); /* * The bounding box is used to determine where the tree * should be split and where to look for nodes that are within view. * * In a production system it would make more sense to use the maximum height value of the tree as a guide to define the bounds of the bounding box. * Even the maximum height within each individual quad may be used to define the bounds which would make culling away invisible quads much more efficient when standing on a mountain. * In fact, a more efficient method would be to use bounding shapes instead of volumes, using a rectangle as the bounding object. * The view frustrum could then be projected onto the terrain as a 2D shape. * Intersection checks for LOD would be much more efficient. */ Bounds = new BoundingBox( this.parentTree.Vertices[VertexTopLeft.Index].Position, this.parentTree.Vertices[VertexBottomRight.Index].Position) { Min = { Y = 0 }, Max = { Y = limY } }; //If node does not belong to the highest LOD if (this.size >= minSizeToContainChildren) { AddChildren(); } // If this is the root node if (this.depth == 1) { /* * Create the neighbors. * This is essentially the bootstrap point for the whole tree. */ AddNeighbors(); VertexTopLeft.Activated = true; VertexTopRight.Activated = true; VertexCenter.Activated = true; VertexBottomLeft.Activated = true; VertexBottomRight.Activated = true; VertexTop.Activated = true; VertexLeft.Activated = true; VertexRight.Activated = true; VertexBottom.Activated = true; } }