Esempio n. 1
0
        private static void FillNode(RooBSPItem Node, List <RooBSPItem> NodeList)
        {
            if (Node == null)
            {
                return;
            }

            NodeList.Add(Node);

            if (Node.Type == RooBSPItem.NodeType.Node)
            {
                RooPartitionLine node = (RooPartitionLine)Node;

                FillNode(node.RightChild, NodeList);
                FillNode(node.LeftChild, NodeList);
            }
        }
Esempio n. 2
0
        private static RooBSPItem BuildNode(List <RooWall> Walls, Polygon Polygon, int Sector)
        {
            if (Polygon.Count == 0 || (Walls.Count == 0 && Sector == 0))
            {
                return(null);
            }

            Polygon.RemoveZeroEdges();

            if (!Polygon.IsConvexPolygon())
            {
                if (FoundNonConvexPolygon != null)
                {
                    FoundNonConvexPolygon(null, new PolygonEventArgs(Polygon));
                }

                //return null; // WTF ?
            }

            // No walls left ==> leaf
            if (Walls.Count == 0)
            {
                RooSubSector leaf = new RooSubSector(RooFile.VERSIONHIGHRESGRID, (ushort)Sector, Polygon);

                // fills in sector reference
                leaf.ResolveIndices(room);

                return(leaf);
            }

            // get best splitter of remaining walls
            RooWall splitter = ChooseSplitter(Walls);

            if (splitter == null)
            {
                return(null); // WTF ?
            }
            // split up walls into right/left
            Tuple <List <RooWall>, List <RooWall> > splitWalls =
                SplitWalls(Walls, splitter);

            // split up polygon into right/left
            Tuple <Polygon, Polygon> splitPolygons =
                Polygon.SplitConvexPolygon(splitter.P1, splitter.P2);

            Real a, b, c;

            GetLineEquation2DCoefficients(splitter.P1, splitter.P2,
                                          out a, out b, out c);

            // create new splitter node
            RooPartitionLine node = new RooPartitionLine(RooFile.VERSIONHIGHRESGRID,
                                                         Polygon.GetBoundingBox(), a, b, c, 0, 0, (ushort)splitter.Num);

            // fills in wall reference
            node.Wall = splitter;

            // recursively descend to children
            node.LeftChild  = BuildNode(splitWalls.Item1, splitPolygons.Item1, splitter.LeftSectorNum);
            node.RightChild = BuildNode(splitWalls.Item2, splitPolygons.Item2, splitter.RightSectorNum);

            return(node);
        }
Esempio n. 3
0
        private static RooBSPItem BuildNode(List<RooWall> Walls, Polygon Polygon, int Sector)
        {
            if (Polygon.Count == 0 || (Walls.Count == 0 && Sector == 0))
                return null;

            Polygon.RemoveZeroEdges();

            if (!Polygon.IsConvexPolygon())
            {
                if (FoundNonConvexPolygon != null)
                    FoundNonConvexPolygon(null, new PolygonEventArgs(Polygon));

                //return null; // WTF ?
            }

            // No walls left ==> leaf
            if (Walls.Count == 0)
            {
                RooSubSector leaf = new RooSubSector(RooFile.VERSIONHIGHRESGRID, (ushort)Sector, Polygon);

                // fills in sector reference
                leaf.ResolveIndices(room);
                
                return leaf;
            }

            // get best splitter of remaining walls
            RooWall splitter = ChooseSplitter(Walls);

            if (splitter == null)
                return null; // WTF ?

            // split up walls into right/left
            Tuple<List<RooWall>, List<RooWall>> splitWalls = 
                SplitWalls(Walls, splitter);
            
            // split up polygon into right/left
            Tuple<Polygon, Polygon> splitPolygons = 
                Polygon.SplitConvexPolygon(splitter.P1, splitter.P2);

            Real a, b, c;
            GetLineEquation2DCoefficients(splitter.P1, splitter.P2,
                out a, out b, out c);

            // create new splitter node
            RooPartitionLine node = new RooPartitionLine(RooFile.VERSIONHIGHRESGRID,
                Polygon.GetBoundingBox(), a, b, c, 0, 0, (ushort)splitter.Num);

            // fills in wall reference
            node.Wall = splitter;

            // recursively descend to children
            node.LeftChild = BuildNode(splitWalls.Item1, splitPolygons.Item1, splitter.LeftSectorNum);
            node.RightChild  = BuildNode(splitWalls.Item2, splitPolygons.Item2, splitter.RightSectorNum);

            return node;
        }