Browse Source

Fixed new 2D portal visibility checks.

Thomas Buck 9 years ago
parent
commit
cffa1c7041
8 changed files with 93 additions and 75 deletions
  1. 5
    0
      ChangeLog.md
  2. 2
    3
      include/Camera.h
  3. 1
    0
      include/Render.h
  4. 9
    10
      src/Camera.cpp
  5. 63
    50
      src/Render.cpp
  6. 7
    6
      src/RoomData.cpp
  7. 2
    2
      src/SkeletalModel.cpp
  8. 4
    4
      src/system/Shader.cpp

+ 5
- 0
ChangeLog.md View File

2
 
2
 
3
 ## OpenRaider (0.1.4) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.4) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20150405 ]
6
+    * No longer flipping axis in shaders, now turning camera upside-down.
7
+    * Mostly fixed portal-to-portal 2D visibility checks.
8
+        * Currently also checking behind player.
9
+
5
     [ 20150404 ]
10
     [ 20150404 ]
6
     * World is now static
11
     * World is now static
7
     * Can display debug informations about Rooms and StaticMeshes
12
     * Can display debug informations about Rooms and StaticMeshes

+ 2
- 3
include/Camera.h View File

22
     static void handleMouseMotion(int x, int y);
22
     static void handleMouseMotion(int x, int y);
23
     static void handleControllerAxis(float value, KeyboardButton axis);
23
     static void handleControllerAxis(float value, KeyboardButton axis);
24
 
24
 
25
-    //! \fixme The Y axis seems to be the source of all evil?
26
-    static void setPosition(glm::vec3 p) { pos = glm::vec3(p.x, -p.y, p.z); dirty = true; }
27
-    static glm::vec3 getPosition() { return glm::vec3(pos.x, -pos.y, pos.z); }
25
+    static void setPosition(glm::vec3 p) { pos = p; dirty = true; }
26
+    static glm::vec3 getPosition() { return pos; }
28
 
27
 
29
     static glm::vec2 getRotation() { return rot; }
28
     static glm::vec2 getRotation() { return rot; }
30
     static glm::mat4 getProjectionMatrix() { return projection; }
29
     static glm::mat4 getProjectionMatrix() { return projection; }

+ 1
- 0
include/Render.h View File

48
     static std::vector<Room*> roomList;
48
     static std::vector<Room*> roomList;
49
 
49
 
50
     static bool displayViewFrustum;
50
     static bool displayViewFrustum;
51
+    static bool displayVisibilityCheck;
51
 };
52
 };
52
 
53
 
53
 #endif
54
 #endif

+ 9
- 10
src/Camera.cpp View File

79
 }
79
 }
80
 
80
 
81
 void Camera::setSize(glm::i32vec2 s) {
81
 void Camera::setSize(glm::i32vec2 s) {
82
-    //! \fixme TODO instead of mirroring the Y axis in the shader, scale with -1 here
83
     projection = glm::perspective(fov, float(s.x) / float(s.y), nearDist, farDist);
82
     projection = glm::perspective(fov, float(s.x) / float(s.y), nearDist, farDist);
84
 }
83
 }
85
 
84
 
