GetValue() public method

public GetValue ( double x, double y, double z ) : double
x double
y double
z double
return double
 public override void Setup()
 {
     double xoff = 0;
     Perlin rnd = new Perlin();
     for (int i = 0; i < 100; i++)
     {
         double yoff = 0;
         for (int j = 0; j <100; j++)
         {
             circ.Add(new Circle(new Point3d(i, j, 0), rnd.GetValue(xoff, yoff, 0) * -1));
             //RhinoApp.WriteLine(String.Format("{0}", circ[j].Radius));
             yoff += 0.01;
         }
         xoff += 0.01;
     }
 }
Ejemplo n.º 2
0
    public void Initiaiise()
    {
        this.internalWidth = ( displayWidth * 3 ) / 2;
        this.tileTable = new List<List<HexTile>>( this.displayHeight );

        for ( int y = 0; y < this.displayHeight; ++y )
        {
            this.tileTable.Add( new List<HexTile>( this.internalWidth ) );

            for ( int x = 0; x < this.internalWidth; ++x )
            {
                if ( this.IsValidDisplayableTile( x, y ) )
                {
                    HexTile hex = this.CreateTile( x, y );
                    this.tileTable[y].Add( hex );
                }
                else
                {
                    this.tileTable[y].Add( null );
                }
            }
        }

        this.availableTiles = this.GetAvailableTiles();
        this.BuildNeighbourConnections();

        LibNoise.Perlin perlin = new LibNoise.Perlin();
        perlin.Frequency *= 5.0f;
        Debug.Log( perlin.Frequency + " : " + perlin.Lacunarity + " : " + perlin.NoiseQuality + " : " + perlin.OctaveCount + " : " + perlin.Persistence + " : " + perlin.Seed );
        perlin.Seed = UnityEngine.Random.Range( 0, 1000 );

        float min = float.MaxValue;
        float max = float.MinValue;
        foreach ( HexTile tile in this.availableTiles )
        {
            tile.terrainData.fuelLoad = ((float)perlin.GetValue( (double)tile.x/(double)this.internalWidth, (double)tile.y/(double)this.displayHeight, 0.0 ) + 1.0f) / 2.0f;

            tile.tileOverlay.SetFuelOverlay();
            min = Mathf.Min( min, tile.terrainData.fuelLoad );
            max = Mathf.Max( max, tile.terrainData.fuelLoad );
        }
        Debug.Log( "Min: " + min + " max: " + max );
    }
Ejemplo n.º 3
0
        public double GetValue(double x, double y, double z)
        {
            if (SourceModule == null)
            {
                throw new NullReferenceException();
            }

            // Get the values from the three noise::module::Perlin noise modules and
            // add each value to each coordinate of the input value.  There are also
            // some offsets added to the coordinates of the input values.  This prevents
            // the distortion modules from returning zero if the (x, y, z) coordinates,
            // when multiplied by the frequency, are near an integer boundary.  This is
            // due to a property of gradient coherent noise, which returns zero at
            // integer boundaries.
            double x0, y0, z0;
            double x1, y1, z1;
            double x2, y2, z2;

            x0 = x + (12414.0 / 65536.0);
            y0 = y + (65124.0 / 65536.0);
            z0 = z + (31337.0 / 65536.0);
            x1 = x + (26519.0 / 65536.0);
            y1 = y + (18128.0 / 65536.0);
            z1 = z + (60493.0 / 65536.0);
            x2 = x + (53820.0 / 65536.0);
            y2 = y + (11213.0 / 65536.0);
            z2 = z + (44845.0 / 65536.0);
            double xDistort = x + (XDistort.GetValue(x0, y0, z0)
                                   * Power);
            double yDistort = y + (YDistort.GetValue(x1, y1, z1)
                                   * Power);
            double zDistort = z + (ZDistort.GetValue(x2, y2, z2)
                                   * Power);

            // Retrieve the output value at the offsetted input value instead of the
            // original input value.
            return(SourceModule.GetValue(xDistort, yDistort, zDistort));
        }
