Beispiel #1
0
        protected override WindowedMap <RectPoint> CreateWindowedMap()
        {
            WindowedMap <RectPoint> windowedHexMap;

            float   cellWidth;
            float   cellHeight;
            Vector2 cellDimensions;

            switch (mapType)
            {
            case MapType.Rect:
                cellWidth      = CellPrefab.Dimensions.x;
                cellHeight     = CellPrefab.Dimensions.y;
                cellDimensions = new Vector2(cellWidth, cellHeight);

                windowedHexMap = new RectMap(cellDimensions.HadamardMul(CellSpacingFactor))
                                 .WithWindow(centerRect);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(windowedHexMap);
        }
        protected override IMap3D <RectPoint> CreateMap()
        {
            switch (mapType)
            {
            case MapType.Rect:
            {
                var windowedMap = new RectMap(cellDimensions.HadamardMul(CellSpacingFactor))
                                  .WithWindow(CenterRect);

                return(GetAlignedMap(windowedMap));
            }

            case MapType.Custom:
            {
                var map = GetCustomMap3D();

                return(map);
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #3
0
 public RectMeshMap(Vector2 cellDimensions, RectMap map)
 {
     this.cellDimensions = cellDimensions;
     this.map            = map;
 }
Beispiel #4
0
        public static List <Vector2> GeneratePoisson(Rect rect, float minDist, int newPointsCount)
        {
            //Create the grid
            float cellSize = minDist / Mathf.Sqrt(2);

            var gridWidth  = Mathf.CeilToInt(rect.width / cellSize);
            var gridHeight = Mathf.CeilToInt(rect.height / cellSize);
            var grid       = RectGrid <Vector2?> .Rectangle(gridWidth, gridHeight);

            var map = new RectMap(Vector2.one)
                      .AnchorCellBottomLeft()
                      .WithWindow(rect)
                      .Stretch(grid);

            var processList  = new RandomQueue <Vector2>();
            var samplePoints = new List <Vector2>();

            //generate the first point randomly
            //and updates
            var firstPoint = new Vector2(Random.value * rect.width, Random.value * rect.height) + new Vector2(rect.xMin, rect.yMin);

            //update containers
            processList.Push(firstPoint);
            samplePoints.Add(firstPoint);
            grid[map[firstPoint]] = firstPoint;

            //generate other points from points in queue.
            while (!processList.IsEmpty())
            {
                var point = processList.Pop();

                for (int i = 0; i < newPointsCount; i++)
                {
                    var newPoint = GenerateRandomPointAround(point, minDist);
                    //check that the point is in the image region
                    //and no points exists in the point's neighbourhood

                    if (rect.Contains(newPoint) && !IsInNeighbourhood(grid, map, newPoint, minDist))
                    {
                        if (grid.Contains(map[newPoint]))                         //TODO: why is this necessary?
                        {
                            //update containers
                            processList.Push(newPoint);
                            samplePoints.Add(newPoint);

                            grid[map[newPoint]] = newPoint;
                        }

                        /*
                         * else
                         * {
                         * Debug.Log(newPoint);
                         * Debug.Log(map[newPoint]);
                         * Debug.Break();
                         * }
                         */
                    }
                }
            }
            return(samplePoints);
        }