Exemplo n.º 1
0
    public void GenerateNoise(Vector2i offset)
    {
        this.offset = offset;

        int sizeX = map.GetLength(0);
        int sizeZ = map.GetLength(1);

        for (int x = 0; x < sizeX; x += step)
        {
            for (int y = 0; y < sizeZ; y += step)
            {
                Vector2i a = new Vector2i(x, y) + offset;
                Vector2i b = a + new Vector2i(step, step);

                float v1 = noise.Noise(a.x, a.y);
                float v2 = noise.Noise(b.x, a.y);
                float v3 = noise.Noise(a.x, b.y);
                float v4 = noise.Noise(b.x, b.y);

                for (int tx = 0; tx < step && x + tx < sizeX; tx++)
                {
                    for (int ty = 0; ty < step && y + ty < sizeZ; ty++)
                    {
                        float fx = (float)tx / step;
                        float fy = (float)ty / step;
                        float i1 = Mathf.Lerp(v1, v2, fx);
                        float i2 = Mathf.Lerp(v3, v4, fx);
                        map[x + tx, y + ty] = Mathf.Lerp(i1, i2, fy);
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    float CalculatePerlinNoiseHeight(int x, int z)
    {
        float xCoordValue = (((float)x + pNoiseOffsetX) / xSize) * scale;
        float zCoordValue = (((float)z + pNoiseOffsetZ) / zSize) * scale;

        float perlinNoiseHeight = perlinNoise2D.Noise(xCoordValue, zCoordValue) * depth;

        return(perlinNoiseHeight);
    }
Exemplo n.º 3
0
 /// <summary>
 /// 頂点座標を動かす
 /// </summary>
 /// <remarks>ノイズを重ねる</remarks>
 /// <param name="peeks">頂点座標</param>
 /// <param name="chunkWorldPos">チャンク座標のワールド座標</param>
 /// <param name="amplitude">波の大きさ</param>
 /// <param name="wavePeriod">波の周期</param>
 private void MovePeeks(int[,] peeks, IntVector3 chunkWorldPos, float amplitude, float wavePeriod)
 {
     for (int z = 0, iEnd = peeks.GetLength(0); z < iEnd; z++)
     {
         for (int x = 0, jEnd = peeks.GetLength(1); x < jEnd; x++)
         {
             // パーリンノイズの結果を四捨五入してから頂点の座標とする
             peeks[z, x] += Mathf.RoundToInt(noiseGenerator.Noise((chunkWorldPos.x + x) / wavePeriod, (chunkWorldPos.z + z) / wavePeriod) * amplitude);
         }
     }
 }
Exemplo n.º 4
0
    //Helper method to generate out a single x,y section of the terrain
    private void Generate(int cx, int cz)
    {
        int h1 = (int)(noise1.Noise(cx, cz) * 4);

        if (h1 < 0)
        {
            h1 *= -1;
        }

        h1 = (h1) < 3? 3: (h1);
        h1 = (h1) > 8? 8 : h1;

        int h2 = (int)(noise2.Noise(cx, cz) * 2);

        h2  = h2 < 0 ? 0: h2;
        h2  = 6 > h2 ? 6: h2;
        h2 += h1;

        int deep   = 0;
        int worldY = h2;

        for (; worldY > h1; worldY--)
        {
            if (noise3d.Noise(cx, worldY, cz) < 0)
            {
                GenerateBlock(cx, worldY, cz, deep);
                deep++;
            }
            else
            {
                deep = 0;
            }
        }

        for (; worldY >= 0; worldY--)
        {
            GenerateBlock(cx, worldY, cz, deep);
            deep++;
        }
    }