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

        int sizeX = Chunk.SIZE_X + 2;
        int sizeY = Chunk.SIZE_Y + 2;
        int sizeZ = Chunk.SIZE_Z + 2;

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

                    float a1 = noise.Noise(a.x, a.y, a.z);
                    float a2 = noise.Noise(b.x, a.y, a.z);
                    float a3 = noise.Noise(a.x, b.y, a.z);
                    float a4 = noise.Noise(b.x, b.y, a.z);

                    float b1 = noise.Noise(a.x, a.y, b.z);
                    float b2 = noise.Noise(b.x, a.y, b.z);
                    float b3 = noise.Noise(a.x, b.y, b.z);
                    float b4 = noise.Noise(b.x, b.y, b.z);

                    for (int tx = 0; tx < step && x + tx < sizeX; tx++)
                    {
                        for (int ty = 0; ty < step && y + ty < sizeY; ty++)
                        {
                            for (int tz = 0; tz < step && z + tz < sizeZ; tz++)
                            {
                                float fx  = (float)tx / step;
                                float fy  = (float)ty / step;
                                float fz  = (float)tz / step;
                                float ta1 = Mathf.Lerp(a1, a2, fx);
                                float ta2 = Mathf.Lerp(a3, a4, fx);
                                float ta3 = Mathf.Lerp(ta1, ta2, fy);

                                float tb1 = Mathf.Lerp(b1, b2, fx);
                                float tb2 = Mathf.Lerp(b3, b4, fx);
                                float tb3 = Mathf.Lerp(tb1, tb2, fy);

                                float val = Mathf.Lerp(ta3, tb3, fz);
                                map[x + tx, y + ty, z + tz] = val;
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 2
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++;
        }
    }