-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
150 lines (126 loc) · 4.01 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
// global shader declaration
#include "stairsPoint.hpp"
#define GLSL_VERSION 330
#include "api.hpp"
#include "image.hpp"
#include "io.hpp"
#include "lights.hpp"
#include "raylib.h"
#include "raylibwrapper.hpp"
#include "raymath.h"
#include "rlImGui.h"
#include "toolbar.hpp"
#include "vignette.hpp"
// constants
const float floor_height = 6.0f;
int width = 1920, height = 1080;
float sumX = 0, sumY = 0;
Vector2 center = Vector2{width / 2.0f, height / 2.0f};
// globals
std::vector<std::vector<std::vector<cv::Point2d>>> floors;
std::vector<std::vector<std::vector<cv::Point2d>>> floor_window;
std::vector<std::string> image_path = {};
void recalculate(RaylibWrapper &viewer) {
floors.clear();
floor_window.clear();
sumX = 0;
sumY = 0;
IOHelper *io = new IOHelper();
std::vector<std::vector<cv::Point>> contours, window_contours;
std::vector<std::vector<cv::Point2d>> contours2d, window_contours2d;
for (auto tmp : image_path) {
auto img = CustImage(imread(tmp));
// io->read_image(temp, contours, 0);
img.water_shed(contours);
io->read_image(tmp, window_contours, 1);
CustImage::normalize(contours, window_contours, contours2d,
window_contours2d);
floors.push_back(contours2d);
floor_window.push_back(window_contours2d);
// rendering
std::vector<cv::Point2d> input_2D;
for (const auto &points : floors[0]) {
for (const auto &point : points) {
input_2D.push_back(point);
}
std::vector<cv::Point2d> boundary_ip = viewer.get_bounding_box(input_2D);
for (const auto &point : boundary_ip) {
sumX += point.x;
sumY += point.y;
}
center = Vector2{sumX / 4.0f, sumY / 4.0f};
viewer.cameras.clear();
viewer.initialize_default_cam(center);
viewer.initialize_floor_cam(floor_height, floors.size());
}
viewer.heights.clear();
std::vector<std::vector<float>> heights(floors.size(),
std::vector<float>());
for (int i = 0; i < floors.size(); i++) {
for (int j = 0; j < floors[i].size(); j++) {
heights[i].push_back(floor_height);
}
}
viewer.heights = heights;
}
}
void enter() {
// flags
SetConfigFlags(FLAG_MSAA_4X_HINT);
RaylibWrapper viewer(width, height, "sugoi");
viewer.init();
viewer.initialize_default_cam(center);
viewer.initialize_floor_cam(floor_height, floors.size());
auto addImage = [&](std::vector<std::string> path) {
for (auto p : path) {
image_path.push_back(p);
cout << p << "\n";
}
recalculate(viewer);
};
Toolbar t;
t.init(&viewer, addImage);
Vignette vignette(width, height);
// lighting
LightLoader light = LightLoader(2, GLSL_VERSION);
light.ShaderInit();
light.InitializeLights(1, (Vector3){0, 0, 0}, Vector3Zero(), WHITE);
light.InitializeLights(1, (Vector3){-3, 3, 55}, Vector3Zero(), WHITE);
rlImGuiSetup(true);
BoundingBox object = {(Vector3){-1.0f, 0.0f, -1.0f},
(Vector3){1.0f, 2.0f, 1.0f}};
SphereSystem stairs(0.1f, &viewer);
while (!WindowShouldClose()) {
float cameraPos[3] = {viewer.get_camera().position.x,
viewer.get_camera().position.y,
viewer.get_camera().position.z};
RaylibWrapper::listen(viewer, floors.size());
BeginDrawing();
ClearBackground(BLACK);
viewer.update_camera();
light.UpdateLight(viewer.get_camera());
BeginMode3D(viewer.get_camera());
light.EnableShader();
stairs.Update();
RaylibWrapper::DrawFloor(viewer, floors);
RaylibWrapper::DrawFloor(viewer, floor_window, true);
stairs.Draw();
EndShaderMode();
RaylibWrapper::DrawCeil(viewer, floors, floor_height);
light.EnableDebug();
EndMode3D();
vignette.EnableShader();
vignette.Draw(!viewer.cameras[viewer.camera_index].is_toggle_sniper);
vignette.DisableShader();
rlImGuiBegin();
t.render();
rlImGuiEnd();
EndDrawing();
}
light.DisableShader();
rlImGuiShutdown();
}
int main() {
enter();
return 0;
}