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  * Menger Smooth
10  * http://www.fractalforums.com/fragmentarium/help-t22583/
11  */
12 
13 #include "all_fractal_definitions.h"
14 
cFractalMengerSmooth()15 cFractalMengerSmooth::cFractalMengerSmooth() : cAbstractFractal()
16 {
17 	nameInComboBox = "Menger - Smooth";
18 	internalName = "menger_smooth";
19 	internalID = fractal::mengerSmooth;
20 	DEType = analyticDEType;
21 	DEFunctionType = linearDEFunction;
22 	cpixelAddition = cpixelDisabledByDefault;
23 	defaultBailout = 10.0;
24 	DEAnalyticFunction = analyticFunctionIFS;
25 	coloringFunction = coloringFunctionDefault;
26 }
27 
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)28 void cFractalMengerSmooth::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
29 {
30 	double sc1 = fractal->transformCommon.scale3 - 1.0; // 3 - 1 = 2, 2/3 = 0.6667;
31 	double sc2 = sc1 / fractal->transformCommon.scale3; //  8 - 1 = 7, 7/8 = 0.89ish;
32 	double OffsetS = fractal->transformCommon.offset0005;
33 
34 	// the closer to origin the greater the effect of OffsetSQ
35 	z =
36 		CVector4(sqrt(z.x * z.x + OffsetS), sqrt(z.y * z.y + OffsetS), sqrt(z.z * z.z + OffsetS), z.w);
37 
38 	double t;
39 	CVector4 OffsetC = fractal->transformCommon.offset1105;
40 
41 	t = z.x - z.y;
42 	t = 0.5 * (t - sqrt(t * t + OffsetS));
43 	z.x = z.x - t;
44 	z.y = z.y + t;
45 
46 	t = z.x - z.z;
47 	t = 0.5 * (t - sqrt(t * t + OffsetS));
48 	z.x = z.x - t;
49 	z.z = z.z + t;
50 
51 	t = z.y - z.z;
52 	t = 0.5 * (t - sqrt(t * t + OffsetS));
53 	z.y = z.y - t;
54 	z.z = z.z + t;
55 
56 	z.z = z.z - OffsetC.z * sc2; // sc2 reduces C.z
57 	z.z = -sqrt(z.z * z.z + OffsetS);
58 	z.z = z.z + OffsetC.z * sc2;
59 
60 	z.x = fractal->transformCommon.scale3 * z.x - OffsetC.x * sc1; // sc1 scales up C.x
61 	z.y = fractal->transformCommon.scale3 * z.y - OffsetC.y * sc1;
62 	z.z = fractal->transformCommon.scale3 * z.z;
63 
64 	aux.DE *= fractal->transformCommon.scale3;
65 
66 	if (fractal->transformCommon.rotationEnabled && aux.i >= fractal->transformCommon.startIterationsR
67 			&& aux.i < fractal->transformCommon.stopIterationsR)
68 	{
69 		z = fractal->transformCommon.rotationMatrix.RotateVector(z);
70 	}
71 
72 	if (fractal->transformCommon.functionEnabledzFalse)
73 	{
74 		CVector4 zA = (aux.i == fractal->transformCommon.intA) ? z : CVector4();
75 		CVector4 zB = (aux.i == fractal->transformCommon.intB) ? z : CVector4();
76 		z = (z * fractal->transformCommon.scale1) + (zA * fractal->transformCommon.offsetA0)
77 				+ (zB * fractal->transformCommon.offsetB0);
78 		aux.DE *= fractal->transformCommon.scale1;
79 	}
80 }
81