93
     } else if (action == backwardAction) {
92
     } else if (action == backwardAction) {
94
         posSpeed -= dirUnit * maxSpeed * factor;
93
         posSpeed -= dirUnit * maxSpeed * factor;
95
     } else if (action == leftAction) {
94
     } else if (action == leftAction) {
96
-        posSpeed += rightUnit * maxSpeed * factor;
97
-    } else if (action == rightAction) {
98
         posSpeed -= rightUnit * maxSpeed * factor;
95
         posSpeed -= rightUnit * maxSpeed * factor;
96
+    } else if (action == rightAction) {
97
+        posSpeed += rightUnit * maxSpeed * factor;
99
     } else if (action == jumpAction) {
98
     } else if (action == jumpAction) {
100
         posSpeed += upUnit * maxSpeed * factor;
99
         posSpeed += upUnit * maxSpeed * factor;
101
     } else if (action == crouchAction) {
100
     } else if (action == crouchAction) {
114
         dirty = true;
113
         dirty = true;
115
 
114
 
116
     while (x > 0) {
115
     while (x > 0) {
117
-        rot.x += rotationDeltaX;
116
+        rot.x -= rotationDeltaX;
118
         x--;
117
         x--;
119
     }
118
     }
120
 
119
 
121
     while (x < 0) {
120
     while (x < 0) {
122
-        rot.x -= rotationDeltaX;
121
+        rot.x += rotationDeltaX;
123
         x++;
122
         x++;
124
     }
123
     }
125
 
124
 
143
         value = 0.0f;
142
         value = 0.0f;
144
 
143
 
145
     if (axis == leftXAxis) {
144
     if (axis == leftXAxis) {
146
-        posSpeed.x = -maxSpeed * value;
145
+        posSpeed.x = maxSpeed * value;
147
     } else if (axis == leftYAxis) {
146
     } else if (axis == leftYAxis) {
148
         posSpeed.z = maxSpeed * value;
147
         posSpeed.z = maxSpeed * value;
149
     } else if (axis == rightXAxis) {
148
     } else if (axis == rightXAxis) {
150
-        rotSpeed.x = controllerViewFactor * value;
149
+        rotSpeed.x = -controllerViewFactor * value;
151
     } else if (axis == rightYAxis) {
150
     } else if (axis == rightYAxis) {
152
         rotSpeed.y = -controllerViewFactor * value;
151
         rotSpeed.y = -controllerViewFactor * value;
153
     } else {
152
     } else {
178
     else
177
     else
179
         rotSpeed = glm::vec2(0.0f, 0.0f);
178
         rotSpeed = glm::vec2(0.0f, 0.0f);
180
 
179
 
180
+    static glm::quat quatZ = glm::angleAxis(glm::pi<float>(), glm::vec3(0.0f, 0.0f, 1.0f));
181
     glm::quat quatY = glm::angleAxis(rot.x, glm::vec3(0.0f, 1.0f, 0.0f));
181
     glm::quat quatY = glm::angleAxis(rot.x, glm::vec3(0.0f, 1.0f, 0.0f));
182
     glm::quat quatX = glm::angleAxis(rot.y, glm::vec3(1.0f, 0.0f, 0.0f));
182
     glm::quat quatX = glm::angleAxis(rot.y, glm::vec3(1.0f, 0.0f, 0.0f));
183
-    glm::quat quaternion = quatY * quatX;
183
+    glm::quat quaternion = quatZ * quatY * quatX;
184
 
184
 
185
     glm::vec3 clampedSpeed;
185
     glm::vec3 clampedSpeed;
186
     if (movingFaster) {
186
     if (movingFaster) {
297
     for (int i = 0; i < 8; i++) {
297
     for (int i = 0; i < 8; i++) {
298
         glm::vec4 t = inverse * glm::vec4(frustumVertices[i], 1.0f);
298
         glm::vec4 t = inverse * glm::vec4(frustumVertices[i], 1.0f);
299
         frustumVertices[i] = glm::vec3(t) / t.w;
299
         frustumVertices[i] = glm::vec3(t) / t.w;
300
-        frustumVertices[i].y *= -1.0f;
301
     }
300
     }
302
 
301
 
303
     // Set planes used for frustum culling
302
     // Set planes used for frustum culling
373
     for (int i = 0; i < 6; i++) {
372
     for (int i = 0; i < 6; i++) {
374
         int out = 0, in = 0;
373
         int out = 0, in = 0;
375
         for (int c = 0; (c < 8) && ((in == 0) || (out == 0)); c++) {
374
         for (int c = 0; (c < 8) && ((in == 0) || (out == 0)); c++) {
376
-            if (planes[i].distance(b.getCorner(c)) < 0)
375
+            if (planes[i].distance(b.getCorner(c)) > 0)
377
                 out++;
376
                 out++;
378
             else
377
             else
379
                 in++;
378
                 in++;

+ 63
- 50
src/Render.cpp View File

28
 RenderMode Render::mode = RenderMode::LoadScreen;
28
 RenderMode Render::mode = RenderMode::LoadScreen;
29
 std::vector<Room*> Render::roomList;
29
 std::vector<Room*> Render::roomList;
30
 bool Render::displayViewFrustum = false;
30
 bool Render::displayViewFrustum = false;
31
+bool Render::displayVisibilityCheck = false;
31
 
32
 
32
 void Render::display() {
33
 void Render::display() {
33
     gl::glClear(gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT);
34
     gl::glClear(gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT);
56
     glm::mat4 view = Camera::getViewMatrix();
57
     glm::mat4 view = Camera::getViewMatrix();
57
     glm::mat4 VP = projection * view;
58
     glm::mat4 VP = projection * view;
58
 
59
 
59
-    //if (updated) {
60
+    if (updated || displayVisibilityCheck) {
60
         int r = Camera::getRoom();
61
         int r = Camera::getRoom();
61
         clearRoomList();
62
         clearRoomList();
62
         if (r < 0) {
63
         if (r < 0) {
64
         } else {
65
         } else {
65
             buildRoomList(VP, r);
66
             buildRoomList(VP, r);
66
         }
67
         }
67
-    //}
68
+    }
68
 
69
 
69
     for (int r = roomList.size() - 1; r >= 0; r--) {
70
     for (int r = roomList.size() - 1; r >= 0; r--) {
70
         roomList.at(r)->display(VP);
71
         roomList.at(r)->display(VP);
103
             }
104
             }
104
         }
105
         }
105
     } else {
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
             // Display the visibility test for the portal to this room
110
             // Display the visibility test for the portal to this room
111
             BoundingBox debugBox(glm::vec3(min, 0.0f), glm::vec3(max, 0.0f));
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));
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
             ImGui::Text("   Min: %.3f %.3f", min.x, min.y);
114
             ImGui::Text("   Min: %.3f %.3f", min.x, min.y);
115
             ImGui::Text("   Max: %.3f %.3f", max.x, max.y);
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
                 } else {
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
         if (ImGui::Checkbox("Portals##bbox", &showBoundingBox3)) {
280
         if (ImGui::Checkbox("Portals##bbox", &showBoundingBox3)) {
270
             Portal::setShowBoundingBox(showBoundingBox3);
281
             Portal::setShowBoundingBox(showBoundingBox3);
271
         }
282
         }
283
+        ImGui::SameLine();
284
+        ImGui::Checkbox("VisChecks##bbox", &displayVisibilityCheck);
272
 
285
 
273
         ImGui::Separator();
286
         ImGui::Separator();
274
         ImGui::Text("Renderable Objects:");
287
         ImGui::Text("Renderable Objects:");

+ 7
- 6
src/RoomData.cpp View File

59
 // ----------------------------------------------------------------------------
59
 // ----------------------------------------------------------------------------
60
 
60
 
61
 StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {
61
 StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {
62
-    glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z));
62
+    glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
63
     glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 1.0f, 0.0f));
63
     glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 1.0f, 0.0f));
64
     model = translate * rotate;
64
     model = translate * rotate;
65
 }
65
 }
84
 // ----------------------------------------------------------------------------
84
 // ----------------------------------------------------------------------------
85
 
85
 
86
 void RoomSprite::display(glm::mat4 VP) {
86
 void RoomSprite::display(glm::mat4 VP) {
87
-    glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z));
88
-    glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), Camera::getRotation().x, glm::vec3(0.0f, 1.0f,
89
-                                   0.0f));
90
-    glm::mat4 model = translate * rotate;
87
+    glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
91
 
