コード例 #1
0
        public Polygon GetOcclusionPoly()
        {
            Polygon         p             = new Polygon();
            PointCollection polygonPoints = new PointCollection();
            Face            checkFace     = this;

            polygonPoints.Add(new Point(x, y)); //Add start point
            int i = 0;

            //Loop through faces starting at the start line until end line is found.
            while (checkFace.endLine == null && i < 20)
            {
                if (checkFace.GetAdjacentFace(false) == null) // There's no adjacent face, so we'll curve around the corner to find the endline
                {
                    checkFace = checkFace.next;
                    polygonPoints.Add(new Point(checkFace.next.next.x, checkFace.next.next.y));                     // add the opposite face so that we can show the wall but not what's behind it.
                }
                else if (checkFace.GetAdjacentFace(false) != null && checkFace.GetAdjacentFace(false).over != null) // If we're in a concave corner, curve around that
                {
                    //Add a fuckton of points to include the wall we're occluding from
                    polygonPoints.Add(new Point(checkFace.next.next.next.x, checkFace.next.next.next.y));
                    polygonPoints.Add(new Point(checkFace.GetAdjacentFace(false).next.next.next.x, checkFace.GetAdjacentFace(false).next.next.next.y));
                    polygonPoints.Add(new Point(checkFace.GetAdjacentFace(false).next.next.x, checkFace.GetAdjacentFace(false).next.next.y));
                    polygonPoints.Add(new Point(checkFace.GetAdjacentFace(false).next.x, checkFace.GetAdjacentFace(false).next.y));
                    checkFace = checkFace.GetAdjacentFace(false).over.next;
                    ///polygonPoints.Add(new Point(checkFace.x, checkFace.y));
                }
                else
                {
                    polygonPoints.Add(new Point(checkFace.next.next.next.x, checkFace.next.next.next.y));
                    polygonPoints.Add(new Point(checkFace.next.next.x, checkFace.next.next.y));
                    checkFace = checkFace.GetAdjacentFace(false);
                    polygonPoints.Add(new Point(checkFace.next.next.x, checkFace.next.next.y));
                }
                i++;
            }
            if (i == 0 && checkFace.endLine != null) // If the endline is on the same face as the start line add the backfaces to the occlusion poly
            {
                polygonPoints.Add(new Point(checkFace.next.next.next.x, checkFace.next.next.next.y));
                polygonPoints.Add(new Point(checkFace.next.next.x, checkFace.next.next.y));
            }

            if (checkFace.endLine != null)
            {
                polygonPoints.Add(new Point(checkFace.endLine.X1, checkFace.endLine.Y1));
                polygonPoints.Add(new Point(checkFace.endLine.X2, checkFace.endLine.Y2));
            }
            else
            {
                return(null);
            }

            //ARTIFACT CORRECTION
            //Do we need a corner point?
            if (startLine.X2 == mainWindow.WindowTopLeft.X && checkFace.endLine.Y2 == mainWindow.WindowTopLeft.Y)
            {
                polygonPoints.Add(mainWindow.WindowTopLeft);
            }
            else if (checkFace.endLine.X2 == mainWindow.WindowBottomRight.X && startLine.Y2 == mainWindow.WindowTopLeft.Y)
            {
                polygonPoints.Add(new Point(mainWindow.WindowBottomRight.X, mainWindow.WindowTopLeft.Y));
            }
            else if (startLine.X2 == mainWindow.WindowBottomRight.X && checkFace.endLine.Y2 == mainWindow.WindowBottomRight.Y)
            {
                polygonPoints.Add(mainWindow.WindowBottomRight);
            }
            else if (checkFace.endLine.X2 == mainWindow.WindowTopLeft.X && startLine.Y2 == mainWindow.WindowBottomRight.Y)
            {
                polygonPoints.Add(new Point(mainWindow.WindowTopLeft.X, mainWindow.WindowBottomRight.Y));
            }

            //Do we need 2 corner points?
            if (checkFace.endLine.X2 == mainWindow.WindowTopLeft.X && startLine.X2 == mainWindow.WindowBottomRight.X)
            {
                polygonPoints.Add(new Point(mainWindow.WindowTopLeft.X, mainWindow.WindowBottomRight.Y));
                polygonPoints.Add(mainWindow.WindowBottomRight);
            }
            if (startLine.X2 == mainWindow.WindowTopLeft.X && checkFace.endLine.X2 == mainWindow.WindowBottomRight.X)
            {
                polygonPoints.Add(new Point(mainWindow.WindowBottomRight.X, mainWindow.WindowTopLeft.Y));
                polygonPoints.Add(mainWindow.WindowTopLeft);
            }
            if (startLine.Y2 == mainWindow.WindowTopLeft.Y && checkFace.endLine.Y2 == mainWindow.WindowBottomRight.Y)
            {
                polygonPoints.Add(mainWindow.WindowBottomRight);
                polygonPoints.Add(new Point(mainWindow.WindowBottomRight.X, mainWindow.WindowTopLeft.Y));
            }
            if (checkFace.endLine.Y2 == mainWindow.WindowTopLeft.Y && startLine.Y2 == mainWindow.WindowBottomRight.Y)
            {
                polygonPoints.Add(mainWindow.WindowTopLeft);
                polygonPoints.Add(new Point(mainWindow.WindowTopLeft.X, mainWindow.WindowBottomRight.Y));
            }


            //And the last point to bring 'er home.
            polygonPoints.Add(new Point(startLine.X2, startLine.Y2));


            p.Points  = polygonPoints;
            p.Stroke  = Brushes.Black;
            p.Fill    = Brushes.Black;
            p.Opacity = 0.4;

            return(p);
        }
コード例 #2
0
ファイル: Tile.cs プロジェクト: Gartley/ss13remake
        public void GenerateFaces()
        {
            //Faces are defined as the start point and the next adjoining face. We're only dealing with squares so no need to do lots of general poly s***e.
            //The point defined per face is the right vertex of the face as if you were inside the square.
            faceW = new Face(mainWindow);
            faceW.x = x * tileSize;
            faceW.y = y * tileSize;
            faceS = new Face(mainWindow);
            faceS.x = x * tileSize;
            faceS.y = (y + 1) * tileSize;
            faceE = new Face(mainWindow);
            faceE.x = (x + 1) * tileSize;
            faceE.y = (y + 1) * tileSize;
            faceN = new Face(mainWindow);
            faceN.x = (x + 1) * tileSize;
            faceN.y = y * tileSize;

            faceW.next = faceS;
            faceS.next = faceE;
            faceE.next = faceN;
            faceN.next = faceW;
        }