|
@@ -51,19 +51,20 @@ void Render::display() {
|
51
|
51
|
gl::glPolygonMode(gl::GL_FRONT_AND_BACK, gl::GL_FILL);
|
52
|
52
|
}
|
53
|
53
|
|
54
|
|
- if (Camera::update()) {
|
|
54
|
+ bool updated = Camera::update();
|
|
55
|
+ glm::mat4 projection = Camera::getProjectionMatrix();
|
|
56
|
+ glm::mat4 view = Camera::getViewMatrix();
|
|
57
|
+ glm::mat4 VP = projection * view;
|
|
58
|
+
|
|
59
|
+ //if (updated) {
|
55
|
60
|
int r = Camera::getRoom();
|
56
|
61
|
clearRoomList();
|
57
|
62
|
if (r < 0) {
|
58
|
|
- buildRoomList();
|
|
63
|
+ buildRoomList(VP);
|
59
|
64
|
} else {
|
60
|
|
- buildRoomList(r);
|
|
65
|
+ buildRoomList(VP, r);
|
61
|
66
|
}
|
62
|
|
- }
|
63
|
|
-
|
64
|
|
- glm::mat4 projection = Camera::getProjectionMatrix();
|
65
|
|
- glm::mat4 view = Camera::getViewMatrix();
|
66
|
|
- glm::mat4 VP = projection * view;
|
|
67
|
+ //}
|
67
|
68
|
|
68
|
69
|
for (int r = roomList.size() - 1; r >= 0; r--) {
|
69
|
70
|
roomList.at(r)->display(VP);
|
|
@@ -84,16 +85,16 @@ void Render::display() {
|
84
|
85
|
}
|
85
|
86
|
}
|
86
|
87
|
|
87
|
|
-void Render::buildRoomList(int room, int budget) {
|
|
88
|
+void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max) {
|
88
|
89
|
if (room < -1) {
|
89
|
90
|
// Check if the camera currently is in a room...
|
90
|
91
|
for (int i = 0; i < World::sizeRoom(); i++) {
|
91
|
92
|
if (World::getRoom(i).getBoundingBox().inBox(Camera::getPosition())) {
|
92
|
|
- buildRoomList(i, budget);
|
|
93
|
+ buildRoomList(VP, i);
|
93
|
94
|
return;
|
94
|
95
|
}
|
95
|
96
|
}
|
96
|
|
- buildRoomList(-1, budget);
|
|
97
|
+ buildRoomList(VP, -1);
|
97
|
98
|
} else if (room == -1) {
|
98
|
99
|
// Check visibility for all rooms!
|
99
|
100
|
for (int i = 0; i < World::sizeRoom(); i++) {
|
|
@@ -102,19 +103,57 @@ void Render::buildRoomList(int room, int budget) {
|
102
|
103
|
}
|
103
|
104
|
}
|
104
|
105
|
} else {
|
105
|
|
- // Check visibility of room and connected rooms, recursively
|
|
106
|
+ // Check if this room is visible
|
106
|
107
|
if (Camera::boxInFrustum(World::getRoom(room).getBoundingBox())) {
|
107
|
108
|
roomList.push_back(&World::getRoom(room));
|
|
109
|
+
|
|
110
|
+ // Display the visibility test for the portal to this room
|
|
111
|
+ BoundingBox debugBox(glm::vec3(min, 0.0f), glm::vec3(max, 0.0f));
|
|
112
|
+ debugBox.display(glm::mat4(1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
|
113
|
+
|
|
114
|
+ ImGui::Text(" Min: %.3f %.3f", min.x, min.y);
|
|
115
|
+ ImGui::Text(" Max: %.3f %.3f", max.x, max.y);
|
|
116
|
+
|
|
117
|
+ // Check all portals leading from this room to somewhere else
|
108
|
118
|
for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
|
109
|
119
|
auto& portal = World::getRoom(room).getPortal(i);
|
110
|
120
|
|
111
|
|
- // Check if portal is visible / can be seen through
|
112
|
|
- bool visible = Camera::boxInFrustum(portal.getBoundingBox());
|
113
|
|
- if (!visible) {
|
|
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
|
+ }
|
|
145
|
+ }
|
|
146
|
+
|
|
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!");
|
114
|
151
|
continue;
|
|
152
|
+ } else {
|
|
153
|
+ ImGui::Text("Visible!");
|
115
|
154
|
}
|
116
|
155
|
|
117
|
|
- // Check if already in list...
|
|
156
|
+ // Check if this room is already in the list...
|
118
|
157
|
bool found = false;
|
119
|
158
|
for (int n = 0; n < roomList.size(); n++) {
|
120
|
159
|
if (roomList.at(n) == &World::getRoom(portal.getAdjoiningRoom())) {
|
|
@@ -123,11 +162,9 @@ void Render::buildRoomList(int room, int budget) {
|
123
|
162
|
}
|
124
|
163
|
}
|
125
|
164
|
|
126
|
|
- // ...only render if not
|
|
165
|
+ // ...only render it if it is not
|
127
|
166
|
if (!found) {
|
128
|
|
- if (budget > 0) {
|
129
|
|
- buildRoomList(portal.getAdjoiningRoom(), --budget);
|
130
|
|
- }
|
|
167
|
+ buildRoomList(VP, portal.getAdjoiningRoom(), newMin, newMax);
|
131
|
168
|
}
|
132
|
169
|
}
|
133
|
170
|
}
|