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  * Blockify
10  * based on a block of Fragmentarium code, from Adam Nixon
11  * analytic aux.DE
12  */
13 
14 #include "all_fractal_definitions.h"
15 
cFractalTransfBlockifyV2()16 cFractalTransfBlockifyV2::cFractalTransfBlockifyV2() : cAbstractFractal()
17 {
18 	nameInComboBox = "T>Blockify V2";
19 	internalName = "transf_blockify_v2";
20 	internalID = fractal::transfBlockifyV2;
21 	DEType = analyticDEType;
22 	DEFunctionType = withoutDEFunction;
23 	cpixelAddition = cpixelDisabledByDefault;
24 	defaultBailout = 100.0;
25 	DEAnalyticFunction = analyticFunctionNone;
26 	coloringFunction = coloringFunctionDefault;
27 }
28 
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)29 void cFractalTransfBlockifyV2::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
30 {
31 	double master = fractal->transformCommon.scale / 100.0;
32 	CVector4 bSize = fractal->transformCommon.constantMultiplier111 * master;
33 	if (!fractal->transformCommon.functionEnabledFalse)
34 	{
35 		if (!fractal->transformCommon.functionEnabledDFalse)
36 		{
37 			if (fractal->transformCommon.functionEnabledCx)
38 			{
39 				if (!fractal->transformCommon.functionEnabledAxFalse)
40 					z.x = (floor(z.x / bSize.x) + 0.5) * bSize.x;
41 				else z.x = floor(z.x / bSize.x + 0.5) * bSize.x;
42 			}
43 			if (fractal->transformCommon.functionEnabledCy)
44 			{
45 				if (!fractal->transformCommon.functionEnabledAyFalse)
46 					z.y = (floor(z.y / bSize.y) + 0.5) * bSize.y;
47 				else z.y = floor(z.y / bSize.y + 0.5) * bSize.y;
48 			}
49 			if (fractal->transformCommon.functionEnabledCz)
50 			{
51 				if (!fractal->transformCommon.functionEnabledAzFalse)
52 					 z.z = (floor(z.z / bSize.z) + 0.5) * bSize.z;
53 				else z.z = floor(z.z / bSize.z + 0.5) * bSize.z;
54 			}
55 		}
56 		else // normalize
57 		{
58 			double rNorm = z.Length();
59 			z /= rNorm;
60 			if (fractal->transformCommon.functionEnabledCx)
61 			{
62 				if (!fractal->transformCommon.functionEnabledAxFalse)
63 					z.x = (floor(z.x / bSize.x) + 0.5) * bSize.x;
64 				else z.x = floor(z.x / bSize.x + 0.5) * bSize.x;
65 			}
66 			if (fractal->transformCommon.functionEnabledCy)
67 			{
68 				if (!fractal->transformCommon.functionEnabledAyFalse)
69 					z.y = (floor(z.y / bSize.y) + 0.5) * bSize.y;
70 				else z.y = floor(z.y / bSize.y + 0.5) * bSize.y;
71 			}
72 			if (fractal->transformCommon.functionEnabledCz)
73 			{
74 				if (!fractal->transformCommon.functionEnabledAzFalse)
75 					 z.z = (floor(z.z / bSize.z) + 0.5) * bSize.z;
76 				else z.z = floor(z.z / bSize.z + 0.5) * bSize.z;
77 			}
78 			z *= rNorm;
79 		}
80 	}
81 	else // radial
82 	{
83 		CVector4 zz = z * z;
84 		double rr = zz.x + zz.y + zz.z;
85 		if (fractal->transformCommon.functionEnabledRFalse) rr = sqrt(rr);
86 		if (fractal->transformCommon.functionEnabledBxFalse) rr = zz.x + zz.y;
87 		if (fractal->transformCommon.functionEnabledByFalse) rr = zz.y + zz.z;
88 		if (fractal->transformCommon.functionEnabledBzFalse) rr = zz.z + zz.x;
89 		if (!fractal->transformCommon.functionEnabledEFalse)
90 		{
91 			z /= rr;
92 			rr = floor(rr / master) * master;
93 			z *= rr;
94 		}
95 		else
96 		{
97 			z *= rr;
98 			rr = floor(rr / master) * master;
99 			z /= rr;
100 		}
101 	}
102 
103 	// post scale
104 	z *= fractal->transformCommon.scale1;
105 	aux.DE = aux.DE * fractal->transformCommon.scale1 * fractal->analyticDE.scale1
106 							 + fractal->analyticDE.offset0;
107 	//aux.DE = aux.DE - 0.001;
108 	//aux.DE *= z.Length() / oldZ.Length();
109 }
110