GetValue() public méthode

public GetValue ( double x, double y, double z ) : double
x double
y double
z double
Résultat double
Exemple #1
0
    private static float[] GeneratePlanetHeightmapData(PlanetArchetypes.Archetype blueprint)
    {
        float[] height = new float[textureSize * textureSize];

        LibNoise.RidgedMultifractal Generator = new LibNoise.RidgedMultifractal();
        blueprint.SetNoiseGenerator(Generator);

        float correctMin = float.MaxValue;
        float correctMax = float.MinValue;

        float currValue;

        for (int y = 0; y < textureSize; y++)
        {
            for (int x = 0; x < textureSize; x++)
            {
                currValue = (float)Generator.GetValue((float)x / textureSize, (float)y / textureSize, 1);
                if (currValue < correctMin)
                {
                    correctMin = currValue;
                }
                if (currValue > correctMax)
                {
                    correctMax = currValue;
                }
                height[x + y * textureSize] = currValue;
            }
        }

        float oldValue;

        for (int y = 0; y < textureSize; y++)
        {
            for (int x = 0; x < textureSize; x++)
            {
                float mult = (float)x / textureSize;

                oldValue  = height[x + y * textureSize];
                currValue = (float)Generator.GetValue(((float)x / textureSize) + 1, (float)y / textureSize, 1);

                float yMult = (float)y / textureSize;
                yMult = Mathf.Clamp01(11.11f * Mathf.Pow(yMult, 2) - 11.11f * yMult + 1);

                height[x + y * textureSize] = Mathf.Lerp(currValue, oldValue, mult);
                height[x + y * textureSize] = Mathf.Lerp(height[x + y * textureSize], 0, yMult);
            }
        }

        for (int y = 0; y < textureSize; y++)
        {
            for (int x = 0; x < textureSize; x++)
            {
                height[x + y * textureSize] = (height[x + y * textureSize] - correctMin) / (correctMax - correctMin);
            }
        }

        return(height);
    }
Exemple #2
0
    private static float[] GeneratePlanetHeightmapData(PlanetArchetypes.Archetype blueprint)
    {
        float[] height = new float[textureSize * textureSize];

        LibNoise.RidgedMultifractal Generator = new LibNoise.RidgedMultifractal();
        blueprint.SetNoiseGenerator(Generator);

        float correctMin = float.MaxValue;
        float correctMax = float.MinValue;

        float currValue;

        for (int y = 0; y < textureSize; y++) {
            for (int x = 0; x < textureSize; x++) {
                currValue = (float)Generator.GetValue((float)x / textureSize, (float)y / textureSize, 1);
                if (currValue < correctMin) correctMin = currValue;
                if (currValue > correctMax) correctMax = currValue;
                height[x + y * textureSize] = currValue;
            }
        }

        float oldValue;

        for (int y = 0; y < textureSize; y++) {
            for (int x = 0; x < textureSize; x++) {

                float mult = (float)x / textureSize;

                oldValue = height[x + y * textureSize];
                currValue = (float)Generator.GetValue(((float)x / textureSize) + 1, (float)y / textureSize, 1);

                float yMult = (float)y / textureSize;
                yMult = Mathf.Clamp01(11.11f * Mathf.Pow(yMult, 2) - 11.11f * yMult + 1);

                height[x + y * textureSize] = Mathf.Lerp(currValue, oldValue, mult);
                height[x + y * textureSize] = Mathf.Lerp(height[x + y * textureSize], 0, yMult);
            }
        }

        for (int y = 0; y < textureSize; y++) {
            for (int x = 0; x < textureSize; x++) {
                height[x + y * textureSize] = (height[x + y * textureSize] - correctMin) / (correctMax - correctMin);
            }
        }

        return height;
    }
Exemple #3
0
 public virtual void AddSoil(long X, long Z, RidgedMultifractal CavernNoise, Perlin CaveNoise, double[,] hm,ref byte[,,] b, BiomeType[,] biomes, int WaterHeight, int depth, MapGenMaterials mats)
 {
     int YH = b.GetLength(1) - 2;
     double xo = (double)(X * b.GetLength(0));
     double zo = (double)(Z * b.GetLength(2));
     for (int x = 0; x < b.GetLength(0); x++)
     {
         //Console.WriteLine();
         for (int z = 0; z < b.GetLength(2); z++)
         {
             double hmY=(double)(System.Math.Min(hm[x, z],1d) * (b.GetLength(1) - 3));
             bool HavePloppedGrass = false;
             bool HaveTouchedSoil = false;
             // Caves first
             if (GenerateCaves)
             {
                 for (int y = 0; y < b.GetLength(1); y++)
                 {
                     // If we're in rock, and CavernNoise value is under a threshold value calculated by height
                     //  or CaveNoise value is over threshold value, and the block we're removing won't fall on us...
                     if (
                         b[x, y, z] == 1
                         && (
                             ((CavernNoise.GetValue(x + xo, y, z + zo) / 2) + 1) < Utils.Lerp(CavernThresholdMax, CavernThresholdMin, (((double)y / (hmY + 1))))
                             || (Utils.FixLibnoiseOutput(CaveNoise.GetValue(x + xo, y, z + zo)) > CaveThreshold)
                         )
                         && !(b[x, y, z] == 9 || b[x, y, z] == 8 || b[x, y, z] == 12 || b[x, y, z] == 13))
                     {
                         // Remove it
                         b[x, y, z] = 0;
                     }
                 }
             }
             for (int y = (int)b.GetLength(1) - 1; y > 0; y--)
             {
                 byte supportBlock = b[x, y-1, z];
                 // Ensure there's going to be stuff holding us up.
                 if (b[x, y, z] == mats.Rock && supportBlock==mats.Rock)
                 {
                     HaveTouchedSoil = true;
                     if (y + depth >= YH)
                         continue;
                     byte ddt = b[x, y+depth, z];
                     switch (ddt)
                     {
                         case 0: // Air
                         case 8: // Water
                         case 9: // Water
                             BiomeType bt = biomes[x,z];
                             if (bt == BiomeType.Tundra)
                             {
                                 b[x, y, z] = mats.Sand;
                             }
                             else
                             {
                                 if (y - depth <= WaterHeight && GenerateWater)
                                 {
                                     if ((bt == BiomeType.Taiga || bt == BiomeType.TemperateForest || bt == BiomeType.Tundra) && y > WaterHeight)
                                     {
                                         b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass;
                                     }
                                     else
                                     {
                                         b[x, y, z] = mats.Sand;
                                     }
                                 }
                                 else
                                     b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass;
                             }
                             if (!HavePloppedGrass)
                                 HavePloppedGrass = true;
                             break;
                         default:
                             y = 0;
                             break;
                     }
                 }
                 else if (b[x, y, z] == 0 && y <= WaterHeight && !HaveTouchedSoil && GenerateWater)
                 {
                     b[x, y, z] = mats.Water;
                 }
             }
         }
     }
 }
 public float QueryDensity(Vector3 pos)
 {
     return((float)_generator.GetValue((double)pos.x, (double)pos.y, (double)pos.z));
 }