Exemplo n.º 1
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);
        }
Exemplo 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;
        }
Exemplo n.º 3
0
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);

            if (room == null)
                return;

            float mapx = ((float)e.Location.X / ZoomInv + (float)boxMin.X);
            float mapy = ((float)e.Location.Y / ZoomInv + (float)boxMin.Y);

            if (e.Button == MouseButtons.Left)
            {
                RooSubSector oldSubSector   = selectedSubSector;
                RooSector oldSector         = selectedSector;

                selectedSubSector   = Room.GetSubSectorAt((int)mapx, (int)mapy);
                selectedSector      = (selectedSubSector != null) ? selectedSubSector.Sector : null;
                
                if (oldSubSector != selectedSubSector || 
                    oldSector != selectedSector)
                {
                    Invalidate();

                    if (oldSector != selectedSector && SelectedSectorChanged != null)
                        SelectedSectorChanged(this, new EventArgs());
                    
                    if (oldSubSector != selectedSubSector && SelectedSubSectorChanged != null)
                        SelectedSubSectorChanged(this, new EventArgs());
                }
            }
        }
        /// <summary>
        /// Looks up the height of a point from the sector it's included in.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>        
        /// <param name="SubSector">The subsector the point was found in or NULL</param>
        /// <param name="IsFloor"></param>
        /// <param name="WithSectorDepth"></param>
        /// <returns>Height of point or -1 if no sector found for point</returns>
        public Real GetHeightAt(Real x, Real y, out RooSubSector SubSector, bool IsFloor = true, bool WithSectorDepth = false)
        {
            SubSector = null;

            // walk BSP tree and get subsector containing point
            SubSector = GetSubSectorAt(x, y);

            if (SubSector != null && SubSector.Sector != null)
            {
                if (IsFloor)
                    return SubSector.Sector.CalculateFloorHeight(x, y, WithSectorDepth);

                else
                    return SubSector.Sector.CalculateCeilingHeight(x, y);
            }

            return -1.0f;
        }