コード例 #1
0
        public void RasterizeBox(Square[,,,] squares, RasterizationGrid rast, Vector3 tl, Vector3 tr, Vector3 bl, Vector3 br)
        {
            float   left         = Mathf.Min(tl.x, tr.x, bl.x, br.x);
            float   right        = Mathf.Max(tl.x, tr.x, bl.x, br.x);
            float   up           = Mathf.Max(tl.y, tr.y, bl.y, br.y);
            float   down         = Mathf.Min(tl.y, tr.y, bl.y, br.y);
            Vector2 topLeft      = new Vector2(left, up);
            Vector2 bottomRight  = new Vector2(right, down);
            int     sectorTop    = rast.SectorColumn(topLeft);
            int     sectorBottom = rast.SectorColumn(bottomRight);
            int     sectorLeft   = rast.SectorRow(topLeft);
            int     sectorRight  = rast.SectorRow(bottomRight);

            for (int sr = sectorLeft; sr <= sectorRight; sr++)
            {
                for (int sc = sectorTop; sc <= sectorBottom; sc++)
                {
                    Vector2Int sector     = new Vector2Int(sr, sc);
                    int        gridTop    = rast.GridColumn(sector, topLeft);
                    int        gridBottom = rast.GridColumn(sector, bottomRight);
                    int        gridLeft   = rast.GridRow(sector, topLeft);
                    int        gridRight  = rast.GridRow(sector, bottomRight);
                    for (int gr = gridLeft; gr <= gridRight; gr++)
                    {
                        for (int gc = gridTop; gc <= gridBottom; gc++)
                        {
                            squares[sr, sc, gr, gc].FillBox(tl, tr, bl, br);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void RasterizeCircle(Square[,,,] squares, RasterizationGrid rast, Vector3 center, float radius)
        {
            Vector2 topLeft      = new Vector2(center.x - radius, center.y + radius);
            Vector2 bottomRight  = new Vector2(center.x + radius, center.y - radius);
            int     sectorTop    = rast.SectorColumn(topLeft);
            int     sectorBottom = rast.SectorColumn(bottomRight);
            int     sectorLeft   = rast.SectorRow(topLeft);
            int     sectorRight  = rast.SectorRow(bottomRight);

            for (int sr = sectorLeft; sr <= sectorRight; sr++)
            {
                for (int sc = sectorTop; sc <= sectorBottom; sc++)
                {
                    Vector2Int sector     = new Vector2Int(sr, sc);
                    int        gridTop    = rast.GridColumn(sector, topLeft);
                    int        gridBottom = rast.GridColumn(sector, bottomRight);
                    int        gridLeft   = rast.GridRow(sector, topLeft);
                    int        gridRight  = rast.GridRow(sector, bottomRight);
                    for (int gr = gridLeft; gr <= gridRight; gr++)
                    {
                        for (int gc = gridTop; gc <= gridBottom; gc++)
                        {
                            squares[sr, sc, gr, gc].FillCircle(center, radius);
                        }
                    }
                }
            }
        }
コード例 #3
0
        private void ReserveGridSquares(Floor floor, Vector3 start, Vector3 end, float width)
        {
            RasterizationGrid rast = floor.rasterizationGrid;

            Square[,,,] squares = floor.Squares;
            Vector3 tl, tr, bl, br;

            GenerationUtility.BoxBounds(start, end, width, out tl, out tr, out bl, out br);
            float   left         = Mathf.Min(tl.x, tr.x, bl.x, br.x);
            float   right        = Mathf.Max(tl.x, tr.x, bl.x, br.x);
            float   up           = Mathf.Max(tl.y, tr.y, bl.y, br.y);
            float   down         = Mathf.Min(tl.y, tr.y, bl.y, br.y);
            Vector2 topLeft      = new Vector2(left, up);
            Vector2 bottomRight  = new Vector2(right, down);
            int     sectorTop    = rast.SectorColumn(topLeft);
            int     sectorBottom = rast.SectorColumn(bottomRight);
            int     sectorLeft   = rast.SectorRow(topLeft);
            int     sectorRight  = rast.SectorRow(bottomRight);

            for (int sr = sectorLeft; sr <= sectorRight; sr++)
            {
                for (int sc = sectorTop; sc <= sectorBottom; sc++)
                {
                    Vector2Int sector     = new Vector2Int(sr, sc);
                    int        gridTop    = rast.GridColumn(sector, topLeft);
                    int        gridBottom = rast.GridColumn(sector, bottomRight);
                    int        gridLeft   = rast.GridRow(sector, topLeft);
                    int        gridRight  = rast.GridRow(sector, bottomRight);
                    for (int gr = gridLeft; gr <= gridRight; gr++)
                    {
                        for (int gc = gridTop; gc <= gridBottom; gc++)
                        {
                            bool a = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].TopLeft.Position, tl, tr, bl, br);
                            bool b = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].TopRight.Position, tl, tr, bl, br);
                            bool c = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].BottomLeft.Position, tl, tr, bl, br);
                            bool d = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].BottomRight.Position, tl, tr, bl, br);
                            if (a || b || c || d)
                            {
                                squares[sr, sc, gr, gc].Reserved = true;
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        private void RaiseMesh(Square[,,,] squares, RasterizationGrid rast, Vector3 start, Vector3 end, float width, Vector3 startHeight, Vector3 endHeight)
        {
            Vector3 tl, tr, bl, br;

            GenerationUtility.BoxBounds(start, end, width, out tl, out tr, out bl, out br);
            float   left         = Mathf.Min(tl.x, tr.x, bl.x, br.x);
            float   right        = Mathf.Max(tl.x, tr.x, bl.x, br.x);
            float   up           = Mathf.Max(tl.y, tr.y, bl.y, br.y);
            float   down         = Mathf.Min(tl.y, tr.y, bl.y, br.y);
            Vector2 topLeft      = new Vector2(left, up);
            Vector2 bottomRight  = new Vector2(right, down);
            int     sectorTop    = rast.SectorColumn(topLeft);
            int     sectorBottom = rast.SectorColumn(bottomRight);
            int     sectorLeft   = rast.SectorRow(topLeft);
            int     sectorRight  = rast.SectorRow(bottomRight);

            for (int sr = sectorLeft; sr <= sectorRight; sr++)
            {
                for (int sc = sectorTop; sc <= sectorBottom; sc++)
                {
                    Vector2Int sector     = new Vector2Int(sr, sc);
                    int        gridTop    = rast.GridColumn(sector, topLeft);
                    int        gridBottom = rast.GridColumn(sector, bottomRight);
                    int        gridLeft   = rast.GridRow(sector, topLeft);
                    int        gridRight  = rast.GridRow(sector, bottomRight);
                    for (int gr = gridLeft; gr <= gridRight; gr++)
                    {
                        for (int gc = gridTop; gc <= gridBottom; gc++)
                        {
                            if (squares[sr, sc, gr, gc].Marked)
                            {
                                squares[sr, sc, gr, gc].SetZHeight(startHeight, endHeight);
                            }
                        }
                    }
                }
            }
        }