public QuadNode(QuadNode parent, NodeChild position) { //array for neighbors at each sides this._neighbors = new QuadNode[4]; //array for all the nine vertices of the current node this._vertices = new TerrainVertex[QuadNode.VerticesNumber]; //the interpolated position difference with the real position this._realToInterpolatedVertexHeight = new float[QuadNode.SidesNumber]; this._parent = parent; this._position = position; if (parent == null) this._depth = 0; else { this._depth = Convert.ToByte(parent.Depth + 1); this._parentTree = parent._parentTree; } }
public void RemoveReferenceFrom(QuadNode node) { this._references.Remove(node); }
public void AddReferenceTo(QuadNode node) { if (this._references.IndexOf(node) >= 0) return; this._references.Add(node); }
/// <summary> /// <para>Add a child at the specified position and enable its flag.</para> /// </summary> /// <param name="position"></param> /// <param name="flag"></param> private void AddChild(NodeChild position, NodeContent flag) { this.EnableVertex(flag); QuadNode node = new QuadNode(this, position); this.Childs[(int)position] = node; float size = node.GetNodeSize(); switch (position) { case NodeChild.NorthWest: node.Location = this.Location + new Vector2(0, size); break; case NodeChild.NorthEast: node.Location = this.Location + new Vector2(size, size); break; case NodeChild.SouthWest: node.Location = this.Location + new Vector2(0, 0); break; default: node.Location = this.Location + new Vector2(size, 0); break; } node.InitializeNeighbors(); this.InitializeNeighbors(); node.Initialize(); switch (position) { case NodeChild.NorthWest: this.EnableVertex(NodeContent.NorthVertex, NodeVertex.North); this.EnableVertex(NodeContent.WestVertex, NodeVertex.West); break; case NodeChild.NorthEast: this.EnableVertex(NodeContent.NorthVertex, NodeVertex.North); this.EnableVertex(NodeContent.EastVertex, NodeVertex.East); break; case NodeChild.SouthWest: this.EnableVertex(NodeContent.SouthVertex, NodeVertex.South); this.EnableVertex(NodeContent.WestVertex, NodeVertex.West); break; default: this.EnableVertex(NodeContent.SouthVertex, NodeVertex.South); this.EnableVertex(NodeContent.EastVertex, NodeVertex.East); break; } }