Quellcode durchsuchen

Fixed window resizing and initial camera offset.

Thomas Buck vor 10 Jahren
Ursprung
Commit
98199883db

+ 3
- 0
ChangeLog.md Datei anzeigen

@@ -9,6 +9,9 @@
9 9
     * Now storing screenshots in PNG format
10 10
     * Updated imgui
11 11
     * Fixed StaticMesh Y-offset (position Y needed to be flipped)
12
+    * Draw Camera position along with view frustum
13
+    * _Fixed_ Camera position Y offset
14
+    * Window resizing working properly again
12 15
 
13 16
     [ 20141228 ]
14 17
     * Room Bounding Boxes are now visualized in Wireframe mode (again).

+ 6
- 4
include/Camera.h Datei anzeigen

@@ -12,22 +12,24 @@
12 12
 #include <glm/vec3.hpp>
13 13
 #include <glm/mat4x4.hpp>
14 14
 #include <glm/gtc/quaternion.hpp>
15
+#include <glm/gtc/type_precision.hpp>
15 16
 
16 17
 #include "RoomData.h"
17 18
 
18 19
 class Camera {
19 20
   public:
20
-
21 21
     static void reset();
22 22
     static bool update();
23
+    static void setSize(glm::i32vec2 s);
23 24
 
24 25
     static void handleAction(ActionEvents action, bool isFinished);
25 26
     static void handleMouseMotion(int x, int y);
26 27
     static void handleControllerAxis(float value, KeyboardButton axis);
27 28
     static void handleControllerButton(KeyboardButton button, bool released);
28 29
 
29
-    static void setPosition(glm::vec3 p) { pos = p; }
30
-    static glm::vec3 getPosition() { return pos; }
30
+    //! \fixme The Y axis seems to be the source of all evil?
31
+    static void setPosition(glm::vec3 p) { pos = glm::vec3(p.x, -p.y, p.z); }
32
+    static glm::vec3 getPosition() { return glm::vec3(pos.x, -pos.y, pos.z); }
31 33
 
32 34
     static glm::vec2 getRotation();
33 35
     static glm::mat4 getProjectionMatrix() { return projection; }
@@ -49,10 +51,10 @@ class Camera {
49 51
     static void calculateFrustumPlanes();
50 52
 
51 53
     static glm::vec3 pos;
54
+    static glm::vec3 drawPos;
52 55
     static glm::quat quaternion;
53 56
     static glm::vec3 posSpeed;
54 57
     static glm::vec2 rotSpeed;
55
-    static glm::vec2 lastSize;
56 58
     static glm::mat4 projection;
57 59
     static glm::mat4 view;
58 60
     static float rotationDeltaX, rotationDeltaY;

+ 5
- 0
include/Log.h Datei anzeigen

@@ -13,6 +13,7 @@
13 13
 #include <vector>
14 14
 #include <glm/vec2.hpp>
15 15
 #include <glm/vec3.hpp>
16
+#include <glm/gtc/type_precision.hpp>
16 17
 
17 18
 class Log {
18 19
   public:
@@ -41,6 +42,10 @@ class Log {
41 42
         return (*this) << v.x << " " << v.y;
42 43
     }
43 44
 
45
+    Log& operator<< (const glm::i32vec2& v) {
46
+        return (*this) << v.x << " " << v.y;
47
+    }
48
+
44 49
     Log& operator<< (const glm::vec3& v) {
45 50
         return (*this) << v.x << " " << v.y << " " << v.z;
46 51
     }

+ 1
- 1
include/Mesh.h Datei anzeigen

@@ -43,7 +43,7 @@ class Mesh {
43 43
          const std::vector<IndexedColoredRectangle>& coloredRectangles,
44 44
          const std::vector<IndexedColoredRectangle>& coloredTriangles);
45 45
     void prepare();
46
-    void display(glm::mat4 model, glm::mat4 view, glm::mat4 projection);
46
+    void display(glm::mat4 MVP);
47 47
 
48 48
   private:
49 49
     std::vector<unsigned short> indices;

+ 2
- 1
include/Render.h Datei anzeigen

@@ -10,13 +10,14 @@
10 10
 #define _RENDER_H_
11 11
 
12 12
 #include <vector>
13
+#include <glm/vec2.hpp>
13 14
 #include <glm/vec4.hpp>
15
+#include <glm/gtc/type_precision.hpp>
14 16
 
15 17
 #include "Room.h"
16 18
 #include "TextureManager.h"
17 19
 
18 20
 enum class RenderMode {
19
-    Disabled,
20 21
     LoadScreen,
21 22
     Solid,
22 23
     Wireframe,

+ 4
- 5
include/Room.h Datei anzeigen

@@ -24,12 +24,10 @@ enum RoomFlags {
24 24
 class Room {
25 25
   public:
26 26
     Room(glm::vec3 _pos, BoundingBox* _bbox, RoomMesh* _mesh, unsigned int f,
27
-         int a, int x, int z)
28
-        : pos(_pos), bbox(_bbox), mesh(_mesh), flags(f), alternateRoom(a),
29
-          numXSectors(x), numZSectors(z) { }
27
+         int a, int x, int z);
30 28
 
31 29
     void prepare() { mesh->prepare(); }
32
-    void display(glm::mat4 view, glm::mat4 projection);
30
+    void display(glm::mat4 VP);
33 31
 
34 32
     bool isWall(unsigned long sector);
35 33
     long getSector(float x, float z, float* floor, float* ceiling);
@@ -68,13 +66,14 @@ class Room {
68 66
 
69 67
   private:
70 68
     glm::vec3 pos;
69
+    glm::mat4 model;
71 70
     std::unique_ptr<BoundingBox> bbox;
72 71
     std::unique_ptr<RoomMesh> mesh;
73 72
 
74 73
     unsigned int flags;
74
+    int alternateRoom;
75 75
     int numXSectors;
76 76
     int numZSectors;
77
-    int alternateRoom;
78 77
 
79 78
     std::vector<std::unique_ptr<Sprite>> sprites;
80 79
     std::vector<std::unique_ptr<StaticModel>> models;

+ 4
- 4
include/RoomData.h Datei anzeigen

@@ -10,6 +10,7 @@
10 10
 
11 11
 #include <memory>
12 12
 #include <vector>
13
+#include <glm/mat4x4.hpp>
13 14
 #include <glm/vec3.hpp>
14 15
 
15 16
 class BoundingBox {
@@ -50,14 +51,13 @@ class BoundingBox {
50 51
 
51 52
 class StaticModel {
52 53
   public:
53
-    StaticModel(glm::vec3 p, float a, int i) : pos(p), angle(a), id(i), cache(-1) { }
54
-    void display(glm::mat4 view, glm::mat4 projection);
54
+    StaticModel(glm::vec3 pos, float angle, int i);
55
+    void display(glm::mat4 VP);
55 56
 
56 57
   private:
57
-    glm::vec3 pos;
58
-    float angle;
59 58
     int id;
60 59
     int cache;
60
+    glm::mat4 model;
61 61
 };
62 62
 
63 63
 // --------------------------------------

+ 1
- 1
include/RoomMesh.h Datei anzeigen

@@ -33,7 +33,7 @@ class RoomMesh {
33 33
              const std::vector<IndexedRectangle>& rectangles,
34 34
              const std::vector<IndexedRectangle>& triangles);
35 35
     void prepare();
36
-    void display(glm::mat4 model, glm::mat4 view, glm::mat4 projection);
36
+    void display(glm::mat4 MVP);
37 37
 
38 38
   private:
39 39
     std::vector<unsigned short> indices;

+ 1
- 1
include/StaticMesh.h Datei anzeigen

@@ -16,7 +16,7 @@ class StaticMesh {
16 16
   public:
17 17
     StaticMesh(int i, int m, BoundingBox* b1, BoundingBox* b2)
18 18
         : id(i), mesh(m), bbox1(b1), bbox2(b2) { }
19
-    void display(glm::mat4 model, glm::mat4 view, glm::mat4 projection);
19
+    void display(glm::mat4 MVP);
20 20
 
21 21
     int getID() { return id; }
22 22
 

+ 3
- 0
include/UI.h Datei anzeigen

@@ -12,6 +12,8 @@
12 12
 #include <list>
13 13
 #include <memory>
14 14
 #include <tuple>
15
+#include <glm/vec2.hpp>
16
+#include <glm/gtc/type_precision.hpp>
15 17
 
16 18
 class ImDrawList;
17 19
 
@@ -21,6 +23,7 @@ class UI {
21 23
     static void eventsFinished();
22 24
     static void display();
23 25
     static void shutdown();
26
+    static void setSize(glm::i32vec2 s);
24 27
 
25 28
     static void setVisible(bool v);
26 29
     static bool isVisible();

+ 3
- 2
include/system/Window.h Datei anzeigen

@@ -13,6 +13,7 @@
13 13
 #include <glm/vec2.hpp>
14 14
 #include <glm/vec3.hpp>
15 15
 #include <glm/vec4.hpp>
16
+#include <glm/gtc/type_precision.hpp>
16 17
 
17 18
 #include "Shader.h"
18 19
 
@@ -23,8 +24,8 @@ class Window {
23 24
     static void swapBuffers();
24 25
     static void shutdown();
25 26
 
26
-    static void setSize(glm::vec2 s);
27
-    static glm::vec2 getSize();
27
+    static void setSize(glm::i32vec2 s);
28
+    static glm::i32vec2 getSize();
28 29
 
29 30
     static void setFullscreen(bool f);
30 31
     static bool getFullscreen();

+ 6
- 3
include/system/WindowGLFW.h Datei anzeigen

@@ -8,6 +8,9 @@
8 8
 #ifndef _WINDOW_GLFW_H_
9 9
 #define _WINDOW_GLFW_H_
10 10
 
11
+#include <glm/vec2.hpp>
12
+#include <glm/gtc/type_precision.hpp>
13
+
11 14
 #include <GLFW/glfw3.h>
12 15
 
13 16
 class WindowGLFW {
@@ -17,8 +20,8 @@ class WindowGLFW {
17 20
     static void swapBuffers();
18 21
     static void shutdown();
19 22
 
20
-    static void setSize(glm::vec2 s);
21
-    static glm::vec2 getSize() { return size; }
23
+    static void setSize(glm::i32vec2 s);
24
+    static glm::i32vec2 getSize() { return size; }
22 25
 
23 26
     static void setFullscreen(bool f);
24 27
     static bool getFullscreen() { return fullscreen; }
@@ -39,7 +42,7 @@ class WindowGLFW {
39 42
 
40 43
     static KeyboardButton convertAsciiButton(int key);
41 44
 
42
-    static glm::vec2 size;
45
+    static glm::i32vec2 size;
43 46
     static bool fullscreen;
44 47
     static bool mousegrab;
45 48
     static bool textinput;

+ 4
- 3
include/system/WindowSDL.h Datei anzeigen

@@ -9,6 +9,7 @@
9 9
 #define _WINDOW_SDL_H_
10 10
 
11 11
 #include <glm/vec2.hpp>
12
+#include <glm/gtc/type_precision.hpp>
12 13
 
13 14
 #include "SDL.h"
14 15
 
@@ -19,8 +20,8 @@ class WindowSDL {
19 20
     static void swapBuffers();
20 21
     static void shutdown();
21 22
 
22
-    static void setSize(glm::vec2 s);
23
-    static glm::vec2 getSize() { return size; }
23
+    static void setSize(glm::i32vec2 s);
24
+    static glm::i32vec2 getSize() { return size; }
24 25
 
25 26
     static void setFullscreen(bool f);
26 27
     static bool getFullscreen() { return fullscreen; }
@@ -32,7 +33,7 @@ class WindowSDL {
32 33
     static bool getTextInput() { return textinput; }
33 34
 
34 35
   private:
35
-    static glm::vec2 size;
36
+    static glm::i32vec2 size;
36 37
     static bool fullscreen;
37 38
     static bool mousegrab;
38 39
     static bool textinput;

+ 20
- 10
src/Camera.cpp Datei anzeigen

@@ -42,10 +42,10 @@ const static glm::vec3 upUnit(0.0f, 1.0f, 0.0f);
42 42
 const static glm::vec3 dirUnit(0.0f, 0.0f, -1.0f);
43 43
 
44 44
 glm::vec3 Camera::pos(0.0f, 0.0f, 0.0f);
45
+glm::vec3 Camera::drawPos(0.0f, 0.0f, 0.0f);
45 46
 glm::quat Camera::quaternion(glm::vec3(0.0f, 0.0f, 0.0f));
46 47
 glm::vec3 Camera::posSpeed(0.0f, 0.0f, 0.0f);
47 48
 glm::vec2 Camera::rotSpeed(0.0f, 0.0f);
48
-glm::vec2 Camera::lastSize(0.0f, 0.0f);
49 49
 glm::mat4 Camera::projection(1.0f);
50 50
 glm::mat4 Camera::view(1.0f);
51 51
 float Camera::rotationDeltaX = 0.75f;
@@ -55,13 +55,20 @@ bool Camera::dirty = true;
55 55
 
56 56
 void Camera::reset() {
57 57
     pos = glm::vec3(0.0f, 0.0f, 0.0f);
58
+    drawPos = glm::vec3(0.0f, 0.0f, 0.0f);
58 59
     quaternion = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
59 60
     posSpeed = glm::vec3(0.0f, 0.0f, 0.0f);
60 61
     rotSpeed = glm::vec2(0.0f, 0.0f);
61 62
     dirty = true;
62
-    lastSize = glm::vec2(0.0f, 0.0f);
63 63
     projection = glm::mat4(1.0f);
64 64
     view = glm::mat4(1.0f);
65
+
66
+    setSize(Window::getSize());
67
+}
68
+
69
+void Camera::setSize(glm::i32vec2 s) {
70
+    //! \fixme TODO instead of mirroring the Y axis in the shader, scale with -1 here
71
+    projection = glm::perspective(fov, float(s.x) / float(s.y), nearDist, farDist);
65 72
 }
66 73
 
67 74
 void Camera::handleAction(ActionEvents action, bool isFinished) {
@@ -150,14 +157,6 @@ void Camera::handleControllerButton(KeyboardButton button, bool released) {
150 157
 }
151 158
 
152 159
 bool Camera::update() {
153
-    glm::vec2 size(Window::getSize());
154
-
155
-    if (lastSize != size) {
156
-        //! \fixme TODO instead of mirroring the Y axis in the shader, scale with -1 here
157
-        projection = glm::perspective(fov, size.x / size.y, nearDist, farDist);
158
-        lastSize = size;
159
-    }
160
-
161 160
     if ((!dirty) && equal(posSpeed, 0.0f) && equal(rotSpeed, 0.0f))
162 161
         return false;
163 162
 
@@ -259,6 +258,8 @@ void Camera::calculateFrustumPlanes() {
259 258
     planes[RIGHT].set(frustumVertices[NBR], frustumVertices[NTR], frustumVertices[FBR]);
260 259
     planes[NEAR].set(frustumVertices[NTL], frustumVertices[NTR], frustumVertices[NBR]);
261 260
     planes[FAR].set(frustumVertices[FTR], frustumVertices[FTL], frustumVertices[FBL]);
261
+
262
+    drawPos = getPosition();
262 263
 }
263 264
 
264 265
 bool Camera::boxInFrustum(BoundingBox b) {
@@ -334,5 +335,14 @@ void Camera::displayFrustum(glm::mat4 MVP) {
334 335
     }
335 336
 
336 337
     Window::drawGL(verts, cols, inds, MVP);
338
+
339
+    verts.clear();
340
+    cols.clear();
341
+    inds.clear();
342
+
343
+    verts.push_back(drawPos);
344
+    cols.push_back(glm::vec3(1.0f, 1.0f, 1.0f));
345
+    inds.push_back(0);
346
+    Window::drawGL(verts, cols, inds, MVP, GL_POINTS);
337 347
 }
338 348
 

+ 1
- 1
src/Game.cpp Datei anzeigen

@@ -116,7 +116,7 @@ int Game::loadLevel(const char* level) {
116 116
             Render::setMode(RenderMode::Texture);
117 117
 
118 118
             Camera::setPosition(glm::vec3(getLara().getPos(0),
119
-                                          getLara().getPos(1) + 1024.0f,
119
+                                          getLara().getPos(1) - 1024.0f,
120 120
                                           getLara().getPos(2)));
121 121
         }
122 122
     } else {

+ 1
- 3
src/Mesh.cpp Datei anzeigen

@@ -120,9 +120,7 @@ void Mesh::prepare() {
120 120
     colors = std::move(col);
121 121
 }
122 122
 
123
-void Mesh::display(glm::mat4 model, glm::mat4 view, glm::mat4 projection) {
124
-    glm::mat4 MVP = projection * view * model;
125
-
123
+void Mesh::display(glm::mat4 MVP) {
126 124
     if (indices.size() > 0) {
127 125
         unsigned int indexStart = 0;
128 126
         unsigned int indexPos = 1;

+ 15
- 25
src/Render.cpp Datei anzeigen

@@ -23,7 +23,7 @@
23 23
 #include "utils/strings.h"
24 24
 #include "Render.h"
25 25
 
26
-RenderMode Render::mode = RenderMode::Disabled;
26
+RenderMode Render::mode = RenderMode::LoadScreen;
27 27
 std::vector<Room*> Render::roomList;
28 28
 bool Render::displayViewFrustum = false;
29 29
 
@@ -34,8 +34,6 @@ RenderMode Render::getMode() {
34 34
 void Render::setMode(RenderMode m) {
35 35
     mode = m;
36 36
     switch (mode) {
37
-        case RenderMode::Disabled:
38
-            break;
39 37
         case RenderMode::Solid:
40 38
         case RenderMode::Wireframe:
41 39
             //glClearColor(PURPLE[0] / 256.0f, PURPLE[1] / 256.0f,
@@ -56,8 +54,6 @@ void Render::display() {
56 54
         drawTexture(0.0f, 0.0f, Window::getSize().x, Window::getSize().y,
57 55
                     color, TEXTURE_SPLASH, TextureManager::TextureStorage::SYSTEM);
58 56
         return;
59
-    } else if (mode == RenderMode::Disabled) {
60
-        return;
61 57
     }
62 58
 
63 59
     if (mode == RenderMode::Wireframe) {
@@ -69,19 +65,18 @@ void Render::display() {
69 65
     if (Camera::update()) {
70 66
         clearRoomList();
71 67
         buildRoomList(-2); // TODO cache room
72
-        std::cout << "Rendering " << roomList.size() << "/"
73
-                  << getWorld().sizeRoom() << " rooms..." << std::endl;
74 68
     }
75 69
 
76 70
     glm::mat4 projection = Camera::getProjectionMatrix();
77 71
     glm::mat4 view = Camera::getViewMatrix();
72
+    glm::mat4 VP = projection * view;
78 73
 
79 74
     for (auto r : roomList) {
80
-        r->display(view, projection);
75
+        r->display(VP);
81 76
     }
82 77
 
83 78
     if (displayViewFrustum)
84
-        Camera::displayFrustum(projection * view);
79
+        Camera::displayFrustum(VP);
85 80
 
86 81
     if (mode == RenderMode::Wireframe) {
87 82
         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
@@ -101,7 +96,6 @@ void Render::buildRoomList(int room) {
101 96
                 return;
102 97
             }
103 98
         }
104
-        std::cout << "Camera not found!" << std::endl;
105 99
         buildRoomList(-1);
106 100
     } else if (room == -1) {
107 101
         // Check visibility for all rooms!
@@ -196,41 +190,37 @@ void Render::drawTexture(float x, float y, float w, float h, glm::vec4 color,
196 190
     Window::drawTextGL(vertices, uvs, color, texture);
197 191
 }
198 192
 
199
-static const int modeStringCount = 5;
193
+static const int modeStringCount = 4;
200 194
 static const char* modeStrings[modeStringCount] = {
201
-    "Disable", "Splash", "Texture", "Wireframe", "Solid"
195
+    "Splash", "Texture", "Wireframe", "Solid"
202 196
 };
203 197
 
204 198
 void Render::displayUI() {
205
-    if (ImGui::CollapsingHeader("Render Settings")) {
199
+    if (ImGui::CollapsingHeader("Render Settings##render")) {
206 200
         int item = 0;
207
-        if (mode == RenderMode::LoadScreen)
201
+        if (mode == RenderMode::Texture)
208 202
             item = 1;
209
-        else if (mode == RenderMode::Texture)
210
-            item = 2;
211 203
         else if (mode == RenderMode::Wireframe)
212
-            item = 3;
204
+            item = 2;
213 205
         else if (mode == RenderMode::Solid)
214
-            item = 4;
206
+            item = 3;
215 207
         if (ImGui::Combo("Mode", &item, modeStrings, modeStringCount)) {
216 208
             if (item == 0)
217
-                mode = RenderMode::Disabled;
218
-            else if (item == 1)
219 209
                 mode = RenderMode::LoadScreen;
220
-            else if (item == 2)
210
+            else if (item == 1)
221 211
                 mode = RenderMode::Texture;
222
-            else if (item == 3)
212
+            else if (item == 2)
223 213
                 mode = RenderMode::Wireframe;
224
-            else if (item == 4)
214
+            else if (item == 3)
225 215
                 mode = RenderMode::Solid;
226 216
         }
227 217
 
228 218
         bool updateViewFrustum = Camera::getUpdateViewFrustum();
229
-        if (ImGui::Checkbox("Update Frustum##runtime", &updateViewFrustum)) {
219
+        if (ImGui::Checkbox("Update Frustum##render", &updateViewFrustum)) {
230 220
             Camera::setUpdateViewFrustum(updateViewFrustum);
231 221
         }
232 222
         ImGui::SameLine();
233
-        ImGui::Checkbox("Show Frustum##runtime", &displayViewFrustum);
223
+        ImGui::Checkbox("Show Frustum##render", &displayViewFrustum);
234 224
     }
235 225
 }
236 226
 

+ 12
- 5
src/Room.cpp Datei anzeigen

@@ -16,16 +16,23 @@
16 16
 #include "Room.h"
17 17
 #include "TextureManager.h"
18 18
 
19
-void Room::display(glm::mat4 view, glm::mat4 projection) {
20
-    glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(pos[0], pos[1], pos[2]));
21
-    mesh->display(model, view, projection);
19
+Room::Room(glm::vec3 _pos, BoundingBox* _bbox, RoomMesh* _mesh, unsigned int f,
20
+           int a, int x, int z) : pos(_pos), bbox(_bbox), mesh(_mesh), flags(f),
21
+                                  alternateRoom(a), numXSectors(x), numZSectors(z) {
22
+    model = glm::translate(glm::mat4(1.0f), pos);
23
+}
24
+
25
+void Room::display(glm::mat4 VP) {
26
+    glm::mat4 MVP = VP * model;
27
+
28
+    mesh->display(MVP);
22 29
 
23 30
     for (auto& m : models) {
24
-        m->display(view, projection);
31
+        m->display(VP);
25 32
     }
26 33
 
27 34
     if (Render::getMode() == RenderMode::Wireframe)
28
-        bbox->display(projection * view, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 1.0f));
35
+        bbox->display(VP, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 1.0f));
29 36
 }
30 37
 
31 38
 bool Room::isWall(unsigned long sector) {

+ 8
- 5
src/RoomData.cpp Datei anzeigen

@@ -55,7 +55,13 @@ void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot)
55 55
 
56 56
 // ----------------------------------------------------------------------------
57 57
 
58
-void StaticModel::display(glm::mat4 view, glm::mat4 projection) {
58
+StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {
59
+    glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z));
60
+    glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 1.0f, 0.0f));
61
+    model = translate * rotate;
62
+}
63
+
64
+void StaticModel::display(glm::mat4 VP) {
59 65
     if (cache < 0) {
60 66
         for (int i = 0; i < getWorld().sizeStaticMesh(); i++) {
61 67
             if (getWorld().getStaticMesh(i).getID() == id) {
@@ -65,10 +71,7 @@ void StaticModel::display(glm::mat4 view, glm::mat4 projection) {
65 71
         assert(cache >= 0);
66 72
     }
67 73
 
68
-    glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z));
69
-    glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 1.0f, 0.0f));
70
-    glm::mat4 model = translate * rotate;
71
-    getWorld().getStaticMesh(cache).display(model, view, projection);
74
+    getWorld().getStaticMesh(cache).display(VP * model);
72 75
 }
73 76
 
74 77
 // ----------------------------------------------------------------------------

+ 1
- 3
src/RoomMesh.cpp Datei anzeigen

@@ -72,9 +72,7 @@ void RoomMesh::prepare() {
72 72
     textures = std::move(tex);
73 73
 }
74 74
 
75
-void RoomMesh::display(glm::mat4 model, glm::mat4 view, glm::mat4 projection) {
76
-    glm::mat4 MVP = projection * view * model;
77
-
75
+void RoomMesh::display(glm::mat4 MVP) {
78 76
     if (indices.size() > 0) {
79 77
         unsigned int indexStart = 0;
80 78
         unsigned int indexPos = 1;

+ 4
- 6
src/StaticMesh.cpp Datei anzeigen

@@ -10,14 +10,12 @@
10 10
 #include "World.h"
11 11
 #include "StaticMesh.h"
12 12
 
13
-void StaticMesh::display(glm::mat4 model, glm::mat4 view, glm::mat4 projection) {
14
-    getWorld().getMesh(mesh).display(model, view, projection);
13
+void StaticMesh::display(glm::mat4 MVP) {
14
+    getWorld().getMesh(mesh).display(MVP);
15 15
 
16 16
     if (Render::getMode() == RenderMode::Wireframe) {
17
-        bbox1->display(projection * view * model,
18
-                       glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
19
-        bbox2->display(projection * view * model,
20
-                       glm::vec3(1.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, 1.0f));
17
+        bbox1->display(MVP, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
18
+        bbox2->display(MVP, glm::vec3(1.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, 1.0f));
21 19
     }
22 20
 }
23 21
 

+ 5
- 0
src/UI.cpp Datei anzeigen

@@ -39,6 +39,11 @@ std::list<std::tuple<unsigned int, unsigned int, KeyboardButton, bool>> UI::clic
39 39
 std::list<std::tuple<int, int, int, int>> UI::motionEvents;
40 40
 std::list<std::tuple<int, int>> UI::scrollEvents;
41 41
 
42
+void UI::setSize(glm::i32vec2 s) {
43
+    ImGuiIO& io = ImGui::GetIO();
44
+    io.DisplaySize = ImVec2(s.x, s.y);
45
+}
46
+
42 47
 int UI::initialize() {
43 48
     iniFilename = RunTime::getBaseDir() + "/imgui.ini";
44 49
     logFilename = RunTime::getBaseDir() + "/imgui_log.txt";

+ 0
- 10
src/commands/CommandRender.cpp Datei anzeigen

@@ -6,7 +6,6 @@
6 6
  */
7 7
 
8 8
 #include "global.h"
9
-#include "Game.h"
10 9
 #include "Log.h"
11 10
 #include "Render.h"
12 11
 #include "commands/CommandRender.h"
@@ -27,16 +26,10 @@ void CommandMode::printHelp() {
27 26
     getLog() << "  solid" << Log::endl;
28 27
     getLog() << "  texture" << Log::endl;
29 28
     getLog() << "  titlescreen" << Log::endl;
30
-    getLog() << "  disabled" << Log::endl;
31 29
 
32 30
 }
33 31
 
34 32
 int CommandMode::execute(std::istream& args) {
35
-    if (!getGame().isLoaded()) {
36
-        getLog() << "Load a level to set the mode!" << Log::endl;
37
-        return -1;
38
-    }
39
-
40 33
     std::string s;
41 34
     args >> s;
42 35
 
@@ -52,9 +45,6 @@ int CommandMode::execute(std::istream& args) {
52 45
     } else if (s == "titlescreen") {
53 46
         Render::setMode(RenderMode::LoadScreen);
54 47
         getLog() << "Titlescreen mode" << Log::endl;
55
-    } else if (s == "disabled") {
56
-        Render::setMode(RenderMode::Disabled);
57
-        getLog() << "Disabled mode" << Log::endl;
58 48
     } else {
59 49
         getLog() << "Invalid use of mode command (" << s << ")!" << Log::endl;
60 50
         return -2;

+ 2
- 0
src/main.cpp Datei anzeigen

@@ -9,6 +9,7 @@
9 9
 #include <memory>
10 10
 
11 11
 #include "global.h"
12
+#include "Camera.h"
12 13
 #include "Exception.h"
13 14
 #include "Game.h"
14 15
 #include "Log.h"
@@ -139,6 +140,7 @@ int main(int argc, char* argv[]) {
139 140
     }
140 141
 
141 142
     getLog() << "Starting " << VERSION << Log::endl;
143
+    Camera::setSize(Window::getSize());
142 144
     getMenu().setVisible(true);
143 145
     systemTimerReset();
144 146
     RunTime::setRunning(true);

+ 9
- 3
src/system/Window.cpp Datei anzeigen

@@ -6,7 +6,9 @@
6 6
  */
7 7
 
8 8
 #include "global.h"
9
+#include "Camera.h"
9 10
 #include "Log.h"
11
+#include "UI.h"
10 12
 #include "utils/strings.h"
11 13
 #include "system/Window.h"
12 14
 
@@ -58,16 +60,20 @@ void Window::shutdown() {
58 60
 #endif
59 61
 }
60 62
 
61
-void Window::setSize(glm::vec2 s) {
63
+void Window::setSize(glm::i32vec2 s) {
62 64
 #ifdef USING_SDL
63 65
     WindowSDL::setSize(s);
64 66
 #elif defined(USING_GLFW)
65 67
     WindowGLFW::setSize(s);
66 68
 #endif
69
+
70
+    UI::setSize(s);
71
+    Camera::setSize(s);
72
+    glViewport(0, 0, s.x, s.y);
67 73
 }
68 74
 
69
-glm::vec2 Window::getSize() {
70
-    glm::vec2 ret(-1, -1);
75
+glm::i32vec2 Window::getSize() {
76
+    glm::i32vec2 ret(-1, -1);
71 77
 #ifdef USING_SDL
72 78
     ret = WindowSDL::getSize();
73 79
 #elif defined(USING_GLFW)

+ 5
- 3
src/system/WindowGLFW.cpp Datei anzeigen

@@ -11,10 +11,11 @@
11 11
 #include "Log.h"
12 12
 #include "RunTime.h"
13 13
 #include "UI.h"
14
+#include "system/Window.h"
14 15
 #include "utils/strings.h"
15 16
 #include "system/WindowGLFW.h"
16 17
 
17
-glm::vec2 WindowGLFW::size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
18
+glm::i32vec2 WindowGLFW::size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
18 19
 bool WindowGLFW::fullscreen = false;
19 20
 bool WindowGLFW::mousegrab = false;
20 21
 bool WindowGLFW::textinput = false;
@@ -78,7 +79,7 @@ void WindowGLFW::shutdown() {
78 79
     }
79 80
 }
80 81
 
81
-void WindowGLFW::setSize(glm::vec2 s) {
82
+void WindowGLFW::setSize(glm::i32vec2 s) {
82 83
     assert((s.x > 0) && (s.y > 0));
83 84
     if (window) {
84 85
         if ((size.x != s.x) || (size.y != s.y)) {
@@ -113,7 +114,8 @@ void WindowGLFW::errorCallback(int error, const char* desc) {
113 114
 }
114 115
 
115 116
 void WindowGLFW::sizeCallback(GLFWwindow* w, int width, int height) {
116
-    size = glm::vec2(width, height);
117
+    size = glm::i32vec2(width, height);
118
+    Window::setSize(size);
117 119
 }
118 120
 
119 121
 void WindowGLFW::cursorCallback(GLFWwindow* w, double xpos, double ypos) {

+ 12
- 7
src/system/WindowSDL.cpp Datei anzeigen

@@ -11,12 +11,13 @@
11 11
 #include "Log.h"
12 12
 #include "RunTime.h"
13 13
 #include "UI.h"
14
+#include "system/Window.h"
14 15
 #include "utils/strings.h"
15 16
 #include "system/WindowSDL.h"
16 17
 
17 18
 #define SUBSYSTEMS_USED (SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER)
18 19
 
19
-glm::vec2 WindowSDL::size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
20
+glm::i32vec2 WindowSDL::size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
20 21
 bool WindowSDL::fullscreen = false;
21 22
 bool WindowSDL::mousegrab = false;
22 23
 bool WindowSDL::textinput = false;
@@ -457,8 +458,10 @@ void WindowSDL::eventHandling() {
457 458
                 break;
458 459
 
459 460
             case SDL_WINDOWEVENT:
460
-                if (event.window.event == SDL_WINDOWEVENT_RESIZED)
461
-                    setSize(glm::vec2(event.window.data1, event.window.data2));
461
+                if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
462
+                    size = glm::i32vec2(event.window.data1, event.window.data2);
463
+                    Window::setSize(size);
464
+                }
462 465
                 break;
463 466
 
464 467
             case SDL_QUIT:
@@ -493,12 +496,14 @@ void WindowSDL::shutdown() {
493 496
     }
494 497
 }
495 498
 
496
-void WindowSDL::setSize(glm::vec2 s) {
499
+void WindowSDL::setSize(glm::i32vec2 s) {
497 500
     assert((s.x > 0) && (s.y > 0));
498
-
501
+    if (window) {
502
+        if ((s.x != size.x) || (s.y != size.y)) {
503
+            SDL_SetWindowSize(window, size.x, size.y);
504
+        }
505
+    }
499 506
     size = s;
500
-    if (window)
501
-        SDL_SetWindowSize(window, size.x, size.y);
502 507
 }
503 508
 
504 509
 void WindowSDL::setFullscreen(bool f) {

Laden…
Abbrechen
Speichern