소스 검색

Room Mesh displayed more or less correctly

Thomas Buck 10 년 전
부모
커밋
014962658a
8개의 변경된 파일74개의 추가작업 그리고 31개의 파일을 삭제
  1. 1
    1
      ChangeLog.md
  2. 1
    0
      include/Camera.h
  3. 3
    2
      include/TextureManager.h
  4. 16
    14
      src/Camera.cpp
  5. 4
    0
      src/Game.cpp
  6. 20
    4
      src/Mesh.cpp
  7. 22
    8
      src/Render.cpp
  8. 7
    2
      src/system/Window.cpp

+ 1
- 1
ChangeLog.md 파일 보기

@@ -4,7 +4,7 @@
4 4
 
5 5
     [ 20141216 ]
6 6
     * Allow navigation with a free-floating Camera
7
-    * Started drawing the Room Mesh structures
7
+    * Room Meshes are displayed more or less correctly
8 8
 
9 9
     [ 20141215 ]
10 10
     * Rewrote GL code for the Font implementations, ImGUI and the Main Menu

+ 1
- 0
include/Camera.h 파일 보기

@@ -22,6 +22,7 @@ class Camera {
22 22
 
23 23
     static float getRadianPitch() { return thetaX; }
24 24
     static float getRadianYaw() { return thetaY; }
25
+    static void setRadianPitch(float x) { thetaX = x; }
25 26
 
26 27
     static void setPosition(glm::vec3 p) { pos = p; }
27 28
     static glm::vec3 getPosition() { return pos; }

+ 3
- 2
include/TextureManager.h 파일 보기

@@ -29,10 +29,11 @@ class TextureTileVertex {
29 29
 class TextureTile {
30 30
   public:
31 31
     TextureTile(unsigned int a, unsigned int t) : attribute(a), texture(t) { }
32
+    void add(TextureTileVertex t) { vertices.push_back(t); }
32 33
 
33 34
     unsigned int getTexture() { return texture; }
34
-    glm::vec2 getUV(unsigned int i) { return glm::vec2(vertices.at(i).xPixel, vertices.at(i).yPixel); }
35
-    void add(TextureTileVertex t) { vertices.push_back(t); }
35
+    glm::vec2 getUV(unsigned int i) { return glm::vec2(vertices.at(i).xPixel / 255.0f,
36
+                                                       vertices.at(i).yPixel / 255.0f); }
36 37
 
37 38
   private:
38 39
     unsigned int attribute;

+ 16
- 14
src/Camera.cpp 파일 보기

@@ -12,14 +12,14 @@
12 12
 #include "Camera.h"
13 13
 
14 14
 glm::vec3 Camera::pos(0.0f, 0.0f, 0.0f);
15
-float Camera::thetaX = glm::pi<float>();
15
+float Camera::thetaX = 0.0f;
16 16
 float Camera::thetaY = 0.0f;
17 17
 float Camera::rotationDeltaX = 0.75f;
18 18
 float Camera::rotationDeltaY = 0.75f;
19 19
 
20 20
 void Camera::reset() {
21 21
     pos = glm::vec3(0.0f, 0.0f, 0.0f);
22
-    thetaX = glm::pi<float>();
22
+    thetaX = 0.0f;
23 23
     thetaY = 0.0f;
24 24
 }
25 25
 
@@ -46,9 +46,9 @@ void Camera::handleAction(ActionEvents action, bool isFinished) {
46 46
     } else if (action == backwardAction) {
47 47
         pos -= dir * step;
48 48
     } else if (action == leftAction) {
49
-        pos -= right * step;
50
-    } else if (action == rightAction) {
51 49
         pos += right * step;
50
+    } else if (action == rightAction) {
51
+        pos -= right * step;
52 52
     } else if (action == jumpAction) {
53 53
         pos += up * step;
54 54
     } else if (action == crouchAction) {
@@ -61,29 +61,31 @@ void Camera::handleAction(ActionEvents action, bool isFinished) {
61 61
 
62 62
 void Camera::handleMouseMotion(int x, int y) {
63 63
     while (x > 0) {
64
-        if (thetaX < (glm::pi<float>() / 2.0f)) {
65
-            thetaX += rotationDeltaX;
66
-        }
64
+        thetaX += rotationDeltaX;
67 65
         x--;
68 66
     }
69 67
     while (x < 0) {
70
-        if (thetaX > -(glm::pi<float>() / 2.0f)) {
71
-            thetaX -= rotationDeltaX;
72
-        }
68
+        thetaX -= rotationDeltaX;
73 69
         x++;
74 70
     }
75 71
     while (y > 0) {
76
-        if (thetaY < (glm::pi<float>() / 2.0f)) {
77
-            thetaY += rotationDeltaY;
72
+        if (thetaY > -(glm::pi<float>() / 2.0f)) {
73
+            thetaY -= rotationDeltaY;
78 74
         }
79 75
         y--;
80 76
     }
81 77
     while (y < 0) {
82
-        if (thetaY > -(glm::pi<float>() / 2.0f)) {
83
-            thetaY -= rotationDeltaY;
78
+        if (thetaY < (glm::pi<float>() / 2.0f)) {
79
+            thetaY += rotationDeltaY;
84 80
         }
85 81
         y++;
86 82
     }
83
+
84
+    while (thetaX > (glm::pi<float>() * 2.0f))
85
+        thetaX -= glm::pi<float>() * 2.0f;
86
+
87
+    while (thetaX < -(glm::pi<float>() * 2.0f))
88
+        thetaX += glm::pi<float>() * 2.0f;
87 89
 }
88 90
 
89 91
 glm::mat4 Camera::getViewMatrix() {

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

@@ -105,6 +105,10 @@ int Game::loadLevel(const char* level) {
105 105
         } else {
106 106
             mLoaded = true;
107 107
             Render::setMode(RenderMode::Texture);
108
+
109
+            Camera::setPosition(glm::vec3(getLara().getPos(0),
110
+                                          getLara().getPos(1) + 1024.0f,
111
+                                          getLara().getPos(2)));
108 112
         }
109 113
     } else {
110 114
         getLog() << "No suitable loader for this level!" << Log::endl;

+ 20
- 4
src/Mesh.cpp 파일 보기

@@ -81,8 +81,8 @@ void Mesh::prepare() {
81 81
         }
82 82
 
83 83
         if (indices.at(i) == 0) {
84
-            ind.push_back(ind.at(ind.size() - 1));
85
-            ind.push_back(ind.at(ind.size() - 3));
84
+            ind.push_back(ind.at(ind.size() - 2));
85
+            ind.push_back(ind.at(ind.size() - 5));
86 86
         }
87 87
 
88 88
         vertIndex += (indices.at(i) == 0) ? 4 : 3;
@@ -91,13 +91,29 @@ void Mesh::prepare() {
91 91
     indices = ind;
92 92
     vertices = vert;
93 93
     textures = tex;
94
+
95
+    assert((indices.size() % 3) == 0);
94 96
 }
95 97
 
96 98
 void Mesh::display(glm::mat4 model, glm::mat4 view, glm::mat4 projection) {
97 99
     glm::mat4 MVP = projection * view * model;
98 100
 
99
-    // TODO handle different textures!
101
+    unsigned int indexStart = 0;
102
+    unsigned int indexPos = 1;
103
+    unsigned int texture = textures.at(indices.at(0));
104
+
105
+    while ((indexStart != indexPos) && (indexPos < indices.size())) {
106
+        while ((indexPos < indices.size()) && (textures.at(indices.at(indexPos)) == texture))
107
+            indexPos++;
108
+
109
+        std::vector<unsigned short> ind(indices.begin() + indexStart, indices.begin() + indexPos);
110
+        Window::drawGL(vertices, uvs, ind, MVP, texture);
100 111
 
101
-    Window::drawGL(vertices, uvs, indices, MVP, textures.at(0));
112
+        if (indexPos < indices.size()) {
113
+            indexStart = indexPos;
114
+            indexPos += 1;
115
+            texture = textures.at(indices.at(indexStart));
116
+        }
117
+    }
102 118
 }
103 119
 

+ 22
- 8
src/Render.cpp 파일 보기

@@ -36,14 +36,15 @@ void Render::setMode(RenderMode m) {
36 36
             break;
37 37
         case RenderMode::Solid:
38 38
         case RenderMode::Wireframe:
39
-            glClearColor(PURPLE[0] / 256.0f, PURPLE[1] / 256.0f,
40
-                         PURPLE[2] / 256.0f, PURPLE[3] / 256.0f);
39
+            //glClearColor(PURPLE[0] / 256.0f, PURPLE[1] / 256.0f,
40
+            //             PURPLE[2] / 256.0f, PURPLE[3] / 256.0f);
41 41
             //glDisable(GL_TEXTURE_2D);
42 42
             break;
43 43
         default:
44
-            glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f,
45
-                         BLACK[2] / 256.0f, BLACK[3] / 256.0f);
44
+            //glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f,
45
+            //             BLACK[2] / 256.0f, BLACK[3] / 256.0f);
46 46
             //glEnable(GL_TEXTURE_2D);
47
+            break;
47 48
     }
48 49
 }
49 50
 
@@ -66,10 +67,23 @@ void Render::display() {
66 67
     }
67 68
 
68 69
     glm::mat4 view = Camera::getViewMatrix();
69
-    glm::mat4 projection = glm::perspective(45.0f, // Field of View
70
-                                            (float)getWindow().getWidth() / (float)getWindow().getHeight(),
71
-                                            0.1f, // Min Distance
72
-                                            100000.0f); // Max Distance
70
+
71
+    static unsigned int w = getWindow().getWidth();
72
+    static unsigned int h = getWindow().getHeight();
73
+    static glm::mat4 projection = glm::perspective(45.0f, // Field of View
74
+                                                   (float)getWindow().getWidth()
75
+                                                 / (float)getWindow().getHeight(),
76
+                                                   0.1f, // Min Distance
77
+                                                   100000.0f); // Max Distance
78
+
79
+    if ((w != getWindow().getWidth()) || (h != getWindow().getHeight())) {
80
+        w = getWindow().getWidth();
81
+        h = getWindow().getHeight();
82
+        glm::mat4 projection = glm::perspective(45.0f, // Field of View
83
+                                                (float)getWindow().getWidth() / (float)getWindow().getHeight(),
84
+                                                0.1f, // Min Distance
85
+                                                100000.0f); // Max Distance
86
+    }
73 87
 
74 88
     // Just draw all rooms, as a test
75 89
     for (int i = 0; i < getWorld().sizeRoom(); i++)

+ 7
- 2
src/system/Window.cpp 파일 보기

@@ -48,7 +48,8 @@ int Window::initializeGL() {
48 48
 	glBindVertexArray(vertexArrayID);
49 49
 
50 50
     // Set background to black
51
-    glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
51
+    //glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
52
+    glClearColor(0.0f, 0.0f, 0.4f, 1.0f);
52 53
 
53 54
     // Set up Z buffer
54 55
     glEnable(GL_DEPTH_TEST);
@@ -377,7 +378,11 @@ out vec2 UV;
377 378
 uniform mat4 MVP;
378 379
 
379 380
 void main() {
380
-    gl_Position = MVP * vec4(vertexPosition_modelspace, 1);
381
+    vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
382
+                          -vertexPosition_modelspace.y,
383
+                          vertexPosition_modelspace.z,
384
+                          1);
385
+    gl_Position = vec4(-pos.x, pos.yzw);
381 386
     UV = vertexUV;
382 387
 }
383 388
 )!?!";

Loading…
취소
저장