Ejemplo n.º 1
0
        // Adds this boundary to a graph as a series of nodes and edges
        public void AddToGraph(BoundaryGraph graph)
        {
            List <Vector2>           corners = Get2DBounds();
            List <BoundaryGraphNode> nodes   = new List <BoundaryGraphNode>();
            int i = 0;

            // Convert each point into a node
            for (i = 0; i < corners.Count; i++)
            {
                BoundaryGraphNode node = new BoundaryGraphNode(corners[i]);
                nodes.Add(node);
            }
            // Link each node to the next one (note linking is reciprical so I don't have to link the reverse)
            for (i = 0; i < nodes.Count; i++)
            {
                int nextInd = (i + 1) % nodes.Count;
                nodes[i].AddNeighbor(nodes[nextInd]);
            }
            // Add the nodes to the graph
            foreach (BoundaryGraphNode node in nodes)
            {
                node.AddParentBoundary(this);
                graph.AddNode(node);
            }
        }