Mgfractal: Create a choice of 4 mandelbrot formulas
authorparamat <mat.gregory@virginmedia.com>
Wed, 11 Nov 2015 05:05:20 +0000 (05:05 +0000)
committerparamat <mat.gregory@virginmedia.com>
Sat, 14 Nov 2015 04:25:47 +0000 (04:25 +0000)
builtin/settingtypes.txt
minetest.conf.example
src/mapgen_fractal.cpp
src/mapgen_fractal.h

index 25849e0c73f24ed61b2a99e74e83a53c5d6999e2..e5fe5cb95a517c51f4a64769e8ab359a4eed6f98 100644 (file)
@@ -970,11 +970,16 @@ mgflat_np_cave2 (Mapgen flat cave2 noise parameters) noise_params 0, 12, (128, 1
 [***Mapgen fractal]
 
 #    Map generation attributes specific to Mapgen fractal.
-#    'julia' selects a julia set to be generated instead of a mandelbrot set.
+#    The 'julia' flag results in the corresponding julia set being generated.
 #    Flags that are not specified in the flag string are not modified from the default.
 #    Flags starting with "no" are used to explicitly disable them.
 mgfractal_spflags (Mapgen fractal flags) flags nojulia julia,nojulia
 
+#    Choice of 4 mandelbrot set variations.
+#    1 = 4D "Roundy" mandelbrot set, 2 = 4D "Squarry" mandelbrot set,
+#    3 = 4D "Mandy Cousin" mandelbrot set, 4 = 4D mandelbrot set variation.
+mgfractal_formula (Mapgen fractal formula) int 1 1 4
+
 #    Mandelbrot set: Iterations of the recursive function.
 #    Controls scale of finest detail.
 mgfractal_m_iterations (Mapgen fractal mandelbrot iterations) int 9
index e5adc0e1d8299e54858e59c7658bf85d9fa07289..74f7006f416477899d39544a5fdd18b18461fc55 100644 (file)
 #### Mapgen fractal
 
 #    Map generation attributes specific to Mapgen fractal.
-#    'julia' selects a julia set to be generated instead of a mandelbrot set.
+#    The 'julia' flag results in the corresponding julia set being generated.
 #    Flags that are not specified in the flag string are not modified from the default.
 #    Flags starting with "no" are used to explicitly disable them.
 #    type: flags possible values: julia, nojulia
 # mgfractal_spflags = nojulia
 
+#    Choice of 4 mandelbrot set variations.
+#    1 = 4D "Roundy" mandelbrot set, 2 = 4D "Squarry" mandelbrot set,
+#    3 = 4D "Mandy Cousin" mandelbrot set, 4 = 4D mandelbrot set variation.
+#    type: int
+# mgfractal_formula = 1
+
 #    Mandelbrot set: Iterations of the recursive function.
 #    Controls scale of finest detail.
 #    type: int
index 5eebc17b3d37c00beafa0be26a08032e0ff9660e..37ed0d86ae2e1846cbdcda07feff7ddae978b482 100644 (file)
@@ -67,6 +67,8 @@ MapgenFractal::MapgenFractal(int mapgenid, MapgenParams *params, EmergeManager *
        MapgenFractalParams *sp = (MapgenFractalParams *)params->sparams;
        this->spflags = sp->spflags;
 
+       this->formula = sp->formula;
+
        this->m_iterations = sp->m_iterations;
        this->m_scale = sp->m_scale;
        this->m_offset = sp->m_offset;
@@ -145,6 +147,8 @@ MapgenFractalParams::MapgenFractalParams()
 {
        spflags = 0;
 
+       formula = 1;
+
        m_iterations = 9;  // Mandelbrot set only
        m_scale = v3f(1024.0, 256.0, 1024.0);
        m_offset = v3f(1.75, 0.0, 0.0);
@@ -170,6 +174,8 @@ void MapgenFractalParams::readParams(const Settings *settings)
 {
        settings->getFlagStrNoEx("mgfractal_spflags", spflags, flagdesc_mapgen_fractal);
 
+       settings->getU16NoEx("mgfractal_formula", formula);
+
        settings->getU16NoEx("mgfractal_m_iterations", m_iterations);
        settings->getV3FNoEx("mgfractal_m_scale", m_scale);
        settings->getV3FNoEx("mgfractal_m_offset", m_offset);
@@ -195,6 +201,8 @@ void MapgenFractalParams::writeParams(Settings *settings) const
 {
        settings->setFlagStr("mgfractal_spflags", spflags, flagdesc_mapgen_fractal, U32_MAX);
 
+       settings->setU16("mgfractal_formula", formula);
+
        settings->setU16("mgfractal_m_iterations", m_iterations);
        settings->setV3F("mgfractal_m_scale", m_scale);
        settings->setV3F("mgfractal_m_offset", m_offset);
@@ -403,11 +411,32 @@ bool MapgenFractal::getFractalAtPoint(s16 x, s16 y, s16 z)
        u16 iterations = spflags & MGFRACTAL_JULIA ? j_iterations : m_iterations;
 
        for (u16 iter = 0; iter < iterations; iter++) {
-               // 4D "Roundy" Mandelbrot set
-               float nx = ox * ox - oy * oy - oz * oz - ow * ow + cx;
-               float ny = 2.0f * (ox * oy + oz * ow) + cy;
-               float nz = 2.0f * (ox * oz + oy * ow) + cz;
-               float nw = 2.0f * (ox * ow + oy * oz) + cw;
+               float nx = 0.0f;
+               float ny = 0.0f;
+               float nz = 0.0f;
+               float nw = 0.0f;
+
+               if (formula == 1) {  // 4D "Roundy" Mandelbrot Set
+                       nx = ox * ox - oy * oy - oz * oz - ow * ow + cx;
+                       ny = 2.0f * (ox * oy + oz * ow) + cy;
+                       nz = 2.0f * (ox * oz + oy * ow) + cz;
+                       nw = 2.0f * (ox * ow + oy * oz) + cw;
+               } else if (formula == 2) {  // 4D "Squarry" Mandelbrot Set
+                       nx = ox * ox - oy * oy - oz * oz - ow * ow + cx;
+                       ny = 2.0f * (ox * oy + oz * ow) + cy;
+                       nz = 2.0f * (ox * oz + oy * ow) + cz;
+                       nw = 2.0f * (ox * ow - oy * oz) + cw;
+               } else if (formula == 3) {  // 4D "Mandy Cousin" Mandelbrot Set
+                       nx = ox * ox - oy * oy - oz * oz + ow * ow + cx;
+                       ny = 2.0f * (ox * oy + oz * ow) + cy;
+                       nz = 2.0f * (ox * oz + oy * ow) + cz;
+                       nw = 2.0f * (ox * ow + oy * oz) + cw;
+               } else if (formula == 4) {  // 4D Mandelbrot Set Variation
+                       nx = ox * ox - oy * oy - oz * oz - ow * ow + cx;
+                       ny = 2.0f * (ox * oy + oz * ow) + cy;
+                       nz = 2.0f * (ox * oz - oy * ow) + cz;
+                       nw = 2.0f * (ox * ow + oy * oz) + cw;
+               }
 
                if (nx * nx + ny * ny + nz * nz + nw * nw > 4.0f)
                        return false;
index f3c0230813d1d0a1c8ff18cd4430cc4fc0d3bb64..1b6683f1f218c2684c6fad9f81985433fdc195f6 100644 (file)
@@ -36,6 +36,8 @@ extern FlagDesc flagdesc_mapgen_fractal[];
 struct MapgenFractalParams : public MapgenSpecificParams {
        u32 spflags;
 
+       u16 formula;
+
        u16 m_iterations;
        v3f m_scale;
        v3f m_offset;
@@ -76,6 +78,8 @@ public:
        v3s16 full_node_min;
        v3s16 full_node_max;
 
+       u16 formula;
+
        u16 m_iterations;
        v3f m_scale;
        v3f m_offset;