예제 #1
0
        TerrainVertex GainVertex(int X, int Y, int DX, int DY, int Seed = 0)
        {
            TerrainVertex v = new TerrainVertex();

            float One32nd = 1.0f / 64.0f;

            v.Position.X = X;
            v.Position.Z = Y;
            int MapX = X + DX * (BlockSize);
            int MapY = Y + DY * (BlockSize);
            // Z = 0;
            // v.Position.Y= noise.PerlinNoise3F(MapX, MapY, Z, 1, One32nd / 1, One32nd / 1, One32nd / 1);
            //*
            //  v.Position.Y *= 10;
            //v.Position.Y += 6;
            // v.Position.Y *= 10;
            float to256 = 1 / 256;
            float H     = 0.0f;

            Simplex.Seed = this.Seed;
            MapY        += 65535;
            MapX        += 65535;
            //land/water scaling
            H = Simplex.CalcPixel2D(MapX, MapY, 1f / 16384f) - 35f;
            //values from -35 to 220ish.
            H += (Simplex.CalcPixel2D(MapX, MapY, 1f / 256) / 16);
            //+-16 variation, values -51..246
            float Hills = Simplex.CalcPixel2D(MapX, MapY, 1f / 256) - 128;

            Hills /= 16;
            //+-8 noise
            //*/
            v.Position.Y = H;
            float Temp = Simplex.CalcPixel2D(MapX, MapY, 1f / 4024f);
            //0 to 255 temp
            int Blend1 = Math.Min((int)(Temp * 2), 160);
            int Blend2 = Math.Min((510 - (int)(Temp * 2)), 200);

            Color grass = new Color(Blend1, Blend2, 0);
            Color sea   = new Color(0, 50, 255);
            Color Snow  = new Color(245, 245, 255);
            Color sand  = new Color(200, 200, 100);
            Color sand2 = new Color(150, 150, 50);

            sea     = sand;
            v.Color = grass;
            // v.Color =
            float BeachRange     = 12;
            float SnowRange      = 185;
            float GroundBaseline = WaterHeight + BeachRange;

            if (H < WaterHeight)
            {
                v.MultiTexData.Z = 1;
                v.Color          = sea;
            }
            if (H > WaterHeight && H < GroundBaseline)
            {
                float dif = H - WaterHeight;
                dif             /= BeachRange;
                dif              = (float)Math.Pow(dif, 7.3);
                v.Position.Y     = WaterHeight + dif * BeachRange;
                v.Color          = sand;
                v.MultiTexData.Z = 1;
            }

            if (H > GroundBaseline)
            {
                unchecked
                {
                    Simplex.Seed = Simplex.Seed ^ (int)0xFFFFFFFF;
                }
                //hill horizontal scale
                float random1 = Simplex.CalcPixel2D(MapX + 1112, MapY + 13123, 2f) / 512f;
                float random2 = Simplex.CalcPixel2D(MapX + 1112, MapY + 13123, 1f) / 1024f;

                float ground    = Simplex.CalcPixel2D(MapX + 1112, MapY + 13123, 0.0006125f / 1f);
                float beachdist = H - GroundBaseline;
                float evenness  = 16f;
                ground    /= 256f;
                ground     = (float)(Math.Pow(ground, 4.4));
                ground    *= 256f;
                beachdist /= evenness;
                beachdist  = MathHelper.Clamp(beachdist, 0.0f, 1.0f);
                float finalground = GroundBaseline + ground * beachdist + Hills * beachdist + (random1 + random2) * beachdist;


                v.Position.Y = finalground;// + random1 + random2;

                v.MultiTexData.Z = (float)Math.Pow((float)MathHelper.Clamp((((Temp / 2f) - finalground + 76f) / 100f), 0f, 1f), 3f);
                if (v.MultiTexData.Z < 0.2f)
                {
                    v.MultiTexData.Z = 0f;
                }
                if (finalground > SnowRange)
                {
                    v.Color          = Snow;
                    v.MultiTexData.Z = 0.20f;
                }
            }
            //  v.Color = new Color(Math.Min(255, (int)H), 0, 0);
            v.TextureCoordinate.X = X / 4f;
            v.TextureCoordinate.Y = Y / 4f;
            v.Normal = new Vector3(0, 0, 0);
            // v.Position.Y = 6;
            return(v);
        }