Ejemplo n.º 4
0
 public static float noise(float x, float y, float z, float s)
 {
     return((float)heightNoise.GetValue(x * s, y * s, z * s));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Generates a new world and then sets the tiles in the TileSystem to it.
        /// </summary>
        /// <param name="seed"></param>
        /// <param name="threaded">If true, the world will generate on another thread.</param>
        public void GenerateWorld(int? seed, bool threaded)
        {
            this.SetSeed(seed);

            if (threaded)
            {
                new Thread(() => this.GenerateWorld(this.Seed, false)).Start();

                return;
            }
            var sw = new Stopwatch();
            sw.Start();

            tileSystem.ClearTiles();

            var perlin = new Perlin() { Seed = this.Seed };

            Console.WriteLine("[WorldGeneration]: Generating terrain...");

            // First part: Generate landscape
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    double pVal = perlin.GetValue(x / 500d, y / 500d, 0);
                    double cpVal = (pVal + 1.975) / 2;
                    cpVal = MathHelper.Clamp((float)cpVal, 0f, 1f);
                    var color = new Color((byte)(cpVal * 255), (byte)(cpVal * 255), (byte)(cpVal * 255), 255);

                    if (pVal > 0.00)
                    {
                        tileSystem.Tiles[0][x, y] = new Tile(Tile.TileId.Grass, Tile.Solidity.NonSolid, SourceRects.Grass, Color.White, Tile.TileSide.Middle);

                        if (rand.NextDouble() <= 0.0005)
                        {
                            seeds.Add(new BigTree(x, y, ref tileSystem));
                        }
                    }
                    else if (pVal <= 0.00 && pVal >= -0.10)
                    {
                        tileSystem.Tiles[0][x, y] = new Tile(
                            Tile.TileId.Sand, Tile.Solidity.NonSolid, SourceRects.SandMiddle, Color.White, Tile.TileSide.Middle);
                    }
                    else if(pVal >= -0.15)
                    {
                        tileSystem.Tiles[0][x, y] = new Tile(
                            Tile.TileId.ShallowWater, Tile.Solidity.NonSolid, SourceRects.ShallowWaterMiddle, Color.White, Tile.TileSide.Middle);
                    }
                    else
                    {
                        color = new Color((byte)(color.R / 1.5f), (byte)(color.G / 1.5f), (byte)(color.B / 1.5f), 255);
                        tileSystem.Tiles[0][x, y] = new Tile(Tile.TileId.Water, Tile.Solidity.NonSolid, SourceRects.Water, color, Tile.TileSide.Middle);
                    }
                }
            }

            // Grow seeds

            foreach (Seed seed1 in seeds)
            {
                seed1.Grow();
            }

            Console.WriteLine("[WorldGeneration]: Finished terrain, smoothing terrain...");

            // Last part: Polish up terrain a bit
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    tileSystem.PolishTile(y, x);
                }
            }

            Console.WriteLine("[WorldGeneration]: Finished edges. Doing inner edges...");

            // Has to be done after doing edges, else it won't be correct in some cases.
            for (int y = 0; y < Height; y++)
                for (int x = 0; x < Width; x++)
                {
                    tileSystem.PolishInnerGrass(
                        x,
                        y,
                        SourceRects.SandToGrassInnerTopLeft,
                        SourceRects.SandToGrassInnerTopRight,
                        SourceRects.SandToGrassInnerBottomLeft,
                        SourceRects.SandToGrassInnerBottomRight);
                }

            sw.Stop();
            Console.WriteLine("Generation time: " + sw.ElapsedMilliseconds + "ms");
        }
