Example #1
0
        public void BuildTerrain()
        {
            InitBlocks(HSIZE, VSIZE, HSIZE);

            for (int x = 0; x < HSIZE; x++)
            {
                for (int z = 0; z < HSIZE; z++)
                {
                    Block lastType = Block.AIR;

                    for (int y = VSIZE - 1; y >= 0; y--)
                    {
                        NoiseWaves waves       = GetNoiseWaves(x + blockWorldOffset.X, 0, z + blockWorldOffset.Z);
                        float      blockHeight = y + blockWorldOffset.Y;

                        double density = GetDensity(waves, blockHeight);

                        if (density >= MIN_BLOCK_DENSITY)
                        {
                            if (lastType == Block.AIR)
                            {
                                Blocks[z, y, x] = lastType = Block.GRASS;
                            }
                            else
                            {
                                Blocks[z, y, x] = lastType = Block.STONE;
                            }
                        }
                    }
                }
            }

            //for (int x = 0; x < HSIZE; x++)
            //{
            //    float xf = x + Position.X / Block.CUBE_SIZE;
            //    for (int z = 0; z < HSIZE; z++)
            //    {
            //        float zf = z + Position.Z / Block.CUBE_SIZE;
            //        Block lastType = Block.AIR;

            //        for (int y = VSIZE - 1; y >= 0; y--)
            //        {
            //            float yf = y + Position.Y / Block.CUBE_SIZE;

            //            double density = p.GetValue(xf / 48, yf / 48, zf / 48);

            //            if (density >= MIN_BLOCK_DENSITY)
            //            {
            //                if (lastType == Block.AIR)
            //                    Blocks[z, y, x] = lastType = Block.GRASS;
            //                else
            //                    Blocks[z, y, x] = lastType = Block.STONE;
            //            }
            //        }
            //    }
            //}
        }
Example #2
0
        public static double GetDensity(NoiseWaves waves, float y)
        {
            double yd    = (double)y / 48;              // [0, 2]
            double yd2   = (double)y / (48 * 2 * rand); // [0, 1]
            double invYd = 1 - yd;                      // [0, 1]

            double mixedWave = Maths.Mix(waves.PrimaryWave, waves.PrimaryWave * waves.SecondaryWave, yd2);

            double density = mixedWave - (yd / 2d);

            density = Maths.ReScale(density, -1, 1, -0.8 + invYd, 0.9);

            return(density);
        }