소스 검색

New vis check (work in progress)

Thomas Buck 9 년 전
부모
커밋
4681b6ac10
8개의 변경된 파일96개의 추가작업 그리고 44개의 파일을 삭제
  1. 13
    0
      CMakeLists.txt
  2. 3
    1
      include/Render.h
  3. 3
    6
      include/RoomData.h
  4. 4
    0
      src/Camera.cpp
  5. 57
    20
      src/Render.cpp
  6. 10
    0
      src/RoomData.cpp
  7. 1
    3
      src/loader/LoaderTR2.cpp
  8. 5
    14
      src/system/Shader.cpp

+ 13
- 0
CMakeLists.txt 파일 보기

171
         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
171
         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
172
         COMMENT "Auto-Formatting code..." VERBATIM
172
         COMMENT "Auto-Formatting code..." VERBATIM
173
     )
173
     )
174
+
175
+    #################################################################
176
+
177
+    # Count source code lines
178
+    add_custom_target (count
179
+        COMMAND cloc --exclude-dir=deps,cmake,data,build ${PROJECT_SOURCE_DIR}
180
+        COMMENT "Counting lines of source code..." VERBATIM
181
+    )
182
+
183
+    add_custom_target (countFull
184
+        COMMAND cloc --exclude-dir=build ${PROJECT_SOURCE_DIR}
185
+        COMMENT "Counting lines of source code..." VERBATIM
186
+    )
174
 endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
187
 endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
175
 
188
 

+ 3
- 1
include/Render.h 파일 보기

40
     static bool getDisplayViewFrustum() { return displayViewFrustum; }
40
     static bool getDisplayViewFrustum() { return displayViewFrustum; }
41
 
41
 
42
   private:
42
   private:
43
-    static void buildRoomList(int room = -2, int budget = 10);
43
+    static void buildRoomList(glm::mat4 VP, int room = -2,
44
+                              glm::vec2 min = glm::vec2(-1.0f, -1.0f),
45
+                              glm::vec2 max = glm::vec2(1.0f, 1.0f));
44
 
46
 
45
     static RenderMode mode;
47
     static RenderMode mode;
46
     static std::vector<Room*> roomList;
48
     static std::vector<Room*> roomList;

+ 3
- 6
include/RoomData.h 파일 보기

76
 
76
 
77
 class Portal {
77
 class Portal {
78
   public:
78
   public:
79
-    Portal(int adj, glm::vec3 n, glm::vec3 v1, glm::vec3 v2, glm::vec3 v3,
80
-           glm::vec3 v4) : adjoiningRoom(adj), normal(n), bbox(v1, v3) {
81
-        vert[0] = v1; vert[1] = v2;
82
-        vert[2] = v3; vert[3] = v4;
83
-    }
79
+    Portal(int adj, glm::vec3 n,
80
+           glm::vec3 v1, glm::vec3 v2, glm::vec3 v3, glm::vec3 v4);
84
 
81
 
85
     int getAdjoiningRoom() { return adjoiningRoom; }
82
     int getAdjoiningRoom() { return adjoiningRoom; }
86
     glm::vec3 getNormal() { return normal; }
83
     glm::vec3 getNormal() { return normal; }
102
     int adjoiningRoom;
99
     int adjoiningRoom;
103
     glm::vec3 normal;
100
     glm::vec3 normal;
104
     glm::vec3 vert[4];
101
     glm::vec3 vert[4];
105
-    BoundingBox bbox;
102
+    BoundingBox bbox, bboxNormal;
106
 
103
 
107
     static bool showBoundingBox;
104
     static bool showBoundingBox;
108
 };
105
 };

+ 4
- 0
src/Camera.cpp 파일 보기

278
 static std::vector<glm::vec3> colorPointBuffer;
278
 static std::vector<glm::vec3> colorPointBuffer;
279
 
279
 
