示例#1
0
        private List <Polygon> GetFrontLeaves(List <Polygon> leaves, BSPNode node)
        {
            if (node.Front != null)
            {
                if (node.Front.IsLeaf)
                {
                    leaves.Add(node.Front.Polygon);
                }

                GetFrontLeaves(leaves, node.Front);
            }

            if (node.Back != null)
            {
                GetFrontLeaves(leaves, node.Back);
            }

            return(leaves);
        }
示例#2
0
        private void DividePolygon(Vector2 start, Vector2 end)
        {
            var startIndex = FindDivisionPoint(start, end);
            var endIndex   = FindDivisionPoint(end, start);

            if ((startIndex >= 0) && (endIndex >= 0))
            {
                var firstVertex    = Polygon.Vertices[Polygon.Indices[startIndex]];
                var secondVertex   = Polygon.Vertices[Polygon.Indices[(startIndex + 1) % Polygon.Indices.Length]];
                var firstIntersect = LineSegment.Intersect(firstVertex, secondVertex, start, end);

                firstVertex  = Polygon.Vertices[Polygon.Indices[endIndex]];
                secondVertex = Polygon.Vertices[Polygon.Indices[(endIndex + 1) % Polygon.Indices.Length]];
                var secondIntersect = LineSegment.Intersect(firstVertex, secondVertex, end, start);

                var inside  = CreateSubPolygon(WalkEdges(startIndex + 1, endIndex), secondIntersect, start, end, firstIntersect);
                var outside = CreateSubPolygon(WalkEdges(endIndex + 1, startIndex), firstIntersect, end, start, secondIntersect);

                Front = new BSPNode(new Polygon(Polygon.Vertices, inside.ToArray()));
                Back  = new BSPNode(new Polygon(Polygon.Vertices, outside.ToArray()));
            }
        }
示例#3
0
 public void Cull()
 {
     Front = new BSPNode(new Polygon(Polygon.Vertices, new int[0]));
     Back  = new BSPNode(new Polygon(Polygon.Vertices, Polygon.Indices));
 }
示例#4
0
 public BSPTree(Polygon polygon)
 {
     Root = new BSPNode(polygon);
 }