Ejemplo n.º 6
0
        private Vector3[] generateUpperVertices(int upperVertCount, float frequencyMultiplier)
        {
            //block count == (height - 1) / 3
            //vertex count per block == 5
            //index count per block == 9

            int heightCount = upperVertCount; //height count should be (divisable by three) + 1
            Vector3[] height = new Vector3[heightCount]; //*2 + 1

            Perlin perlin = new Perlin();
            perlin.Seed = DateTime.Now.Millisecond;
            float x = 0;
            float multiplier = frequencyMultiplier;

            for (int i = 0; i < height.Length; i++)
            {
                float value = (float)perlin.GetValue(x + 0.005f * i, 0, 0);
                value += 1;
                value = value / 2;
                value += 0.3f;
                height[i] = new Vector3(x, value, 0);
                x += 1.5f / (multiplier + 500);
            }

            return height;
        }
Ejemplo n.º 7
0
 public virtual void AddSoil(long X, long Z, RidgedMultifractal CavernNoise, Perlin CaveNoise, double[,] hm,ref byte[,,] b, BiomeType[,] biomes, int WaterHeight, int depth, MapGenMaterials mats)
 {
     int YH = b.GetLength(1) - 2;
     double xo = (double)(X * b.GetLength(0));
     double zo = (double)(Z * b.GetLength(2));
     for (int x = 0; x < b.GetLength(0); x++)
     {
         //Console.WriteLine();
         for (int z = 0; z < b.GetLength(2); z++)
         {
             double hmY=(double)(System.Math.Min(hm[x, z],1d) * (b.GetLength(1) - 3));
             bool HavePloppedGrass = false;
             bool HaveTouchedSoil = false;
             // Caves first
             if (GenerateCaves)
             {
                 for (int y = 0; y < b.GetLength(1); y++)
                 {
                     // If we're in rock, and CavernNoise value is under a threshold value calculated by height
                     //  or CaveNoise value is over threshold value, and the block we're removing won't fall on us...
                     if (
                         b[x, y, z] == 1
                         && (
                             ((CavernNoise.GetValue(x + xo, y, z + zo) / 2) + 1) < Utils.Lerp(CavernThresholdMax, CavernThresholdMin, (((double)y / (hmY + 1))))
                             || (Utils.FixLibnoiseOutput(CaveNoise.GetValue(x + xo, y, z + zo)) > CaveThreshold)
                         )
                         && !(b[x, y, z] == 9 || b[x, y, z] == 8 || b[x, y, z] == 12 || b[x, y, z] == 13))
                     {
                         // Remove it
                         b[x, y, z] = 0;
                     }
                 }
             }
             for (int y = (int)b.GetLength(1) - 1; y > 0; y--)
             {
                 byte supportBlock = b[x, y-1, z];
                 // Ensure there's going to be stuff holding us up.
                 if (b[x, y, z] == mats.Rock && supportBlock==mats.Rock)
                 {
                     HaveTouchedSoil = true;
                     if (y + depth >= YH)
                         continue;
                     byte ddt = b[x, y+depth, z];
                     switch (ddt)
                     {
                         case 0: // Air
                         case 8: // Water
                         case 9: // Water
                             BiomeType bt = biomes[x,z];
                             if (bt == BiomeType.Tundra)
                             {
                                 b[x, y, z] = mats.Sand;
                             }
                             else
                             {
                                 if (y - depth <= WaterHeight && GenerateWater)
                                 {
                                     if ((bt == BiomeType.Taiga || bt == BiomeType.TemperateForest || bt == BiomeType.Tundra) && y > WaterHeight)
                                     {
                                         b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass;
                                     }
                                     else
                                     {
                                         b[x, y, z] = mats.Sand;
                                     }
                                 }
                                 else
                                     b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass;
                             }
                             if (!HavePloppedGrass)
                                 HavePloppedGrass = true;
                             break;
                         default:
                             y = 0;
                             break;
                     }
                 }
                 else if (b[x, y, z] == 0 && y <= WaterHeight && !HaveTouchedSoil && GenerateWater)
                 {
                     b[x, y, z] = mats.Water;
                 }
             }
         }
     }
 }