|
@@ -133,16 +133,10 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
|
133
|
133
|
auto& r = World::getRoom(portal.getAdjoiningRoom());
|
134
|
134
|
|
135
|
135
|
// Calculate the 2D screen-space bounding box of this portal
|
136
|
|
- glm::vec3 newMin, newMax;
|
|
136
|
+ glm::vec4 newMin, newMax;
|
137
|
137
|
for (int c = 0; c < 4; c++) {
|
138
|
138
|
glm::vec3 port = portal.getVertex(c);
|
139
|
|
- glm::vec4 result = VP * glm::vec4(port, 1.0f);
|
140
|
|
- glm::vec3 vert = glm::vec3(result) / result.w;
|
141
|
|
-
|
142
|
|
- ImGui::Text("%.2f %.2f %.2f", port.x, port.y, port.z);
|
143
|
|
- ImGui::Text("%.2f %.2f %.2f %.2f", result.x, result.y, result.z, result.w);
|
144
|
|
- ImGui::Text("%.2f %.2f %.2f", vert.x, vert.y, vert.z);
|
145
|
|
- ImGui::Text("----");
|
|
139
|
+ glm::vec4 vert = VP * glm::vec4(port, 1.0f);
|
146
|
140
|
|
147
|
141
|
if (c == 0) {
|
148
|
142
|
newMin = vert;
|
|
@@ -154,23 +148,24 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
|
154
|
148
|
newMin.y = vert.y;
|
155
|
149
|
if (vert.z < newMin.z)
|
156
|
150
|
newMin.z = vert.z;
|
|
151
|
+ if (vert.w < newMin.w)
|
|
152
|
+ newMin.w = vert.w;
|
157
|
153
|
if (vert.x > newMax.x)
|
158
|
154
|
newMax.x = vert.x;
|
159
|
155
|
if (vert.y > newMax.y)
|
160
|
156
|
newMax.y = vert.y;
|
161
|
157
|
if (vert.z > newMax.z)
|
162
|
158
|
newMax.z = vert.z;
|
|
159
|
+ if (vert.w > newMax.w)
|
|
160
|
+ newMax.w = vert.w;
|
163
|
161
|
}
|
164
|
162
|
}
|
165
|
163
|
|
166
|
|
- //ImGui::Text("%.2f %.2f %.2f", newMin.x, newMin.y, newMin.z);
|
167
|
|
- //ImGui::Text("%.2f %.2f %.2f", newMax.x, newMax.y, newMax.z);
|
168
|
|
- //ImGui::Text("----");
|
169
|
|
-
|
170
|
|
- //! \fixme Currently also checking behind player, because Z is always 1.0f?!
|
171
|
|
- //if ((newMin.z > 0.0f) || (newMin.z < -1.0f) || (newMax.z > 0.0f) || (newMax.z < -1.0f)) {
|
172
|
|
- // continue;
|
173
|
|
- //}
|
|
164
|
+ // Check if the portal lies behind the player
|
|
165
|
+ if (!((newMin.z <= newMin.w) && (newMin.z >= -newMin.w)
|
|
166
|
+ && (newMax.z <= newMax.w) && (newMax.z >= -newMax.w))) {
|
|
167
|
+ continue;
|
|
168
|
+ }
|
174
|
169
|
|
175
|
170
|
//! \fixme Need to check portal normal, only render if it points in our direction
|
176
|
171
|
//if (!normalFacingUs) {
|
|
@@ -178,8 +173,8 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
|
178
|
173
|
//}
|
179
|
174
|
|
180
|
175
|
// Check if the portal intersects the portal leading into this room
|
181
|
|
- if (!((min.x < newMax.x) && (max.x > newMin.x)
|
182
|
|
- && (min.y < newMax.y) && (max.y > newMin.y))) {
|
|
176
|
+ if (!((min.x < (newMax.x / newMax.w)) && (max.x > (newMin.x / newMin.w))
|
|
177
|
+ && (min.y < (newMax.y / newMax.w)) && (max.y > (newMin.y / newMin.w)))) {
|
183
|
178
|
continue;
|
184
|
179
|
}
|
185
|
180
|
|
|
@@ -199,7 +194,7 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
|
199
|
194
|
|
200
|
195
|
// ...only render it if it is not
|
201
|
196
|
if (!found) {
|
202
|
|
- buildRoomList(VP, portal.getAdjoiningRoom(), glm::vec2(newMin), glm::vec2(newMax));
|
|
197
|
+ buildRoomList(VP, portal.getAdjoiningRoom(), glm::vec2(newMin) / newMin.w, glm::vec2(newMax) / newMax.w);
|
203
|
198
|
}
|
204
|
199
|
}
|
205
|
200
|
}
|