Pārlūkot izejas kodu

No longer checking portals behind player

Thomas Buck 9 gadus atpakaļ
vecāks
revīzija
902128652c
2 mainītis faili ar 28 papildinājumiem un 19 dzēšanām
  1. 14
    0
      ChangeLog.md
  2. 14
    19
      src/Render.cpp

+ 14
- 0
ChangeLog.md Parādīt failu

2
 
2
 
3
 ## OpenRaider (0.1.4) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.4) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20150429 ]
6
+    * Fixed the new BoundingBox rendering approach
7
+    * Fixed portal rendering method, no longer checking portals behind player.
8
+
9
+    [ 20150424 ]
10
+    * Imgui update
11
+
12
+    [ 20150417 ]
13
+    * Updated imgui
14
+    * First try at scissoring rendering through room portals.
15
+
16
+    [ 20150413 ]
17
+    * Now trying to cache all bounding box vertices, drawing all at end of frame.
18
+
5
     [ 20150408 ]
19
     [ 20150408 ]
6
     * Now checking for errors after every OpenGL call.
20
     * Now checking for errors after every OpenGL call.
7
     * Slightly tweaked portal visibility checks.
21
     * Slightly tweaked portal visibility checks.

+ 14
- 19
src/Render.cpp Parādīt failu

133
             auto& r = World::getRoom(portal.getAdjoiningRoom());
133
             auto& r = World::getRoom(portal.getAdjoiningRoom());
134
 
134
 
135
             // Calculate the 2D screen-space bounding box of this portal
135
             // Calculate the 2D screen-space bounding box of this portal
136
-            glm::vec3 newMin, newMax;
136
+            glm::vec4 newMin, newMax;
137
             for (int c = 0; c < 4; c++) {
137
             for (int c = 0; c < 4; c++) {
138
                 glm::vec3 port = portal.getVertex(c);
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
                 if (c == 0) {
141
                 if (c == 0) {
148
                     newMin = vert;
142
                     newMin = vert;
154
                         newMin.y = vert.y;
148
                         newMin.y = vert.y;
155
                     if (vert.z < newMin.z)
149
                     if (vert.z < newMin.z)
156
                         newMin.z = vert.z;
150
                         newMin.z = vert.z;
151
+                    if (vert.w < newMin.w)
152
+                        newMin.w = vert.w;
157
                     if (vert.x > newMax.x)
153
                     if (vert.x > newMax.x)
158
                         newMax.x = vert.x;
154
                         newMax.x = vert.x;
159
                     if (vert.y > newMax.y)
155
                     if (vert.y > newMax.y)
160
                         newMax.y = vert.y;
156
                         newMax.y = vert.y;
161
                     if (vert.z > newMax.z)
157
                     if (vert.z > newMax.z)
162
                         newMax.z = vert.z;
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
             //! \fixme Need to check portal normal, only render if it points in our direction
170
             //! \fixme Need to check portal normal, only render if it points in our direction
176
             //if (!normalFacingUs) {
171
             //if (!normalFacingUs) {
178
             //}
173
             //}
179
 
174
 
180
             // Check if the portal intersects the portal leading into this room
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
                 continue;
178
                 continue;
184
             }
179
             }
185
 
180
 
199
 
194
 
200
             // ...only render it if it is not
195
             // ...only render it if it is not
201
             if (!found) {
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
     }

Notiek ielāde…
Atcelt
Saglabāt