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  * amazing surf from Mandelbulber3D. Formula proposed by Kali, with features added by DarkBeam
10  *
11  * This formula has a c.x c.y SWAP
12  *
13  * @reference
14  * http://www.fractalforums.com/mandelbulb-3d/custom-formulas-and-transforms-release-t17106/
15  */
16 
17 #include "all_fractal_definitions.h"
18 
cFractalAmazingSurf()19 cFractalAmazingSurf::cFractalAmazingSurf() : cAbstractFractal()
20 {
21 	nameInComboBox = "Amazing Surf";
22 	internalName = "amazing_surf";
23 	internalID = fractal::amazingSurf;
24 	DEType = analyticDEType;
25 	DEFunctionType = linearDEFunction;
26 	cpixelAddition = cpixelEnabledByDefault;
27 	defaultBailout = 100.0;
28 	DEAnalyticFunction = analyticFunctionLinear;
29 	coloringFunction = coloringFunctionAmazingSurf;
30 }
31 
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)32 void cFractalAmazingSurf::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
33 {
34 	// update aux.actualScale
35 	aux.actualScale =
36 		fractal->mandelbox.scale + fractal->mandelboxVary4D.scaleVary * (fabs(aux.actualScale) - 1.0);
37 
38 	CVector4 c = aux.const_c;
39 	z.x = fabs(z.x + fractal->transformCommon.additionConstant111.x)
40 				- fabs(z.x - fractal->transformCommon.additionConstant111.x) - z.x;
41 	z.y = fabs(z.y + fractal->transformCommon.additionConstant111.y)
42 				- fabs(z.y - fractal->transformCommon.additionConstant111.y) - z.y;
43 	// no z fold
44 
45 	double rr = z.Dot(z);
46 	if (fractal->transformCommon.functionEnabledFalse) // force cylinder fold
47 		rr -= z.z * z.z;
48 
49 	double sqrtMinR = sqrt(fractal->transformCommon.minR05);
50 	double dividend = rr < sqrtMinR ? sqrtMinR : min(rr, 1.0);
51 
52 	/*if (rr < sqrtMinR)
53 	{
54 		aux.color += fractal->mandelbox.color.factorSp1;
55 	}
56 	else if (rr < 1.0)
57 	{
58 		aux.color += fractal->mandelbox.color.factorSp2;
59 	}*/
60 	// use aux.actualScale
61 	double m = aux.actualScale / dividend;
62 
63 	z *= (m - 1.0) * fractal->transformCommon.scale1 + 1.0;
64 	// z *= m * fractal->transformCommon.scale1 + 1.0 * (1.0 - fractal->transformCommon.scale1);
65 	aux.DE = aux.DE * fabs(m) + 1.0;
66 
67 	if (fractal->transformCommon.addCpixelEnabledFalse)
68 		z += CVector4(c.y, c.x, c.z, c.w) * fractal->transformCommon.constantMultiplier111;
69 
70 	z = fractal->transformCommon.rotationMatrix.RotateVector(z);
71 }
72