1 /**
2  * Mandelbulber v2, a 3D fractal generator       ,=#MKNmMMKmmßMNWy,
3  *                                             ,B" ]L,,p%%%,,,§;, "K
4  * Copyright (C) 2014-21 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  * RenderedImage class - extension for QWidget class. Widget prepared for displaying rendered image
33  * and 3D cursor
34  */
35 
36 #ifndef MANDELBULBER2_SRC_RENDERED_IMAGE_WIDGET_HPP_
37 #define MANDELBULBER2_SRC_RENDERED_IMAGE_WIDGET_HPP_
38 
39 #include <memory>
40 
41 #include <QWidget>
42 
43 #include "QVariant"
44 #include "algebra.hpp"
45 #include "animation_path_data.hpp"
46 #include "rendered_tile_data.hpp"
47 #include "stereo.h"
48 
49 // forward declarations
50 class cImage;
51 class cParameterContainer;
52 class cFractalContainer;
53 struct sAnimationPathData;
54 
55 class RenderedImage : public QWidget
56 {
57 	Q_OBJECT
58 
59 public:
60 	enum enumClickMode
61 	{
62 		clickDoNothing = 0,
63 		clickMoveCamera = 1,
64 		clickFogVisibility = 2,
65 		clickDOFFocus = 3,
66 		clickGetJuliaConstant = 4,
67 		clickPlaceLight = 5,
68 		clickPlacePrimitive = 6,
69 		clickFlightSpeedControl = 7,
70 		clickPlaceRandomLightCenter = 8,
71 		clickGetPoint = 9,
72 		clickWrapLimitsAroundObject = 10,
73 	};
74 
75 	enum enumGridType
76 	{
77 		gridTypeCrosshair = 0,
78 		gridTypeThirds = 1,
79 		gridTypeGolden = 2
80 	};
81 
82 	struct sFlightData
83 	{
84 		// numbers
85 		int frame;
86 		CVector3 camera;
87 		double speed;
88 		double distance;
89 		double speedSp;
90 
91 		// HUD
92 		CVector3 rotation;
93 		CVector3 speedVector;
94 		CVector3 forwardVector;
95 		CVector3 topVector;
96 	};
97 
98 	RenderedImage(QWidget *parent = nullptr);
AssignImage(std::shared_ptr<cImage> _image)99 	void AssignImage(std::shared_ptr<cImage> _image) { image = _image; }
AssignParameters(std::shared_ptr<cParameterContainer> _mainParams,std::shared_ptr<cFractalContainer> _fractals)100 	void AssignParameters(
101 		std::shared_ptr<cParameterContainer> _mainParams, std::shared_ptr<cFractalContainer> _fractals)
102 	{
103 		params = _mainParams;
104 		fractals = _fractals;
105 	}
setNewZ(double z)106 	void setNewZ(double z) { smoothLastZMouse = z; }
107 	void setClickMode(QList<QVariant> _clickMode);
SetEnableClickModes(bool enable)108 	void SetEnableClickModes(bool enable) { clickModesEnables = enable; }
GetEnableClickModes() const109 	bool GetEnableClickModes() const { return clickModesEnables; }
SetFrontDist(double dist)110 	void SetFrontDist(double dist) { frontDist = dist; }
SetCursorVisibility(bool enable)111 	void SetCursorVisibility(bool enable) { cursorVisible = enable; }
SetLightsVisibility(bool enable)112 	void SetLightsVisibility(bool enable) { lightsVisible = enable; }
113 	void SetGridType(enumGridType gridType);
SetFlightData(const sFlightData & fData)114 	void SetFlightData(const sFlightData &fData) { flightData = fData; }
SetPlaceBehindObjects(bool behind)115 	void SetPlaceBehindObjects(bool behind) { placeLightBehind = behind; }
SetCameraMovementMode(int index)116 	void SetCameraMovementMode(int index) { cameraMovementMode = index; }
117 	void SetAnimationPath(const sAnimationPathData &_animationPath);
SetCurrentLightIndex(int index)118 	void SetCurrentLightIndex(int index) { currentLightIndex = index; }
GetCurrentLightIndex()119 	int GetCurrentLightIndex() { return currentLightIndex; }
120 	// CVector2<double> GetLastMousePositionScaled();
121 
122 public slots:
123 	void slotSetMinimumSize(int width, int height);
124 	void showRenderedTilesList(QList<sRenderedTileData> listOfRenderedTiles);
125 
126 signals:
127 	void SpeedChanged(double amount);
128 	void SpeedSet(double amount);
129 	void StrafeChanged(CVector2<double> arrows);
130 	void YawAndPitchChanged(CVector2<double> yawAndPitch);
131 	void RotationChanged(double direction);
132 	void ShiftModeChanged(bool shiftPressed);
133 	void Pause();
134 
135 protected:
136 	void paintEvent(QPaintEvent *event) override;
137 	void mouseMoveEvent(QMouseEvent *event) override;
138 	void mousePressEvent(QMouseEvent *event) override;
139 	void mouseReleaseEvent(QMouseEvent *event) override;
140 	void keyPressEvent(QKeyEvent *event) override;
141 	void keyReleaseEvent(QKeyEvent *event) override;
142 	void enterEvent(QEvent *event) override;
143 	void leaveEvent(QEvent *event) override;
144 	void wheelEvent(QWheelEvent *event) override;
145 
146 private:
147 	void DisplayCoordinates();
148 	void Display3DCursor(CVector2<int> screenPoint, double z);
149 	void DisplayCrosshair() const;
150 	void Compass(CVector3 rotation, QPointF center, double size);
151 	void Draw3DBox(
152 		float scale, float fov, CVector2<float> point, float z, cStereo::enumEye eye) const;
153 	static QPointF CalcPointPersp(const CVector3 &point, const CRotationMatrix &rot, double persp);
154 	void DrawAnimationPath();
155 	void PaintLastRenderedTilesInfo();
156 	void DisplayAllLights();
157 	void line3D(const CVector3 &p1, const CVector3 &p2, const CVector3 camera,
158 		const CRotationMatrix &mRotInv, params::enumPerspectiveType perspectiveType, double fov,
159 		double imgWidth, double imgHeight, sRGB8 color, double thickness, sRGBFloat opacity,
160 		int numberOfSegments, int layer);
161 
162 	bool anaglyphMode;
163 	bool cursorVisible;
164 	bool lightsVisible;
165 	bool isFocus;
166 	bool isOnObject;
167 	bool placeLightBehind;
168 	bool redrawed;
169 	bool clickModesEnables;
170 	int draggingStarted;
171 	bool draggingInitStarted;
172 	std::shared_ptr<cFractalContainer> fractals;
173 	std::shared_ptr<cImage> image;
174 	std::shared_ptr<cParameterContainer> params;
175 	CVector2<double> keyArrows;
176 	CVector2<int> lastMousePosition;
177 	CVector2<int> dragStartPosition;
178 	int buttonsPressed;
179 	CVector3 lastCoordinates;
180 	Qt::MouseButtons dragButtons;
181 	double flightRotationDirection;
182 	double frontDist;
183 	double lastDepth;
184 	double smoothLastZMouse;
185 	enumClickMode clickMode;
186 	enumGridType gridType;
187 	int cameraMovementMode;
188 	QList<QVariant> clickModeData;
189 	QTimer *timerRefreshImage;
190 	sFlightData flightData;
191 	sAnimationPathData animationPathData;
192 	QList<sRenderedTileData> listOfRenderedTilesData;
193 	int currentLightIndex;
194 
195 signals:
196 	void mouseMoved(int x, int y);
197 	void singleClick(int x, int y, Qt::MouseButton button);
198 	void keyPress(QKeyEvent *event);
199 	void keyRelease(QKeyEvent *event);
200 	void mouseWheelRotatedWithKey(int x, int y, int delta, Qt::KeyboardModifiers keyModifiers);
201 	void mouseDragStart(int x, int y, Qt::MouseButtons button);
202 	void mouseDragFinish();
203 	void mouseDragDelta(int dx, int dy);
204 };
205 
206 #endif /* MANDELBULBER2_SRC_RENDERED_IMAGE_WIDGET_HPP_ */
207