-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
187 lines (156 loc) · 6.25 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* @brief - Reimplementation of a program that have seen a lot of trials along
* the years with the notable examples listed below:
*
* +-------------------------+---------------+
* | Name | Creation date |
* +-------------------------+---------------+
* | MANDELBULB | 11/07/2013 |
* +-------------------------+---------------+
* | MANDELBULB VIEWER | 02/08/2013 |
* +-------------------------+---------------+
* | MANDELBULB VIEWER REAL | 19/06/2014 |
* +-------------------------+---------------+
* | MANDELBULB RAYTRACING | ~15/04/2017 |
* +-------------------------+---------------+
*
* The goal of the tool is to provide a way to display the `Mandelbulb`
* which is analogous to the `Mandelbrot` set fractal in 2D.
* Several approaches have been tried out including the use of raytracing
* (even though it does not seem to have paid off). The approach followed
* here will be raytracing as well, with some sort of a deferred rendering
* on a GPU device.
* We have to acknowledge the value of the information found in the link
* below:
* http://celarek.at/wp/wp-content/uploads/2014/05/realTimeFractalsReport.pdf
* which proved very useful to implement the distance estimation techniques.
*
* Implemented from:
* - 17/01/2020 - 29/01/2020
*/
# include <core_utils/log/StdLogger.hh>
# include <core_utils/log/PrefixedLogger.hh>
# include <core_utils/log/Locator.hh>
# include <sdl_app_core/SdlApplication.hh>
# include <core_utils/CoreException.hh>
# include "MandelbulbRenderer.hh"
# include "InfoPanel.hh"
# include "LightSettings.hh"
# include "RenderMenu.hh"
# include "RenderSettings.hh"
# include "FractalSettings.hh"
namespace {
constexpr auto APP_NAME = "mandelbulb";
constexpr auto APP_TITLE = "I saw an interior designer running away in fear earlier";
constexpr auto APP_ICON_PATH = "data/img/brute.bmp";
}
int main(int /*argc*/, char** /*argv*/) {
// Create the logger.
utils::log::StdLogger raw;
raw.setLevel(utils::log::Severity::DEBUG);
utils::log::PrefixedLogger logger("mandelbulb", "main");
utils::log::Locator::provide(&raw);
const std::string service("mandelbulb");
const std::string module("main");
const float eventsFPS = 60.0f;
const float renderFPS = 50.0f;
sdl::app::SdlApplicationShPtr app = nullptr;
try {
app = std::make_shared<sdl::app::SdlApplication>(
APP_NAME,
APP_TITLE,
APP_ICON_PATH,
utils::Sizei(640, 480),
true,
utils::Sizef(0.7f, 0.5f),
renderFPS,
eventsFPS
);
// Create the layout of the window: the main tab is a scrollable widget
// allowing the display of the mandelbulb. The right dock widget allows
// to control the computation parameters of this object.
const float fov = 40.0f;
const float distance = 6.83f;
mandelbulb::CameraShPtr cam = std::make_shared<mandelbulb::Camera>(
utils::Sizei(512, 256),
fov,
distance,
utils::Vector2f()
);
mandelbulb::RenderProperties rProps{10u, 8.0f, 0.001f, 100u, 8.0f};
mandelbulb::ShadingProperties sProps{
sdl::core::engine::Color::NamedColor::Maroon,
0.7f,
sdl::core::engine::Color::NamedColor::Black,
1.0f,
0.1f
};
mandelbulb::FractalShPtr fractal = std::make_shared<mandelbulb::Fractal>(
cam,
rProps,
sProps,
mandelbulb::LightSettings::generateDefaultLights()
);
mandelbulb::RenderMenu* menu = new mandelbulb::RenderMenu();
app->setMenuBar(menu);
mandelbulb::MandelbulbRenderer* renderer = new mandelbulb::MandelbulbRenderer(fractal);
app->setCentralWidget(renderer);
mandelbulb::RenderSettings* render = new mandelbulb::RenderSettings();
app->addDockWidget(render, sdl::app::DockWidgetArea::RightArea, "Render");
mandelbulb::LightSettings* lights = new mandelbulb::LightSettings();
app->addDockWidget(lights, sdl::app::DockWidgetArea::RightArea, "Lights");
mandelbulb::FractalSettings* settings = new mandelbulb::FractalSettings();
app->addDockWidget(settings, sdl::app::DockWidgetArea::RightArea, "Fractal");
mandelbulb::InfoPanel* info = new mandelbulb::InfoPanel();
app->setStatusBar(info);
// Connect signals and slots of various components of the `UI`.
int slot1 = renderer->onCoordinatesChanged.connect_member<mandelbulb::InfoPanel>(
info,
&mandelbulb::InfoPanel::onCoordinatesChanged
);
int slot2 = renderer->onDepthChanged.connect_member<mandelbulb::InfoPanel>(
info,
&mandelbulb::InfoPanel::onDepthChanged
);
int slot3 = fractal->onRenderingCompletionAdvanced.connect_member<mandelbulb::RenderMenu>(
menu,
&mandelbulb::RenderMenu::onCompletionChanged
);
int slot4 = render->onRenderingSettingsChanged.connect_member<mandelbulb::Fractal>(
fractal.get(),
&mandelbulb::Fractal::onRenderingPropsChanged
);
int slot5 = lights->onLightsChanged.connect_member<mandelbulb::Fractal>(
fractal.get(),
&mandelbulb::Fractal::onLightsChanged
);
int slot6 = settings->onShadingPropertiesChanged.connect_member<mandelbulb::Fractal>(
fractal.get(),
&mandelbulb::Fractal::onShadingPropsChanged
);
// Run it.
app->run();
// Disconnect signals.
renderer->onCoordinatesChanged.disconnect(slot1);
renderer->onDepthChanged.disconnect(slot2);
fractal->onRenderingCompletionAdvanced.disconnect(slot3);
render->onRenderingSettingsChanged.disconnect(slot4);
lights->onLightsChanged.disconnect(slot5);
settings->onShadingPropertiesChanged.disconnect(slot6);
app.reset();
}
catch (const utils::CoreException& e) {
logger.error("Caught internal exception while setting up application", e.what());
return EXIT_FAILURE;
}
catch (const std::exception& e) {
logger.error("Caught internal exception while setting up application", e.what());
return EXIT_FAILURE;
}
catch (...) {
logger.error("Unexpected error while setting up application");
return EXIT_FAILURE;
}
// All is good.
return EXIT_SUCCESS;
}