Exemplo n.º 1
0
        public void RandomizeHeights(int LevelCount)
        {
            var    hmSource         = new clsHeightmap();
            var    hmA              = new clsHeightmap();
            var    hmB              = new clsHeightmap();
            var    IntervalCount    = 0;
            var    AlterationLevels = new clsHeightmap.sHeights();
            var    hmAlteration     = new sHeightmaps();
            float  LevelHeight      = 0;
            double HeightRange      = 0;
            var    Level            = 0;
            double IntervalHeight   = 0;
            double Variation        = 0;
            var    X = 0;
            var    Y = 0;

            IntervalCount = LevelCount - 1;

            AlterationLevels.Heights = new float[IntervalCount + 1];
            var MinMax = new clsHeightmap.sMinMax();

            hmAlteration.Heightmaps    = new clsHeightmap[IntervalCount + 1];
            hmSource.HeightData.Height = new long[Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1];
            hmSource.HeightData.SizeX  = Terrain.TileSize.X + 1;
            hmSource.HeightData.SizeY  = Terrain.TileSize.Y + 1;
            for (Y = 0; Y <= Terrain.TileSize.Y; Y++)
            {
                for (X = 0; X <= Terrain.TileSize.X; X++)
                {
                    hmSource.HeightData.Height[Y, X] = Convert.ToInt32(Terrain.Vertices[X, Y].Height / hmSource.HeightScale);
                }
            }
            hmSource.MinMaxGet(ref MinMax);
            HeightRange    = 255.0D;
            IntervalHeight = HeightRange / IntervalCount;
            Variation      = IntervalHeight / 4.0D;
            for (Level = 0; Level <= IntervalCount; Level++)
            {
                LevelHeight =
                    Convert.ToSingle(Convert.ToDouble(MinMax.Min + Convert.ToInt32(Level * MinMax.Max / IntervalCount)) * hmSource.HeightScale);
                AlterationLevels.Heights[Level] = LevelHeight;
                hmB.GenerateNewOfSize(Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1, 2.0F, 10000.0D);
                hmAlteration.Heightmaps[Level] = new clsHeightmap();
                hmAlteration.Heightmaps[Level].Rescale(hmB, LevelHeight - Variation, LevelHeight + Variation);
            }
            hmA.FadeMultiple(hmSource, ref hmAlteration, ref AlterationLevels);
            hmB.Rescale(hmA, Math.Max(Convert.ToDouble(Convert.ToDouble(MinMax.Min * hmSource.HeightScale) - Variation), 0.0D),
                        Math.Min(Convert.ToDouble(Convert.ToDouble(MinMax.Max * hmSource.HeightScale) + Variation), 255.9D));
            for (Y = 0; Y <= Terrain.TileSize.Y; Y++)
            {
                for (X = 0; X <= Terrain.TileSize.X; X++)
                {
                    Terrain.Vertices[X, Y].Height = Convert.ToByte((hmB.HeightData.Height[Y, X] * hmB.HeightScale));
                }
            }
        }
Exemplo n.º 2
0
        public void RandomizeHeights(int LevelCount)
        {
            var hmSource = new clsHeightmap();
            var hmA = new clsHeightmap();
            var hmB = new clsHeightmap();
            var IntervalCount = 0;
            var AlterationLevels = new clsHeightmap.sHeights();
            var hmAlteration = new sHeightmaps();
            float LevelHeight = 0;
            double HeightRange = 0;
            var Level = 0;
            double IntervalHeight = 0;
            double Variation = 0;
            var X = 0;
            var Y = 0;

            IntervalCount = LevelCount - 1;

            AlterationLevels.Heights = new float[IntervalCount + 1];
            var MinMax = new clsHeightmap.sMinMax();
            hmAlteration.Heightmaps = new clsHeightmap[IntervalCount + 1];
            hmSource.HeightData.Height = new long[Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1];
            hmSource.HeightData.SizeX = Terrain.TileSize.X + 1;
            hmSource.HeightData.SizeY = Terrain.TileSize.Y + 1;
            for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X; X++ )
                {
                    hmSource.HeightData.Height[Y, X] = Convert.ToInt32(Terrain.Vertices[X, Y].Height / hmSource.HeightScale);
                }
            }
            hmSource.MinMaxGet(ref MinMax);
            HeightRange = 255.0D;
            IntervalHeight = HeightRange / IntervalCount;
            Variation = IntervalHeight / 4.0D;
            for ( Level = 0; Level <= IntervalCount; Level++ )
            {
                LevelHeight =
                    Convert.ToSingle(Convert.ToDouble(MinMax.Min + Convert.ToInt32(Level * MinMax.Max / IntervalCount)) * hmSource.HeightScale);
                AlterationLevels.Heights[Level] = LevelHeight;
                hmB.GenerateNewOfSize(Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1, 2.0F, 10000.0D);
                hmAlteration.Heightmaps[Level] = new clsHeightmap();
                hmAlteration.Heightmaps[Level].Rescale(hmB, LevelHeight - Variation, LevelHeight + Variation);
            }
            hmA.FadeMultiple(hmSource, ref hmAlteration, ref AlterationLevels);
            hmB.Rescale(hmA, Math.Max(Convert.ToDouble(Convert.ToDouble(MinMax.Min * hmSource.HeightScale) - Variation), 0.0D),
                Math.Min(Convert.ToDouble(Convert.ToDouble(MinMax.Max * hmSource.HeightScale) + Variation), 255.9D));
            for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X; X++ )
                {
                    Terrain.Vertices[X, Y].Height = Convert.ToByte((hmB.HeightData.Height[Y, X] * hmB.HeightScale));
                }
            }
        }