Browse Source

First try at scissoring room portals

Thomas Buck 9 years ago
parent
commit
9c84aa597f
6 changed files with 44 additions and 30 deletions
  1. 9
    1
      include/Render.h
  2. 7
    12
      src/BoundingBox.cpp
  3. 26
    6
      src/Render.cpp
  4. 0
    1
      src/RoomData.cpp
  5. 0
    2
      src/main.cpp
  6. 2
    8
      src/system/Shader.cpp

+ 9
- 1
include/Render.h View File

23
     Texture
23
     Texture
24
 };
24
 };
25
 
25
 
26
+struct RoomRenderList {
27
+    RoomRenderList(Room* r, glm::vec2 pos, glm::vec2 size)
28
+        : room(r), portalPos(pos), portalSize(size) { }
29
+
30
+    Room* room;
31
+    glm::vec2 portalPos, portalSize;
32
+};
33
+
26
 class Render {
34
 class Render {
27
   public:
35
   public:
28
 
36
 
45
                               glm::vec2 max = glm::vec2(1.0f, 1.0f));
53
                               glm::vec2 max = glm::vec2(1.0f, 1.0f));
46
 
54
 
47
     static RenderMode mode;
55
     static RenderMode mode;
48
-    static std::vector<Room*> roomList;
56
+    static std::vector<RoomRenderList> roomList;
49
 
57
 
50
     static bool displayViewFrustum;
58
     static bool displayViewFrustum;
51
     static bool displayVisibilityCheck;
59
     static bool displayVisibilityCheck;

+ 7
- 12
src/BoundingBox.cpp View File

39
     auto startSize = vertices.size();
39
     auto startSize = vertices.size();
40
 
40
 
41
     for (auto& c : corner) {
41
     for (auto& c : corner) {
42
-        vertices.emplace_back(VP * glm::vec4(c, 1.0f));
42
+        glm::vec4 t = VP * glm::vec4(c, 1.0f);
43
+        vertices.emplace_back(glm::vec3(t) / t.w);
43
         colorsLine.emplace_back(colorLine);
44
         colorsLine.emplace_back(colorLine);
44
         colorsPoint.emplace_back(colorDot);
45
         colorsPoint.emplace_back(colorDot);
45
     }
46
     }
62
     indicesLine.emplace_back(startSize);
63
     indicesLine.emplace_back(startSize);
63
     indicesLine.emplace_back(startSize);
64
     indicesLine.emplace_back(startSize);
64
     indicesLine.emplace_back(startSize + 1);
65
     indicesLine.emplace_back(startSize + 1);
65
-    indicesLine.emplace_back(startSize + 1);
66
-    indicesLine.emplace_back(startSize + 4);
67
     indicesLine.emplace_back(startSize + 4);
66
     indicesLine.emplace_back(startSize + 4);
68
     indicesLine.emplace_back(startSize + 7);
67
     indicesLine.emplace_back(startSize + 7);
69
-    indicesLine.emplace_back(startSize + 7);
70
-    indicesLine.emplace_back(startSize + 6);
71
     indicesLine.emplace_back(startSize + 6);
68
     indicesLine.emplace_back(startSize + 6);
72
     indicesLine.emplace_back(startSize + 3);
69
     indicesLine.emplace_back(startSize + 3);
73
-    indicesLine.emplace_back(startSize + 3);
74
-    indicesLine.emplace_back(startSize + 5);
75
     indicesLine.emplace_back(startSize + 5);
70
     indicesLine.emplace_back(startSize + 5);
76
     indicesLine.emplace_back(startSize + 2);
71
     indicesLine.emplace_back(startSize + 2);
77
 }
72
 }
80
     if (vertices.size() > 0) {
75
     if (vertices.size() > 0) {
81
         Shader::drawGL(vertices, colorsLine, indicesLine, glm::mat4(1.0f), gl::GL_LINES);
76
         Shader::drawGL(vertices, colorsLine, indicesLine, glm::mat4(1.0f), gl::GL_LINES);
82
         Shader::drawGL(vertices, colorsPoint, glm::mat4(1.0f), gl::GL_POINTS);
77
         Shader::drawGL(vertices, colorsPoint, glm::mat4(1.0f), gl::GL_POINTS);
83
-
84
-        vertices.clear();
85
-        colorsLine.clear();
86
-        colorsPoint.clear();
87
-        indicesLine.clear();
88
     }
78
     }
