예제 #1
0
        /// <summary>
        /// Create the grid with rectangluar cells
        /// </summary>
        /// <param name="mapmeta"></param>
        private static void BuildMapGrid(MapMetaData mapmeta)
        {
            PosX = PosX = (int)mapmeta.CoordOriginX;
            PosY = PosY = (int)mapmeta.CoordOriginY;

            MapWidth  = (int)mapmeta.Width;
            MapHeight = (int)mapmeta.Height;

            CellEdgeLength = (int)Math.Ceiling((double)MapWidth / Cellamount);

            var currentx = PosX;
            var currenty = PosY;
            var cells    = (MapHeight / CellEdgeLength) * (MapWidth / CellEdgeLength);

            MapGrid = new MapGridCell[MapHeight / CellEdgeLength][];

            for (int k = 0; k < MapGrid.Length; k++)
            {
                MapGrid[k] = new MapGridCell[MapWidth / CellEdgeLength];

                for (int l = 0; l < MapGrid[k].Length; l++)
                {
                    MapGrid[k][l] = new MapGridCell
                    {
                        Index_X = k,
                        Index_Y = l,
                        Bounds  = new Rectangle2D(new Point2D(currentx, currenty), CellEdgeLength, CellEdgeLength),
                        Blocked = false
                    };
                    currentx += CellEdgeLength;
                }
                currentx  = PosX;
                currenty -= CellEdgeLength;
            }
        }
예제 #2
0
        /// <summary>
        /// This function takes a list of all registered points on the map and tries to
        /// reconstruct a polygonal represenatation of the map with serveral levels
        /// </summary>
        /// <param name="ps"></param>
        public static Map CreateMap(MapMetaData mapmeta, List <Point3D> ps)
        {
            PosX = (int)mapmeta.CoordOriginX;
            PosY = (int)mapmeta.CoordOriginY;

            MapWidth  = (int)mapmeta.Width;
            MapHeight = (int)mapmeta.Height;

            CellEdgeLength = (int)Math.Ceiling((double)MapWidth / Cellamount);

            var currentx = PosX;
            var currenty = PosY;
            var cells    = (MapHeight / CellEdgeLength) * (MapWidth / CellEdgeLength);

            MapGrid = new MapGridCell[MapHeight / CellEdgeLength][];

            for (int k = 0; k < MapGrid.Length; k++)
            {
                MapGrid[k] = new MapGridCell[MapWidth / CellEdgeLength];

                for (int l = 0; l < MapGrid[k].Length; l++)
                {
                    MapGrid[k][l] = new MapGridCell
                    {
                        Index_X = k,
                        Index_Y = l,
                        Bounds  = new Rectangle2D(new Point2D(currentx, currenty), CellEdgeLength, CellEdgeLength),
                        Blocked = false
                    };
                    currentx += CellEdgeLength;
                }
                currentx  = PosX;
                currenty -= CellEdgeLength;
            }


            // Create the map levels
            MapLevel[] maplevels   = CreateMapLevels(ps);
            var        map_width_x = ps.Max(point => point.X) - ps.Min(point => point.X);
            var        map_width_y = ps.Max(point => point.Y) - ps.Min(point => point.Y);

            Console.WriteLine("Max x: " + ps.Max(point => point.X) + " Min x: " + ps.Min(point => point.X));
            Console.WriteLine("Mapwidth in x-Range: " + map_width_x + " Mapwidth in y-Range: " + map_width_y);

            return(new Map(map_width_x, map_width_y, maplevels));
        }