88
 
92
-    World::getSprite(sprite).display(VP * model);
89
+    //! \fixme Calculate angle between camera and sprite
90
+    glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), Camera::getRotation().x,
91
+                                   glm::vec3(0.0f, 1.0f, 0.0f));
92
+
93
+    World::getSprite(sprite).display(VP * (translate * rotate));
93
 }
94
 }
94
 
95
 
95
 // ----------------------------------------------------------------------------
96
 // ----------------------------------------------------------------------------

+ 2
- 2
src/SkeletalModel.cpp View File

108
     BoneFrame& boneframe = anim.get(bframe);
108
     BoneFrame& boneframe = anim.get(bframe);
109
 
109
 
110
     glm::vec3 pos = boneframe.getPosition();
110
     glm::vec3 pos = boneframe.getPosition();
111
-    glm::mat4 frameTrans = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z));
111
+    glm::mat4 frameTrans = glm::translate(glm::mat4(1.0f), pos);
112
 
112
 
113
     MatrixStack stack(MVP * frameTrans);
113
     MatrixStack stack(MVP * frameTrans);
114
 
114
 
147
 #endif
147
 #endif
148
 
148
 
149
             glm::vec3 off = tag.getOffset();
149
             glm::vec3 off = tag.getOffset();
150
-            translate = glm::translate(glm::mat4(1.0f), glm::vec3(off.x, -off.y, off.z));
150
+            translate = glm::translate(glm::mat4(1.0f), off);
151
         }
151
         }
152
 
152
 
153
         glm::vec3 rot = tag.getRotation();
153
         glm::vec3 rot = tag.getRotation();

+ 4
- 4
src/system/Shader.cpp View File

411
 
411
 
412
 void main() {
412
 void main() {
413
     vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
413
     vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
414
-                          -vertexPosition_modelspace.y,
414
+                          vertexPosition_modelspace.y,
415
                           vertexPosition_modelspace.z,
415
                           vertexPosition_modelspace.z,
416
                           1);
416
                           1);
417
-    gl_Position = vec4(-pos.x, pos.yzw);
417
+    gl_Position = pos;
418
     UV = vertexUV;
418
     UV = vertexUV;
419
 }
419
 }
420
 )!?!";
420
 )!?!";
447
 
447
 
448
 void main() {
448
 void main() {
449
     vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
449
     vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
450
-                          -vertexPosition_modelspace.y,
450
+                          vertexPosition_modelspace.y,
451
                           vertexPosition_modelspace.z,
451
                           vertexPosition_modelspace.z,
452
                           1);
452
                           1);
453
-    gl_Position = vec4(-pos.x, pos.yzw);
453
+    gl_Position = pos;
454
     color = vertexColor;
454
     color = vertexColor;
455
 }
455
 }
456
 )!?!";
456
 )!?!";

Loading…
Cancel
Save