79
+
80
+    vertices.clear();
81
+    colorsLine.clear();
82
+    colorsPoint.clear();
83
+    indicesLine.clear();
89
 }
84
 }
90
 
85
 

+ 26
- 6
src/Render.cpp View File

10
 #include <sstream>
10
 #include <sstream>
11
 
11
 
12
 #include "global.h"
12
 #include "global.h"
13
+#include "BoundingBox.h"
13
 #include "Camera.h"
14
 #include "Camera.h"
14
 #include "Log.h"
15
 #include "Log.h"
15
 #include "Menu.h"
16
 #include "Menu.h"
26
 #include "stb/stb_image_write.h"
27
 #include "stb/stb_image_write.h"
27
 
28
 
28
 RenderMode Render::mode = RenderMode::LoadScreen;
29
 RenderMode Render::mode = RenderMode::LoadScreen;
29
-std::vector<Room*> Render::roomList;
30
+std::vector<RoomRenderList> Render::roomList;
30
 bool Render::displayViewFrustum = false;
31
 bool Render::displayViewFrustum = false;
31
 bool Render::displayVisibilityCheck = false;
32
 bool Render::displayVisibilityCheck = false;
32
 
33
 
63
     }
64
     }
64
 
65
 
65
     for (int r = roomList.size() - 1; r >= 0; r--) {
66
     for (int r = roomList.size() - 1; r >= 0; r--) {
66
-        roomList.at(r)->display(VP);
67
+        auto& rl = roomList.at(r);
68
+
69
+        //! \fixme TODO scissor to portal in screenspace to fix 4D rendering
70
+
71
+        //gl::glEnable(gl::GL_SCISSOR_TEST);
72
+        //gl::glScissor(rl.portalPos.x, rl.portalPos.y, rl.portalSize.x, rl.portalSize.y);
73
+
74
+        //ImGui::Text("%.2f %.2f", rl.portalPos.x, rl.portalPos.y);
75
+        //ImGui::Text("%.2f %.2f", rl.portalSize.x, rl.portalSize.y);
76
+        //ImGui::Text("--");
77
+
78
+        rl.room->display(VP);
67
 
79
 
68
         for (int i = 0; i < World::sizeEntity(); i++) {
80
         for (int i = 0; i < World::sizeEntity(); i++) {
69
             auto& e = World::getEntity(i);
81
             auto& e = World::getEntity(i);
70
-            if (roomList.at(r)->getIndex() == e.getRoom()) {
82
+            if (rl.room->getIndex() == e.getRoom()) {
71
                 e.display(VP);
83
                 e.display(VP);
72
             }
84
             }
73
         }
85
         }
86
+
87
+        //gl::glDisable(gl::GL_SCISSOR_TEST);
74
     }
88
     }
75
 
89
 
76
     if (displayViewFrustum)
90
     if (displayViewFrustum)
77
         Camera::displayFrustum(VP);
91
         Camera::displayFrustum(VP);
78
 
92
 
93
+    BoundingBox::display();
94
+
79
     if (mode == RenderMode::Wireframe) {
95
     if (mode == RenderMode::Wireframe) {
80
         gl::glPolygonMode(gl::GL_FRONT_AND_BACK, gl::GL_FILL);
96
         gl::glPolygonMode(gl::GL_FRONT_AND_BACK, gl::GL_FILL);
81
     }
97
     }
82
 }
98
 }
83
 
99
 
