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  * transfDIFSHextgrid2Iteration  fragmentarium code, mdifs by knighty (jan 2012)
10  * and  darkbeams optimized verion @reference
11  * http://www.fractalforums.com/mandelbulb-3d/custom-formulas-and-transforms-release-t17106/
12  * "Beautiful iso-surface made of a hexagonal grid of tubes.
13  * Taken from K3DSurf forum, posted by user abdelhamid belaid."
14  */
15 
16 #include "all_fractal_definitions.h"
17 
cFractalTransfDIFSHextgrid2()18 cFractalTransfDIFSHextgrid2::cFractalTransfDIFSHextgrid2() : cAbstractFractal()
19 {
20 	nameInComboBox = "T>DIFS Hextgrid2";
21 	internalName = "transf_difs_hextgrid2";
22 	internalID = fractal::transfDIFSHextgrid2;
23 	DEType = analyticDEType;
24 	DEFunctionType = customDEFunction;
25 	cpixelAddition = cpixelDisabledByDefault;
26 	defaultBailout = 100.0;
27 	DEAnalyticFunction = analyticFunctionCustomDE;
28 	coloringFunction = coloringFunctionDefault;
29 }
30 
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)31 void cFractalTransfDIFSHextgrid2::FormulaCode(
32 	CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
33 {
34 	CVector4 zc = z;
35 
36 	double size = fractal->transformCommon.scale1;
37 	double hexD = 0.0;
38 
39 	if (fractal->transformCommon.rotationEnabled)
40 	{
41 		zc = fractal->transformCommon.rotationMatrix.RotateVector(zc);
42 	}
43 
44 	zc.z /= fractal->transformCommon.scaleF1;
45 
46 	double cosPi6 = cos(M_PI / 6.0);
47 	double yFloor = fabs(zc.y - size * floor(zc.y / size + 0.5));
48 	double xFloor = fabs(zc.x - size * 1.5 / cosPi6 * floor(zc.x / size / 1.5 * cosPi6 + 0.5));
49 	double gridMax = max(yFloor, xFloor * cosPi6 + yFloor * sin(M_PI / 6.0));
50 	double gridMin = min(gridMax - size * 0.5, yFloor);
51 	if (!fractal->transformCommon.functionEnabledJFalse)
52 		hexD = sqrt(gridMin * gridMin + zc.z * zc.z);
53 	else
54 		hexD = max(fabs(gridMin), fabs(zc.z));
55 
56 	aux.dist = min(aux.dist, (hexD - fractal->transformCommon.offset0005) / (aux.DE + 1.0));
57 }
58