示例#1
0
    public static IsLandShapeGen MakeRadial(uint seed)
    {
        ParkMillerRNG isLandRandom = new ParkMillerRNG();

        isLandRandom.Seed = seed;
        uint   bumps      = isLandRandom.NextIntRange(1, 6);
        double startAngle = isLandRandom.NextDoubleRange(0, 2 * Mathf.PI);
        double dipAngle   = isLandRandom.NextDoubleRange(0, 2 * Mathf.PI);
        double dipWidth   = isLandRandom.NextDoubleRange(0.2, 0.7);

        bool inside(Vector2f q)
        {
            double angle  = Mathf.Atan2(q.y, q.x);
            float  max    = Mathf.Max(Mathf.Abs(q.x), Mathf.Abs(q.y));
            float  length = 0.5f * (max + q.magnitude);
            double f      = bumps + 3.0f;
            double r1     = 0.5f + 0.40f * System.Math.Sin(startAngle + bumps * angle + System.Math.Cos(f * angle));
            double r2     = 0.7 - 0.20 * System.Math.Sin(startAngle + bumps * angle - System.Math.Sin((bumps + 2) * angle));

            if (System.Math.Abs(angle - dipAngle) < dipWidth ||
                System.Math.Abs(angle - dipAngle + 2 * System.Math.PI) < dipWidth ||
                System.Math.Abs(angle - dipAngle - 2 * System.Math.PI) < dipWidth)
            {
                r1 = r2 = 0.2;
            }
            return(length < r1 || (length > r1 * ISLAND_FACTOR && length < r2));
        }

        IsLandShapeGen islandShapeGen = inside;

        return(islandShapeGen);
    }
示例#2
0
    public static IsLandShapeGen MakeSquare(uint seed)
    {
        bool inside(Vector2f q)
        {
            return(true);
        }

        IsLandShapeGen isLandShapeGen = inside;

        return(isLandShapeGen);
    }
示例#3
0
    public static IsLandShapeGen MakePerlin(uint seed)
    {
        bool inside(Vector2f q)
        {
            float px = (q.x + 1) * 128;
            float py = (q.y + 1) * 128;

            double c = Mathf.PerlinNoise(px + seed, py + seed);

            return(c > (0.3 + 0.3 * q.magnitude * q.magnitude));
        }

        IsLandShapeGen islandShapeGen = inside;

        return(islandShapeGen);
    }
示例#4
0
    public void NewIsLand(IsLandShapeType islandType, PointType pointType, int numPoints, uint seed, uint variant)
    {
        switch (islandType)
        {
        case IsLandShapeType.Perlin:
            IslandShapeGen = IsLandShape.MakePerlin(seed);
            break;

        case IsLandShapeType.Radial:
            IslandShapeGen = IsLandShape.MakeRadial(seed);
            break;

        case IsLandShapeType.Square:
            IslandShapeGen = IsLandShape.MakeSquare(seed);
            break;

        default:
            break;
        }

        switch (pointType)
        {
        case PointType.Random:
            PointSelectorGen = PointSelector.generateRandom(MapSize, seed);
            break;

        case PointType.Relaxed:
            PointSelectorGen = PointSelector.generateRelaxed(MapSize, seed);
            break;

        case PointType.Square:
            PointSelectorGen = PointSelector.generateSquare(MapSize, seed);
            break;

        case PointType.Hexagon:
            PointSelectorGen = PointSelector.generateHexagon(MapSize, seed);
            break;

        default:
            break;
        }

        NeedsMoreRandomness = PointSelector.needsMoreRandomness(pointType);
        NumPoints           = numPoints;
        ParkMillerRng.Seed  = variant;
    }