280
 void Camera::calculateFrustumPlanes() {
280
 void Camera::calculateFrustumPlanes() {
281
+    vertexBuffer.clear();
282
+    vertexPointBuffer.clear();
283
+    colorPointBuffer.clear();
284
+
281
     glm::mat4 combo = projection * view;
285
     glm::mat4 combo = projection * view;
282
 
286
 
283
     // Calculate frustum corners to display them
287
     // Calculate frustum corners to display them

+ 57
- 20
src/Render.cpp 파일 보기

51
         gl::glPolygonMode(gl::GL_FRONT_AND_BACK, gl::GL_FILL);
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
         int r = Camera::getRoom();
60
         int r = Camera::getRoom();
56
         clearRoomList();
61
         clearRoomList();
57
         if (r < 0) {
62
         if (r < 0) {
58
-            buildRoomList();
63
+            buildRoomList(VP);
59
         } else {
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
     for (int r = roomList.size() - 1; r >= 0; r--) {
69
     for (int r = roomList.size() - 1; r >= 0; r--) {
69
         roomList.at(r)->display(VP);
70
         roomList.at(r)->display(VP);
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
     if (room < -1) {
89
     if (room < -1) {
89
         // Check if the camera currently is in a room...
90
         // Check if the camera currently is in a room...
90
         for (int i = 0; i < World::sizeRoom(); i++) {
91
         for (int i = 0; i < World::sizeRoom(); i++) {
91
             if (World::getRoom(i).getBoundingBox().inBox(Camera::getPosition())) {
92
             if (World::getRoom(i).getBoundingBox().inBox(Camera::getPosition())) {
92
-                buildRoomList(i, budget);
93
+                buildRoomList(VP, i);
93
                 return;
94
                 return;
94
             }
95
             }
95
         }
96
         }
96
-        buildRoomList(-1, budget);
97
+        buildRoomList(VP, -1);
97
     } else if (room == -1) {
98
     } else if (room == -1) {
98
         // Check visibility for all rooms!
99
         // Check visibility for all rooms!
99
         for (int i = 0; i < World::sizeRoom(); i++) {
100
         for (int i = 0; i < World::sizeRoom(); i++) {
102
             }
103
             }
103
         }
104
         }
104
     } else {
105
     } else {
105
-        // Check visibility of room and connected rooms, recursively
106
+        // Check if this room is visible
106
         if (Camera::boxInFrustum(World::getRoom(room).getBoundingBox())) {
107
         if (Camera::boxInFrustum(World::getRoom(room).getBoundingBox())) {
107
             roomList.push_back(&World::getRoom(room));
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
             for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
118
             for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
109
                 auto& portal = World::getRoom(room).getPortal(i);
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
                     continue;
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
                 bool found = false;
157
                 bool found = false;
119
                 for (int n = 0; n < roomList.size(); n++) {
158
                 for (int n = 0; n < roomList.size(); n++) {
120
                     if (roomList.at(n) == &World::getRoom(portal.getAdjoiningRoom())) {
159
                     if (roomList.at(n) == &World::getRoom(portal.getAdjoiningRoom())) {
123
                     }
162
                     }
124
                 }
163
                 }
125
 
164
 
126
-                // ...only render if not
165
+                // ...only render it if it is not
127
                 if (!found) {
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
         }

+ 10
- 0
src/RoomData.cpp 파일 보기

96
 
96
 
97
 bool Portal::showBoundingBox = false;
97
 bool Portal::showBoundingBox = false;
98
 
98
 
99
+Portal::Portal(int adj, glm::vec3 n, glm::vec3 v1, glm::vec3 v2, glm::vec3 v3,
100
+               glm::vec3 v4) : adjoiningRoom(adj), normal(n), bbox(v1, v3),
101
+                               bboxNormal(v1 + ((v3 - v1) / 2.0f),
102
+                                          v1 + ((v3 - v1) / 2.0f)
103
+                                             + (normal * 1024.0f)) {
104
+    vert[0] = v1; vert[1] = v2;
105
+    vert[2] = v3; vert[3] = v4;
106
+}
107
+
99
 void Portal::display(glm::mat4 VP) {
108
 void Portal::display(glm::mat4 VP) {
100
     if (showBoundingBox) {
109
     if (showBoundingBox) {
101
         bbox.display(VP, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
110
         bbox.display(VP, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
111
+        bboxNormal.display(VP, glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f));
102
     }
112
     }
103
 }
113
 }
104
 
114
 

+ 1
- 3
src/loader/LoaderTR2.cpp 파일 보기

381
             int16_t yCorner4 = file.read16();
381
             int16_t yCorner4 = file.read16();
382
             int16_t zCorner4 = file.read16();
382
             int16_t zCorner4 = file.read16();
383
 
383
 
384
-            // TODO translate vertices by room offset!
385
-
386
             portals.push_back(new Portal(adjoiningRoom,
384
             portals.push_back(new Portal(adjoiningRoom,
387
-                                         glm::vec3(xNormal, yNormal, zNormal) + pos,
385
+                                         glm::vec3(xNormal, yNormal, zNormal),
388
                                          glm::vec3(xCorner1, yCorner1, zCorner1) + pos,
386
                                          glm::vec3(xCorner1, yCorner1, zCorner1) + pos,
389
                                          glm::vec3(xCorner2, yCorner2, zCorner2) + pos,
387
                                          glm::vec3(xCorner2, yCorner2, zCorner2) + pos,
390
                                          glm::vec3(xCorner3, yCorner3, zCorner3) + pos,
388
                                          glm::vec3(xCorner3, yCorner3, zCorner3) + pos,

+ 5
- 14
src/system/Shader.cpp 파일 보기

137
 
137
 
138
 void Shader::use() {
138
 void Shader::use() {
139
     orAssert(programID >= 0);
139
     orAssert(programID >= 0);
140
-    gl::glUseProgram(programID);
140
+    static int lastID = -1;
141
+    if (programID != lastID) {
142
+        gl::glUseProgram(programID);
143
+        lastID = programID;
144
+    }
141
 }
145
 }
142
 
146
 
143
 int Shader::compile(const char* vertex, const char* fragment) {
147
 int Shader::compile(const char* vertex, const char* fragment) {
299
 void Shader::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& uvs,
303
 void Shader::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& uvs,
300
                     glm::mat4 MVP, unsigned int texture, TextureStorage store,
304
                     glm::mat4 MVP, unsigned int texture, TextureStorage store,
301
                     gl::GLenum mode, ShaderTexture* target, Shader& shader) {
305
                     gl::GLenum mode, ShaderTexture* target, Shader& shader) {
302
-    orAssert(vertices.size() == uvs.size());
303
-    if (mode == gl::GL_TRIANGLES)
304
-        orAssert((vertices.size() % 3) == 0);
305
     bindProperBuffer(target);
306
     bindProperBuffer(target);
306
 
307
 
307
     shader.use();
308
     shader.use();
329
 }
330
 }
330
 
331
 
331
 void Shader::drawGLBuffer(std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& uvs, Shader& shader) {
332
 void Shader::drawGLBuffer(std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& uvs, Shader& shader) {
332
-    orAssert(vertices.size() == uvs.size());
333
-
334
     shader.vertexBuffer.bufferData(vertices);
333
     shader.vertexBuffer.bufferData(vertices);
335
     shader.otherBuffer.bufferData(uvs);
334
     shader.otherBuffer.bufferData(uvs);
336
 }
335
 }
338
 void Shader::drawGLOnly(std::vector<unsigned short>& indices, glm::mat4 MVP,
337
 void Shader::drawGLOnly(std::vector<unsigned short>& indices, glm::mat4 MVP,
339
                         unsigned int texture, TextureStorage store,
338
                         unsigned int texture, TextureStorage store,
340
                         gl::GLenum mode, ShaderTexture* target, Shader& shader) {
339
                         gl::GLenum mode, ShaderTexture* target, Shader& shader) {
341
-    if (mode == gl::GL_TRIANGLES)
342
-        orAssert((indices.size() % 3) == 0);
343
     bindProperBuffer(target);
340
     bindProperBuffer(target);
344
 
341
 
345
     shader.use();
342
     shader.use();
360
 
357
 
361
 void Shader::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& colors,
358
 void Shader::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& colors,
362
                     glm::mat4 MVP, gl::GLenum mode, ShaderTexture* target, Shader& shader) {
359
                     glm::mat4 MVP, gl::GLenum mode, ShaderTexture* target, Shader& shader) {
363
-    orAssert(vertices.size() == colors.size());
364
-    if (mode == gl::GL_TRIANGLES)
365
-        orAssert((vertices.size() % 3) == 0);
366
     bindProperBuffer(target);
360
     bindProperBuffer(target);
367
 
361
 
368
     shader.use();
362
     shader.use();
383
 void Shader::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& colors,
377
 void Shader::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& colors,
384
                     std::vector<unsigned short>& indices, glm::mat4 MVP,
378
                     std::vector<unsigned short>& indices, glm::mat4 MVP,
385
                     gl::GLenum mode, ShaderTexture* target, Shader& shader) {
379
                     gl::GLenum mode, ShaderTexture* target, Shader& shader) {
386
-    orAssert(vertices.size() == colors.size());
387
-    if (mode == gl::GL_TRIANGLES)
388
-        orAssert((indices.size() % 3) == 0);
389
     bindProperBuffer(target);
380
     bindProperBuffer(target);
390
 
381
 
391
     shader.use();
382
     shader.use();

Loading…
취소
저장