Ejemplo n.º 1
0
        /// <summary>
        /// QuadNode constructor
        /// </summary>
        /// <param name="nodeType">Type of node.</param>
        /// <param name="nodeSize">Width/Height of node (# of vertices across - 1).</param>
        /// <param name="nodeDepth">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 Vertice in the parent tree Vertices array</param>
        public QuadNode(NodeType nodeType, int nodeSize, int nodeDepth, QuadNode parent, QuadTree parentTree, int positionIndex)
        {
            NodeType       = nodeType;
            _nodeSize      = nodeSize;
            _nodeDepth     = nodeDepth;
            _positionIndex = positionIndex;

            _parent     = parent;
            _parentTree = parentTree;

            //Add the 9 vertices
            AddVertices();

            Bounds = new BoundingBox(_parentTree.Vertices[VertexTopLeft.Index].Position,
                                     _parentTree.Vertices[VertexBottomRight.Index].Position);
            Bounds.Min.Y = -950f;
            Bounds.Max.Y = 950f;

            if (nodeSize >= 4)
            {
                AddChildren();
            }

            //Make call to UpdateNeighbors from the parent node.
            //This will update all neighbors recursively for the
            //children as well.  This ensures all nodes are created
            //prior to updating neighbors.
            if (_nodeDepth == 1)
            {
                AddNeighbors();

                VertexTopLeft.Activated     = true;
                VertexTopRight.Activated    = true;
                VertexCenter.Activated      = true;
                VertexBottomLeft.Activated  = true;
                VertexBottomRight.Activated = true;
            }
        }