Ejemplo n.º 1
0
        void CreateHeightmap()
        {
            Noise n1 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            Noise n2 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            Noise n3    = new OctaveNoise(6, rnd);
            int   index = 0;

            short[] hMap = new short[width * length];
            CurrentState = "Building heightmap";

            for (int z = 0; z < length; z++)
            {
                CurrentProgress = (float)z / length;
                for (int x = 0; x < width; x++)
                {
                    double hLow  = n1.Compute(x * 1.3f, z * 1.3f) / 6 - 4;
                    double hHigh = n2.Compute(x * 1.3f, z * 1.3f) / 5 + 6;

                    double height = n3.Compute(x, z) > 0 ? hLow : Math.Max(hLow, hHigh);
                    height *= 0.5;
                    if (height < 0)
                    {
                        height *= 0.8f;
                    }
                    hMap[index++] = (short)(height + waterLevel);
                }
            }
            heightmap = hMap;
        }
Ejemplo n.º 2
0
        /* ========================= */
        /* ===== OLD FUNCTIONS ===== */
        /* ========================= */

        void CreateHeightmap()
        {
            CombinedNoise n1 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            CombinedNoise n2 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            OctaveNoise n3    = new OctaveNoise(6, rnd);
            int         index = 0;

            short[] hMap = new short[Width * Length];
            CurrentState = "Building heightmap";

            for (int z = 0; z < Length; z++)
            {
                CurrentProgress = (float)z / Length;
                for (int x = 0; x < Width; x++)
                {
                    double hLow = n1.Compute(x * 1.3f, z * 1.3f) / 6 - 4, height = hLow;
                    double hHigh = n2.Compute(x * 1.3f, z * 1.3f) / 5 + 6;

                    if (n3.Compute(x, z) <= 0)
                    {
                        height = Math.Max(hLow, hHigh);
                    }

                    /*if (x == 135 && z == 138) {
                     *      double nose = n3.Compute(x, z) / 8;
                     *      Console.WriteLine(nose.ToString());
                     * }*/

                    height *= 0.5;
                    if (height < 0)
                    {
                        height *= 0.8f;
                    }

                    double erode = n3.Compute(x, z);

                    //if (n3.Compute(x, z) > 3.0 && hHigh < hLow) {
                    if (erode / 8 <= hLow && Closer(hLow, hHigh, erode / 4) == hLow && erode >= 0)
                    {
                        //if (n3.Compute(x * 1.3, z * 1.3) / 6 < -0.5 || n3.Compute(x * 1.3, z * 1.3) / 6 > 1.5) {
                        if ((short)height % 2 != 0 && (short)height > 0)
                        {
                            height -= 1;
                        }
                    }

                    short adjHeight = (short)(height + waterLevel);
                    minHeight     = adjHeight < minHeight ? adjHeight : minHeight;
                    hMap[index++] = adjHeight;
                }
            }
            heightmap = hMap;
        }
Ejemplo n.º 3
0
        void CreateChunkHeightmap(int chunkX, int chunkZ, CombinedNoise n1, CombinedNoise n2, OctaveNoise n3)
        {
            /*CombinedNoise n1 = new CombinedNoise(
             *      new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
             * CombinedNoise n2 = new CombinedNoise(
             *      new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
             * OctaveNoise n3 = new OctaveNoise(6, rnd);*/
            int index = 0;
            //short[] hMap = new short[16 * 16];
            int offsetX = (chunkX * 16);
            int offsetZ = (chunkZ * 16);

            CurrentState = "Building heightmap";

            for (int z = 0; z < 16; z++)
            {
                int zCur = z + offsetZ;
                CurrentProgress = (float)z / Length;
                for (int x = 0; x < 16; x++)
                {
                    int xCur = x + offsetX;
                    if (xCur >= Width || zCur >= Length)
                    {
                        break;
                    }
                    double hLow = n1.Compute(xCur * 1.3f, zCur * 1.3f) / 6 - 4, height = hLow;

                    if (n3.Compute(xCur, zCur) <= 0)
                    {
                        double hHigh = n2.Compute(xCur * 1.3f, zCur * 1.3f) / 5 + 6;
                        height = Math.Max(hLow, hHigh);
                    }

                    height *= 0.5;
                    if (height < 0)
                    {
                        height *= 0.8f;
                    }

                    short adjHeight = (short)(height + waterLevel);
                    minHeight        = adjHeight < minHeight ? adjHeight : minHeight;
                    index            = zCur * Width + xCur;
                    heightmap[index] = adjHeight;
                }
            }
            //heightmap = hMap;
        }
        void CreateHeightmap()
        {
            CombinedNoise n1 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            CombinedNoise n2 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            OctaveNoise n3    = new OctaveNoise(6, rnd);
            int         index = 0;

            short[] hMap = new short[Width * Length];
            CurrentState = "Building heightmap";

            for (int z = 0; z < Length; z++)
            {
                CurrentProgress = (float)z / Length;
                for (int x = 0; x < Width; x++)
                {
                    double hLow = n1.Compute(x * 1.3f, z * 1.3f) / 6 - 4, height = hLow;

                    if (n3.Compute(x, z) <= 0)
                    {
                        double hHigh = n2.Compute(x * 1.3f, z * 1.3f) / 5 + 6;
                        height = Math.Max(hLow, hHigh);
                    }

                    height *= 0.5;
                    if (height < 0)
                    {
                        height *= 0.8f;
                    }

                    short adjHeight = (short)(height + waterLevel);
                    minHeight     = adjHeight < minHeight ? adjHeight : minHeight;
                    hMap[index++] = adjHeight;
                }
            }
            heightmap = hMap;
        }
        void CreateHeightmap()
        {
            Noise n1 = new CombinedNoise(
                new OctaveNoise( 8, rnd ), new OctaveNoise( 8, rnd ) );
            Noise n2 = new CombinedNoise(
                new OctaveNoise( 8, rnd ), new OctaveNoise( 8, rnd ) );
            Noise n3 = new OctaveNoise( 6, rnd );
            int index = 0;
            short[] hMap = new short[width * length];
            CurrentState = "Building heightmap";

            for( int z = 0; z < length; z++ ) {
                CurrentProgress = (float)z / length;
                for( int x = 0; x < width; x++ ) {
                    double hLow = n1.Compute( x * 1.3f, z * 1.3f ) / 6 - 4;
                    double hHigh = n2.Compute( x * 1.3f, z * 1.3f ) / 5 + 6;

                    double height = n3.Compute( x, z ) > 0 ? hLow : Math.Max( hLow, hHigh );
                    height *= 0.5;
                    if( height < 0 ) height *= 0.8f;
                    hMap[index++] = (short)(height + waterLevel);
                }
            }
            heightmap = hMap;
        }