|
@@ -28,6 +28,7 @@
|
28
|
28
|
RenderMode Render::mode = RenderMode::LoadScreen;
|
29
|
29
|
std::vector<Room*> Render::roomList;
|
30
|
30
|
bool Render::displayViewFrustum = false;
|
|
31
|
+bool Render::displayVisibilityCheck = false;
|
31
|
32
|
|
32
|
33
|
void Render::display() {
|
33
|
34
|
gl::glClear(gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT);
|
|
@@ -56,7 +57,7 @@ void Render::display() {
|
56
|
57
|
glm::mat4 view = Camera::getViewMatrix();
|
57
|
58
|
glm::mat4 VP = projection * view;
|
58
|
59
|
|
59
|
|
- //if (updated) {
|
|
60
|
+ if (updated || displayVisibilityCheck) {
|
60
|
61
|
int r = Camera::getRoom();
|
61
|
62
|
clearRoomList();
|
62
|
63
|
if (r < 0) {
|
|
@@ -64,7 +65,7 @@ void Render::display() {
|
64
|
65
|
} else {
|
65
|
66
|
buildRoomList(VP, r);
|
66
|
67
|
}
|
67
|
|
- //}
|
|
68
|
+ }
|
68
|
69
|
|
69
|
70
|
for (int r = roomList.size() - 1; r >= 0; r--) {
|
70
|
71
|
roomList.at(r)->display(VP);
|
|
@@ -103,70 +104,80 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
|
103
|
104
|
}
|
104
|
105
|
}
|
105
|
106
|
} else {
|
106
|
|
- // Check if this room is visible
|
107
|
|
- if (Camera::boxInFrustum(World::getRoom(room).getBoundingBox())) {
|
108
|
|
- roomList.push_back(&World::getRoom(room));
|
|
107
|
+ roomList.push_back(&World::getRoom(room));
|
109
|
108
|
|
|
109
|
+ if (displayVisibilityCheck) {
|
110
|
110
|
// Display the visibility test for the portal to this room
|
111
|
111
|
BoundingBox debugBox(glm::vec3(min, 0.0f), glm::vec3(max, 0.0f));
|
112
|
112
|
debugBox.display(glm::mat4(1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
113
|
113
|
|
114
|
114
|
ImGui::Text(" Min: %.3f %.3f", min.x, min.y);
|
115
|
115
|
ImGui::Text(" Max: %.3f %.3f", max.x, max.y);
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ // Check all portals leading from this room to somewhere else
|
|
119
|
+ for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
|
|
120
|
+ auto& portal = World::getRoom(room).getPortal(i);
|
|
121
|
+
|
|
122
|
+ // Calculate the 2D window of this portal
|
|
123
|
+ glm::vec3 newMin, newMax;
|
|
124
|
+ for (int c = 0; c < 4; c++) {
|
|
125
|
+ glm::vec3 vert = portal.getVertex(c);
|
|
126
|
+ glm::vec4 result = VP * glm::vec4(vert, 1.0f);
|
|
127
|
+ vert = glm::vec3(result) / result.w;
|
116
|
128
|
|
117
|
|
- // Check all portals leading from this room to somewhere else
|
118
|
|
- for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
|
119
|
|
- auto& portal = World::getRoom(room).getPortal(i);
|
120
|
|
-
|
121
|
|
- // Calculate the 2D window of this portal
|
122
|
|
- glm::vec2 newMin, newMax;
|
123
|
|
- bool inited = false;
|
124
|
|
- for (int c = 0; c < 4; c++) {
|
125
|
|
- glm::vec3 vert = portal.getVertex(c);
|
126
|
|
- glm::vec4 result = VP * glm::vec4(vert, 1.0f);
|
127
|
|
- vert = glm::vec3(result) / result.w;
|
128
|
|
-
|
129
|
|
- ImGui::Text("Test %d: %.3f %.3f", c, vert.x, vert.y);
|
130
|
|
-
|
131
|
|
- if (!inited) {
|
132
|
|
- newMin = glm::vec2(vert);
|
133
|
|
- newMax = glm::vec2(vert);
|
134
|
|
- inited = true;
|
135
|
|
- } else {
|
136
|
|
- if (vert.x < newMin.x)
|
137
|
|
- newMin.x = vert.x;
|
138
|
|
- if (vert.y < newMin.y)
|
139
|
|
- newMin.y = vert.y;
|
140
|
|
- if (vert.x > newMax.x)
|
141
|
|
- newMax.x = vert.x;
|
142
|
|
- if (vert.y > newMax.y)
|
143
|
|
- newMax.y = vert.y;
|
144
|
|
- }
|
|
129
|
+ if (displayVisibilityCheck) {
|
|
130
|
+ ImGui::Text("Test %d: %.3f %.3f %.3f", c, vert.x, vert.y, vert.z);
|
145
|
131
|
}
|
146
|
132
|
|
147
|
|
- // Check if the portal intersects the portal leading into this room
|
148
|
|
- if (!((min.x < newMax.x) && (max.x > newMin.x)
|
149
|
|
- && (min.y < newMax.y) && (max.y > newMin.y))) {
|
150
|
|
- ImGui::Text("Invisible!");
|
151
|
|
- continue;
|
|
133
|
+ if (c == 0) {
|
|
134
|
+ newMin = vert;
|
|
135
|
+ newMax = vert;
|
152
|
136
|
} else {
|
153
|
|
- ImGui::Text("Visible!");
|
|
137
|
+ if (vert.x < newMin.x)
|
|
138
|
+ newMin.x = vert.x;
|
|
139
|
+ if (vert.y < newMin.y)
|
|
140
|
+ newMin.y = vert.y;
|
|
141
|
+ if (vert.z < newMin.z)
|
|
142
|
+ newMin.z = vert.z;
|
|
143
|
+ if (vert.x > newMax.x)
|
|
144
|
+ newMax.x = vert.x;
|
|
145
|
+ if (vert.y > newMax.y)
|
|
146
|
+ newMax.y = vert.y;
|
|
147
|
+ if (vert.z > newMax.z)
|
|
148
|
+ newMax.z = vert.z;
|
154
|
149
|
}
|
|
150
|
+ }
|
155
|
151
|
|
156
|
|
- // Check if this room is already in the list...
|
157
|
|
- bool found = false;
|
158
|
|
- for (int n = 0; n < roomList.size(); n++) {
|
159
|
|
- if (roomList.at(n) == &World::getRoom(portal.getAdjoiningRoom())) {
|
160
|
|
- found = true;
|
161
|
|
- break;
|
162
|
|
- }
|
163
|
|
- }
|
|
152
|
+ if (displayVisibilityCheck) {
|
|
153
|
+ ImGui::Text("NewMin: %.3f %.3f %.3f", newMin.x, newMin.y, newMin.z);
|
|
154
|
+ ImGui::Text("NewMax: %.3f %.3f %.3f", newMax.x, newMax.y, newMax.z);
|
|
155
|
+ }
|
164
|
156
|
|
165
|
|
- // ...only render it if it is not
|
166
|
|
- if (!found) {
|
167
|
|
- buildRoomList(VP, portal.getAdjoiningRoom(), newMin, newMax);
|
|
157
|
+ //! \fixme Currently also checking behind player, because Z is always 1.0f?!
|
|
158
|
+ //if ((newMin.z > 0.0f) || (newMin.z < -1.0f) || (newMax.z > 0.0f) || (newMax.z < -1.0f)) {
|
|
159
|
+ // continue;
|
|
160
|
+ //}
|
|
161
|
+
|
|
162
|
+ // Check if the portal intersects the portal leading into this room
|
|
163
|
+ if (!((min.x < newMax.x) && (max.x > newMin.x)
|
|
164
|
+ && (min.y < newMax.y) && (max.y > newMin.y))) {
|
|
165
|
+ continue;
|
|
166
|
+ }
|
|
167
|
+
|
|
168
|
+ // Check if this room is already in the list...
|
|
169
|
+ bool found = false;
|
|
170
|
+ for (int n = 0; n < roomList.size(); n++) {
|
|
171
|
+ if (roomList.at(n) == &World::getRoom(portal.getAdjoiningRoom())) {
|
|
172
|
+ found = true;
|
|
173
|
+ break;
|
168
|
174
|
}
|
169
|
175
|
}
|
|
176
|
+
|
|
177
|
+ // ...only render it if it is not
|
|
178
|
+ if (!found) {
|
|
179
|
+ buildRoomList(VP, portal.getAdjoiningRoom(), glm::vec2(newMin), glm::vec2(newMax));
|
|
180
|
+ }
|
170
|
181
|
}
|
171
|
182
|
}
|
172
|
183
|
}
|
|
@@ -269,6 +280,8 @@ void Render::displayUI() {
|
269
|
280
|
if (ImGui::Checkbox("Portals##bbox", &showBoundingBox3)) {
|
270
|
281
|
Portal::setShowBoundingBox(showBoundingBox3);
|
271
|
282
|
}
|
|
283
|
+ ImGui::SameLine();
|
|
284
|
+ ImGui::Checkbox("VisChecks##bbox", &displayVisibilityCheck);
|
272
|
285
|
|
273
|
286
|
ImGui::Separator();
|
274
|
287
|
ImGui::Text("Renderable Objects:");
|