Esempio n. 1
0
        private VoronoiImpl(NoiseModule frequency, VoronoiType type)
        {
            NumberFormatInfo nfi = new NumberFormatInfo();

            nfi.NumberGroupSeparator   = "";
            nfi.NumberDecimalSeparator = ".";

            genCode(frequency.Code, getVoronoiFunction(type));
        }
Esempio n. 2
0
 public Voronoi()
 {
     DropOff     = 0.6f;
     FallOff     = 0.2f;
     MinHeight   = 0.6f;
     MaxHeight   = 0.2f;
     PeaksAmount = 1;
     Type        = VoronoiType.Linear;
 }
Esempio n. 3
0
        private string getVoronoiFunction(VoronoiType type)
        {
            switch (type)
            {
            case VoronoiType.Cell:
                return("voronoiCell");

            case VoronoiType.F1:
                return("voronoiF1");

            case VoronoiType.F2:
                return("voronoiF2");

            case VoronoiType.F3:
                return("voronoiF3");

            case VoronoiType.F2F1:
                return("voronoiF2F1");

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Generates a mosaic pattern
 /// </summary>
 /// <param name="frequency">The scale of the noise</param>
 /// <param name="type">Type of Voronoi</param>
 /// <returns>NoiseModule</returns>
 public static NoiseModule Voronoi(NoiseModule frequency, VoronoiType type)
 {
     return(VoronoiImpl.ValueOf(frequency, type));
 }
Esempio n. 5
0
 public void setVoronoiPreset(voronoiPresetData preset)
 {
     generatorTypeInt = 0;
     generatorType = GeneratorType.Voronoi;
     voronoiTypeInt = (int) preset.voronoiType;
     voronoiType = preset.voronoiType;
     voronoiCells = preset.voronoiCells;
     voronoiFeatures = preset.voronoiFeatures;
     voronoiScale = preset.voronoiScale;
     voronoiBlend = preset.voronoiBlend;
 }
Esempio n. 6
0
 public voronoiPresetData(string pn, VoronoiType vt, int c, float vf, float vs, float vb)
 {
     presetName = pn;
     voronoiType = vt;
     voronoiCells = c;
     voronoiFeatures = vf;
     voronoiScale = vs;
     voronoiBlend = vb;
 }
Esempio n. 7
0
 // -------------------------------------------------------------------------------------------------------- UTILITIES
 private void convertIntVarsToEnums()
 {
     switch (erosionTypeInt) {
         case 0:
         erosionType = ErosionType.Thermal;
         break;
         case 1:
         erosionType = ErosionType.Hydraulic;
         break;
         case 2:
         erosionType = ErosionType.Tidal;
         break;
         case 3:
         erosionType = ErosionType.Wind;
         break;
         case 4:
         erosionType = ErosionType.Glacial;
         break;
     }
     switch (hydraulicTypeInt) {
         case 0:
         hydraulicType = HydraulicType.Fast;
         break;
         case 1:
         hydraulicType = HydraulicType.Full;
         break;
         case 2:
         hydraulicType = HydraulicType.Velocity;
         break;
     }
     switch (generatorTypeInt) {
         case 0:
         generatorType = GeneratorType.Voronoi;
         break;
         case 1:
         generatorType = GeneratorType.DiamondSquare;
         break;
         case 2:
         generatorType = GeneratorType.Perlin;
         break;
         case 3:
         generatorType = GeneratorType.Smooth;
         break;
         case 4:
         generatorType = GeneratorType.Normalise;
         break;
     }
     switch (voronoiTypeInt) {
         case 0:
         voronoiType = VoronoiType.Linear;
         break;
         case 1:
         voronoiType = VoronoiType.Sine;
         break;
         case 2:
         voronoiType = VoronoiType.Tangent;
         break;
     }
     switch (neighbourhoodInt) {
         case 0:
         neighbourhood = Neighbourhood.Moore;
         break;
         case 1:
         neighbourhood = Neighbourhood.VonNeumann;
         break;
     }
 }
Esempio n. 8
0
 public void VoronoiGenerator(FeatureType featureType, int cells, float features, float scale, float blend)
 {
     generatorTypeInt = 0;
     generatorType = GeneratorType.Voronoi;
     switch (featureType) {
         case FeatureType.Mountains:
         voronoiTypeInt = 0;
         voronoiType = VoronoiType.Linear;
         break;
         case FeatureType.Hills:
         voronoiTypeInt = 1;
         voronoiType = VoronoiType.Sine;
         break;
         case FeatureType.Plateaus:
         voronoiTypeInt = 2;
         voronoiType = VoronoiType.Tangent;
         break;
     }
     voronoiCells = cells;
     voronoiFeatures = features;
     voronoiScale = scale;
     voronoiBlend = blend;
     GeneratorProgressDelegate generatorProgressDelegate = new GeneratorProgressDelegate(dummyGeneratorProgress);
     generateTerrain(generatorProgressDelegate);
 }
Esempio n. 9
0
        float Calculate(float x, float y, float z, VoronoiType type)
        {
            Result distanceResult;

            int xci = 0;
            int yci = 0;
            int zci = 0;

            float value = 0;

            switch (type)
            {
                case VoronoiType.First:
                    {
                        Calculate(x, y, z, out distanceResult);

                        xci = NoiseHelper.Floor(distanceResult.Position0.X);
                        yci = NoiseHelper.Floor(distanceResult.Position0.Y);
                        zci = NoiseHelper.Floor(distanceResult.Position0.Z);

                        if (distanceEnabled)
                            value = distanceResult.Distance0;

                        return value + displacement * GetPosition(xci, yci, zci, 0);
                    }
                case VoronoiType.Second:
                    {
                        Calculate(x, y, z, out distanceResult);

                        xci = NoiseHelper.Floor(distanceResult.Position1.X);
                        yci = NoiseHelper.Floor(distanceResult.Position1.Y);
                        zci = NoiseHelper.Floor(distanceResult.Position1.Z);

                        if (distanceEnabled)
                            value = distanceResult.Distance1;

                        return value + displacement * GetPosition(xci, yci, zci, 0);
                    }
                case VoronoiType.Third:
                    {
                        Calculate(x, y, z, out distanceResult);

                        xci = NoiseHelper.Floor(distanceResult.Position2.X);
                        yci = NoiseHelper.Floor(distanceResult.Position2.Y);
                        zci = NoiseHelper.Floor(distanceResult.Position2.Z);

                        if (distanceEnabled)
                            value = distanceResult.Distance2;

                        return value + displacement * GetPosition(xci, yci, zci, 0);
                    }
                case VoronoiType.Fourth:
                    {
                        Calculate(x, y, z, out distanceResult);

                        xci = NoiseHelper.Floor(distanceResult.Position3.X);
                        yci = NoiseHelper.Floor(distanceResult.Position3.Y);
                        zci = NoiseHelper.Floor(distanceResult.Position3.Z);

                        if (distanceEnabled)
                            value = distanceResult.Distance3;

                        return value + displacement * GetPosition(xci, yci, zci, 0);
                    }
                case VoronoiType.Difference21:
                    {
                        Calculate(x, y, z, out distanceResult);

                        var p = distanceResult.Position1 - distanceResult.Position0;
                        p *= 0.5f;

                        xci = NoiseHelper.Floor(p.X);
                        yci = NoiseHelper.Floor(p.Y);
                        zci = NoiseHelper.Floor(p.Z);

                        if (distanceEnabled)
                            value = distanceResult.Distance1 - distanceResult.Distance0;

                        return value + displacement * GetPosition(xci, yci, zci, 0);
                    }
                case VoronoiType.Difference32:
                    {
                        Calculate(x, y, z, out distanceResult);

                        var p = distanceResult.Position2 - distanceResult.Position1;
                        p *= 0.5f;

                        xci = NoiseHelper.Floor(p.X);
                        yci = NoiseHelper.Floor(p.Y);
                        zci = NoiseHelper.Floor(p.Z);

                        if (distanceEnabled)
                            value = distanceResult.Distance2 - distanceResult.Distance1;

                        return value + displacement * GetPosition(xci, yci, zci, 0);
                    }
                case VoronoiType.Crackle:
                    {
                        var d = 10 * Calculate(x, y, z, VoronoiType.Difference21);
                        return (1 < d) ? 1 : d;
                    }
            }

            throw new InvalidOperationException("An unknown VoronoiType is specified.");
        }