84
 void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max) {
100
 void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max) {
101
+    glm::vec2 halfSize = glm::vec2(Window::getSize()) / 2.0f;
102
+    glm::vec2 pos = (min * halfSize) + halfSize;
103
+    glm::vec2 size = (max * halfSize) + halfSize - pos;
104
+
85
     if (room < -1) {
105
     if (room < -1) {
86
         // Check if the camera currently is in a room...
106
         // Check if the camera currently is in a room...
87
         for (int i = 0; i < World::sizeRoom(); i++) {
107
         for (int i = 0; i < World::sizeRoom(); i++) {
95
         // Check visibility for all rooms!
115
         // Check visibility for all rooms!
96
         for (int i = 0; i < World::sizeRoom(); i++) {
116
         for (int i = 0; i < World::sizeRoom(); i++) {
97
             if (Camera::boxInFrustum(World::getRoom(i).getBoundingBox())) {
117
             if (Camera::boxInFrustum(World::getRoom(i).getBoundingBox())) {
98
-                roomList.push_back(&World::getRoom(i));
118
+                roomList.emplace_back(&World::getRoom(i), pos, size);
99
             }
119
             }
100
         }
120
         }
101
     } else {
121
     } else {
102
-        roomList.push_back(&World::getRoom(room));
122
+        roomList.emplace_back(&World::getRoom(room), pos, size);
103
 
123
 
104
         if (displayVisibilityCheck) {
124
         if (displayVisibilityCheck) {
105
             // Display the visibility test for the portal to this room
125
             // Display the visibility test for the portal to this room
157
             // Check if this room is already in the list...
177
             // Check if this room is already in the list...
158
             bool found = false;
178
             bool found = false;
159
             for (int n = 0; n < roomList.size(); n++) {
179
             for (int n = 0; n < roomList.size(); n++) {
160
-                if (roomList.at(n) == &room) {
180
+                if (roomList.at(n).room == &room) {
161
                     found = true;
181
                     found = true;
162
                     break;
182
                     break;
163
                 }
183
                 }

+ 0
- 1
src/RoomData.cpp View File

13
 
13
 
14
 #include "imgui/imgui.h"
14
 #include "imgui/imgui.h"
15
 
15
 
16
-#include <glbinding/gl/gl.h>
17
 #include <glm/gtc/matrix_transform.hpp>
16
 #include <glm/gtc/matrix_transform.hpp>
18
 
17
 
19
 StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {
18
 StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {

+ 0
- 2
src/main.cpp View File

9
 #include <memory>
9
 #include <memory>
10
 
10
 
11
 #include "global.h"
11
 #include "global.h"
12
-#include "BoundingBox.h"
13
 #include "Camera.h"
12
 #include "Camera.h"
14
 #include "Log.h"
13
 #include "Log.h"
15
 #include "Menu.h"
14
 #include "Menu.h"
196
 
195
 
197
 void renderFrame() {
196
 void renderFrame() {
198
     Render::display();
197
     Render::display();
199
-    BoundingBox::display();
200
     UI::display();
198
     UI::display();
201
     Window::swapBuffers();
199
     Window::swapBuffers();
202
     RunTime::updateFPS();
200
     RunTime::updateFPS();

+ 2
- 8
src/system/Shader.cpp View File

416
 uniform mat4 MVP;
416
 uniform mat4 MVP;
417
 
417
 
418
 void main() {
418
 void main() {
419
-    vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
420
-                          vertexPosition_modelspace.y,
421
-                          vertexPosition_modelspace.z,
422
-                          1);
419
+    vec4 pos = MVP * vec4(vertexPosition_modelspace, 1);
423
     gl_Position = pos;
420
     gl_Position = pos;
424
     UV = vertexUV;
421
     UV = vertexUV;
425
 }
422
 }
452
 uniform mat4 MVP;
449
 uniform mat4 MVP;
453
 
450
 
454
 void main() {
451
 void main() {
455
-    vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
456
-                          vertexPosition_modelspace.y,
457
-                          vertexPosition_modelspace.z,
458
-                          1);
452
+    vec4 pos = MVP * vec4(vertexPosition_modelspace, 1);
459
     gl_Position = pos;
453
     gl_Position = pos;
460
     color = vertexColor;
454
     color = vertexColor;
461
 }
455
 }

Loading…
Cancel
Save