1 /**
2 * Mandelbulber v2, a 3D fractal generator _%}}i*<. ______
3 * Copyright (C) 2020 Mandelbulber Team _>]|=||i=i<, / ____/ __ __
4 * \><||i|=>>%) / / __/ /___/ /_
5 * This file is part of Mandelbulber. )<=i=]=|=i<> / /__ /_ __/_ __/
6 * The project is licensed under GPLv3, -<>>=|><|||` \____/ /_/ /_/
7 * see also COPYING file in this folder. ~+{i%+++
8 *
9 * Menger4D MOD1 from Syntopia & DarkBeam's Menger4 code from M3D
10 * @reference
11 * http://www.fractalforums.com/mandelbulb-3d/custom-formulas-and-transforms-release-t17106/
12 */
13
14 #include "all_fractal_definitions.h"
15
cFractalMenger4dMod1()16 cFractalMenger4dMod1::cFractalMenger4dMod1() : cAbstractFractal()
17 {
18 nameInComboBox = "Menger 4D Mod1";
19 internalName = "menger4d_mod1";
20 internalID = fractal::menger4dMod1;
21 DEType = analyticDEType;
22 DEFunctionType = linearDEFunction;
23 cpixelAddition = cpixelDisabledByDefault;
24 defaultBailout = 10.0;
25 DEAnalyticFunction = analyticFunctionIFS;
26 coloringFunction = coloringFunctionDefault;
27 }
28
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)29 void cFractalMenger4dMod1::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
30 {
31 double paraAddP0 = 0.0;
32 if (fractal->Cpara.enabledParabFalse)
33 { // parabolic = paraOffset + iter *slope + (iter *iter *scale)
34 paraAddP0 = fractal->Cpara.parabOffset0 + (aux.i * fractal->Cpara.parabSlope)
35 + (aux.i * aux.i * 0.001 * fractal->Cpara.parabScale);
36 z.w += paraAddP0;
37 }
38
39 if (aux.i >= fractal->transformCommon.startIterationsC
40 && aux.i < fractal->transformCommon.stopIterationsC)
41 {
42 z += fractal->transformCommon.additionConstant0000; // offset
43 }
44
45 z = fabs(z);
46 if (z.x - z.y < 0.0) swap(z.y, z.x);
47 if (z.x - z.z < 0.0) swap(z.z, z.x);
48 if (z.y - z.z < 0.0) swap(z.z, z.y);
49 if (z.x - z.w < 0.0) swap(z.w, z.x);
50 if (z.y - z.w < 0.0) swap(z.w, z.y);
51 if (z.z - z.w < 0.0) swap(z.w, z.z);
52
53 // 6 plane rotation
54 if (fractal->transformCommon.functionEnabledRFalse
55 && aux.i >= fractal->transformCommon.startIterationsR
56 && aux.i < fractal->transformCommon.stopIterationsR)
57 {
58 CVector4 tp;
59 if (fractal->transformCommon.rotation44a.x != 0)
60 {
61 tp = z;
62 double alpha = fractal->transformCommon.rotation44a.x * M_PI_180;
63 z.x = tp.x * cos(alpha) + tp.y * sin(alpha);
64 z.y = tp.x * -sin(alpha) + tp.y * cos(alpha);
65 }
66 if (fractal->transformCommon.rotation44a.y != 0)
67 {
68 tp = z;
69 double beta = fractal->transformCommon.rotation44a.y * M_PI_180;
70 z.y = tp.y * cos(beta) + tp.z * sin(beta);
71 z.z = tp.y * -sin(beta) + tp.z * cos(beta);
72 }
73 if (fractal->transformCommon.rotation44a.z != 0)
74 {
75 tp = z;
76 double gamma = fractal->transformCommon.rotation44a.z * M_PI_180;
77 z.x = tp.x * cos(gamma) + tp.z * sin(gamma);
78 z.z = tp.x * -sin(gamma) + tp.z * cos(gamma);
79 }
80 if (fractal->transformCommon.rotation44b.x != 0)
81 {
82 tp = z;
83 double delta = fractal->transformCommon.rotation44b.x * M_PI_180;
84 z.x = tp.x * cos(delta) + tp.w * sin(delta);
85 z.w = tp.x * -sin(delta) + tp.w * cos(delta);
86 }
87 if (fractal->transformCommon.rotation44b.y != 0)
88 {
89 tp = z;
90 double epsilon = fractal->transformCommon.rotation44b.y * M_PI_180;
91 z.y = tp.y * cos(epsilon) + tp.w * sin(epsilon);
92 z.w = tp.y * -sin(epsilon) + tp.w * cos(epsilon);
93 }
94 if (fractal->transformCommon.rotation44b.z != 0)
95 {
96 tp = z;
97 double zeta = fractal->transformCommon.rotation44b.z * M_PI_180;
98 z.z = tp.z * cos(zeta) + tp.w * sin(zeta);
99 z.w = tp.z * -sin(zeta) + tp.w * cos(zeta);
100 }
101 }
102 double scaleM = fractal->transformCommon.scale3;
103 CVector4 offsetM = fractal->transformCommon.additionConstant111d5;
104 z.x = scaleM * z.x - offsetM.x;
105 z.y = scaleM * z.y - offsetM.y;
106 z.w = scaleM * z.w - offsetM.w;
107 if (fractal->transformCommon.functionEnabledz
108 && aux.i >= fractal->transformCommon.startIterationsM
109 && aux.i < fractal->transformCommon.stopIterationsM)
110 {
111 z.z -= 0.5 * offsetM.z / scaleM;
112 z.z = -fabs(z.z);
113 z.z += 0.5 * offsetM.z / scaleM;
114 }
115 else
116 {
117 z.w = scaleM * z.w - offsetM.w;
118 }
119 z.z *= scaleM;
120 aux.DE *= scaleM;
121
122 if (fractal->transformCommon.functionEnabledSFalse
123 && aux.i >= fractal->transformCommon.startIterationsS
124 && aux.i < fractal->transformCommon.stopIterationsS)
125 {
126 double rr = 0.;
127 if (fractal->transformCommon.functionEnabledBxFalse)
128 {
129 rr = z.x * z.x + z.y * z.y;
130 }
131 if (fractal->transformCommon.functionEnabledByFalse)
132 {
133 rr = z.x * z.x + z.y * z.y + z.z * z.z;
134 }
135 if (fractal->transformCommon.functionEnabledBz)
136 //{ r2 = z.Dot(z) ;}
137 {
138 rr = z.x * z.x + z.y * z.y + z.z * z.z + z.w * z.w;
139 }
140 // if (r2 < 1e-21 && r2 > -1e-21) r2 = (r2 > 0) ? 1e-21 : -1e-21;
141
142 if (rr < fractal->transformCommon.minR2p25)
143 {
144 z *= fractal->transformCommon.maxMinR2factor;
145 aux.DE *= fractal->transformCommon.maxMinR2factor;
146 aux.color += fractal->mandelbox.color.factorSp1;
147 }
148 else if (rr < fractal->transformCommon.maxR2d1)
149 {
150 double tglad_factor2 = fractal->transformCommon.maxR2d1 / rr;
151 z *= tglad_factor2;
152 aux.DE *= tglad_factor2;
153 aux.color += fractal->mandelbox.color.factorSp2;
154 }
155 }
156
157 if (fractal->transformCommon.functionEnabledFalse)
158 {
159 CVector4 zA4 = (aux.i == fractal->transformCommon.intA) ? z : CVector4();
160 CVector4 zB4 = (aux.i == fractal->transformCommon.intB) ? z : CVector4();
161
162 z = (z * fractal->transformCommon.scale) + (zA4 * fractal->transformCommon.offset)
163 + (zB4 * fractal->transformCommon.offset0);
164 aux.DE *= fractal->transformCommon.scale1;
165 }
166
167 aux.DE *= fractal->analyticDE.scale1;
168 }
169