1 /**
2  * Mandelbulber v2, a 3D fractal generator       ,=#MKNmMMKmmßMNWy,
3  *                                             ,B" ]L,,p%%%,,,§;, "K
4  * Copyright (C) 2014-20 Mandelbulber Team     §R-==%w["'~5]m%=L.=~5N
5  *                                        ,=mm=§M ]=4 yJKA"/-Nsaj  "Bw,==,,
6  * This file is part of Mandelbulber.    §R.r= jw",M  Km .mM  FW ",§=ß., ,TN
7  *                                     ,4R =%["w[N=7]J '"5=],""]]M,w,-; T=]M
8  * Mandelbulber is free software:     §R.ß~-Q/M=,=5"v"]=Qf,'§"M= =,M.§ Rz]M"Kw
9  * you can redistribute it and/or     §w "xDY.J ' -"m=====WeC=\ ""%""y=%"]"" §
10  * modify it under the terms of the    "§M=M =D=4"N #"%==A%p M§ M6  R' #"=~.4M
11  * GNU General Public License as        §W =, ][T"]C  §  § '§ e===~ U  !§[Z ]N
12  * published by the                    4M",,Jm=,"=e~  §  §  j]]""N  BmM"py=ßM
13  * Free Software Foundation,          ]§ T,M=& 'YmMMpM9MMM%=w=,,=MT]M m§;'§,
14  * either version 3 of the License,    TWw [.j"5=~N[=§%=%W,T ]R,"=="Y[LFT ]N
15  * or (at your option)                   TW=,-#"%=;[  =Q:["V""  ],,M.m == ]N
16  * any later version.                      J§"mr"] ,=,," =="""J]= M"M"]==ß"
17  *                                          §= "=C=4 §"eM "=B:m|4"]#F,§~
18  * Mandelbulber is distributed in            "9w=,,]w em%wJ '"~" ,=,,ß"
19  * the hope that it will be useful,                 . "K=  ,=RMMMßM"""
20  * but WITHOUT ANY WARRANTY;                            .'''
21  * without even the implied warranty
22  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23  *
24  * See the GNU General Public License for more details.
25  * You should have received a copy of the GNU General Public License
26  * along with Mandelbulber. If not, see <http://www.gnu.org/licenses/>.
27  *
28  * ###########################################################################
29  *
30  * Authors: Krzysztof Marczak (buddhi1980@gmail.com)
31  *
32  * definitions of primitive objects
33  */
34 
35 #ifndef MANDELBULBER2_SRC_PRIMITIVES_H_
36 #define MANDELBULBER2_SRC_PRIMITIVES_H_
37 
38 #include <memory>
39 #include <utility>
40 
41 #include "QtCore"
42 #include "algebra.hpp"
43 #include "color_structures.hpp"
44 #include "object_data.hpp"
45 #include "object_types.hpp"
46 
47 enum enumPrimitiveBooleanOperator
48 {
49 	primBooleanOperatorAND = 0,
50 	primBooleanOperatorOR = 1,
51 	primBooleanOperatorSUB = 2,
52 	primBooleanOperatorRevSUB = 3
53 };
54 
55 // forward declarations
56 class cParameterContainer;
57 struct sRenderData;
58 
59 struct sPrimitiveItem
60 {
sPrimitiveItemsPrimitiveItem61 	sPrimitiveItem(fractal::enumObjectType _type, int _id, QString _name)
62 			: type(_type), id(_id), name(std::move(_name))
63 	{
64 	}
65 
66 	fractal::enumObjectType type;
67 	int id;
68 	QString name;
69 };
70 
71 struct sPrimitiveBasic : cObjectData
72 {
73 	bool enable = false;
74 	int objectId = 0;
75 	enumPrimitiveBooleanOperator booleanOperator = primBooleanOperatorOR;
76 	virtual ~sPrimitiveBasic() = default;
77 	virtual double PrimitiveDistance(CVector3 _point) const = 0;
78 };
79 
80 struct sPrimitivePlane : sPrimitiveBasic
81 {
82 	bool empty;
83 	double PrimitiveDistance(CVector3 _point) const override;
84 };
85 
86 struct sPrimitiveBox : sPrimitiveBasic
87 {
88 	bool empty;
89 	double rounding;
90 	CVector3 repeat;
91 	double PrimitiveDistance(CVector3 _point) const override;
92 };
93 
94 struct sPrimitiveSphere : sPrimitiveBasic
95 {
96 	bool empty;
97 	double radius;
98 	CVector3 repeat;
99 	double PrimitiveDistance(CVector3 _point) const override;
100 };
101 
102 struct sPrimitiveWater : sPrimitiveBasic
103 {
104 	bool empty;
105 	bool waveFromObjectsEnable;
106 	double relativeAmplitude;
107 	double animSpeed;
108 	double animProgressionSpeed;
109 	double length;
110 	double waveFromObjectsRelativeAmplitude;
111 	int iterations;
112 	int animFrame;
113 	double PrimitiveDistance(CVector3 _point) const override;
114 	double PrimitiveDistanceWater(CVector3 _point, double distanceFromAnother) const;
115 };
116 
117 struct sPrimitiveCone : sPrimitiveBasic
118 {
119 	bool empty;
120 	bool caps;
121 	double radius;
122 	double height;
123 	CVector2<double> wallNormal;
124 	CVector3 repeat;
125 	double PrimitiveDistance(CVector3 _point) const override;
126 };
127 
128 struct sPrimitiveCylinder : sPrimitiveBasic
129 {
130 	bool empty;
131 	bool caps;
132 	double radius;
133 	double height;
134 	CVector3 repeat;
135 	double PrimitiveDistance(CVector3 _point) const override;
136 };
137 
138 struct sPrimitiveTorus : sPrimitiveBasic
139 {
140 	bool empty;
141 	double radius;
142 	double radiusLPow;
143 	double tubeRadius;
144 	double tubeRadiusLPow;
145 	CVector3 repeat;
146 	double PrimitiveDistance(CVector3 _point) const override;
147 };
148 
149 struct sPrimitiveCircle : sPrimitiveBasic
150 {
151 	double radius;
152 	double PrimitiveDistance(CVector3 _point) const override;
153 };
154 
155 struct sPrimitiveRectangle : sPrimitiveBasic
156 {
157 	double height;
158 	double width;
159 	double PrimitiveDistance(CVector3 _point) const override;
160 };
161 
162 QString PrimitiveNames(fractal::enumObjectType primitiveType);
163 
164 fractal::enumObjectType PrimitiveNameToEnum(const QString &primitiveType);
165 
166 class cPrimitives
167 {
168 	// some of functions for primitives were taken from
169 	// http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
170 
171 public:
172 	cPrimitives(
173 		const std::shared_ptr<cParameterContainer> par, QVector<cObjectData> *objectData = nullptr);
174 	~cPrimitives();
175 	double TotalDistance(CVector3 point, double fractalDistance, double detailSize,
176 		bool normalCalculationMode, int *closestObjectId, sRenderData *data) const;
GetListOfPrimitives()177 	const QList<sPrimitiveBasic *> *GetListOfPrimitives() const { return &allPrimitives; }
178 
179 	CVector3 allPrimitivesPosition;
180 	CVector3 allPrimitivesRotation;
181 	CRotationMatrix mRotAllPrimitivesRotation;
182 
183 private:
184 	QList<sPrimitiveBasic *> allPrimitives;
185 
Plane(CVector3 point,CVector3 position,CVector3 normal)186 	static double Plane(CVector3 point, CVector3 position, CVector3 normal)
187 	{
188 		return (normal.Dot(point - position));
189 	}
190 	bool isAnyPrimitive;
191 };
192 
193 #endif /* MANDELBULBER2_SRC_PRIMITIVES_H_ */
194