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; } }
/// <summary> /// 通过节点对象创建一个 /// </summary> /// <param name="node"></param> /// <returns></returns> public static JsonNode Create(Node node) { JsonNode jn = new JsonNode(); jn.id = node.id; jn.nodeIndex = node.nodeIndex; jn.code = node.code; jn.name = node.name; jn.area = node.areaCode; jn.trade = node.sgTrade; jn.sgName = node.sgName; jn.areaName = node.areaName; jn.longName = node.longName; jn.weight = node.weight; jn.type = node.type; jn.dimession = node.index; jn.relationType = node.relationType; if (node.filter != null && node.filter.Count > 0) { int len = node.filter.Count; NodeChild[] nc = new NodeChild[len]; int i = 0; foreach (Node n in node.filter) { nc[i].nodeIndex = n.nodeIndex; i++; } jn.children = nc; } else { jn.children = EmptyNCArray; } return(jn); }
/// <summary> /// <para>Remove a child from the specified position and disable its flag.</para> /// </summary> private void RemoveChild(NodeChild position, NodeContent flag) { this.DisableVertex(flag); QuadNode node = this.Childs[(int)position]; switch (position) { case NodeChild.NorthWest: this.DisableVertex(NodeContent.NorthVertex, NodeVertex.North); this.DisableVertex(NodeContent.WestVertex, NodeVertex.West); break; case NodeChild.NorthEast: this.DisableVertex(NodeContent.NorthVertex, NodeVertex.North); this.DisableVertex(NodeContent.EastVertex, NodeVertex.East); break; case NodeChild.SouthWest: this.DisableVertex(NodeContent.SouthVertex, NodeVertex.South); this.DisableVertex(NodeContent.WestVertex, NodeVertex.West); break; default: this.DisableVertex(NodeContent.SouthVertex, NodeVertex.South); this.DisableVertex(NodeContent.EastVertex, NodeVertex.East); break; } this.Childs[(int)position] = null; this.InitializeNeighbors(); node.InitializeNeighbors(); node.Dispose(); }
/// <summary> /// <para>Check the specified child of the current <see cref="QuadNode"/>.</para> /// </summary> /// <param name="position">Position of the child.</param> /// <param name="flag">Flag to enable/disable.</param> /// <param name="childBox">Associated child's bounding box.</param> private void CheckChildAt(NodeChild position, NodeContent flag, float dotprod, BoundingBox childBox) { if (this.IsDisabled(flag)//if the flag is not enabled && ChildTest(dotprod, childBox, Camera.Camera.DefaultCamera.Transform.Translation))//and the child bounding box show that the child have to be enabled this.AddChild(position, flag); else if (this.IsEnabled(flag)//if the flag is enabled && this.Childs[(int)position].IsLeaf() //and the child have not childs && this.Childs[(int)position].HaveNoEdge() // and the child have no side edges && !ChildTest(dotprod, childBox, Camera.Camera.DefaultCamera.Transform.Translation)) ////and the child bounding box show that the child have to be disabled this.RemoveChild(position, flag); }
/// <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; } }