Browse Source

Fixed window resizing and initial camera offset.

Thomas Buck 10 years ago
parent
commit
98199883db

+ 3
- 0
ChangeLog.md View File

9
     * Now storing screenshots in PNG format
9
     * Now storing screenshots in PNG format
10
     * Updated imgui
10
     * Updated imgui
11
     * Fixed StaticMesh Y-offset (position Y needed to be flipped)
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
     [ 20141228 ]
16
     [ 20141228 ]
14
     * Room Bounding Boxes are now visualized in Wireframe mode (again).
17
     * Room Bounding Boxes are now visualized in Wireframe mode (again).

+ 6
- 4
include/Camera.h View File

12
 #include <glm/vec3.hpp>
12
 #include <glm/vec3.hpp>
13
 #include <glm/mat4x4.hpp>
13
 #include <glm/mat4x4.hpp>
14
 #include <glm/gtc/quaternion.hpp>
14
 #include <glm/gtc/quaternion.hpp>
15
+#include <glm/gtc/type_precision.hpp>
15
 
16
 
16
 #include "RoomData.h"
17
 #include "RoomData.h"
17
 
18
 
18
 class Camera {
19
 class Camera {
19
   public:
20
   public:
20
-
21
     static void reset();
21
     static void reset();
22
     static bool update();
22
     static bool update();
23
+    static void setSize(glm::i32vec2 s);
23
 
24
 
24
     static void handleAction(ActionEvents action, bool isFinished);
25
     static void handleAction(ActionEvents action, bool isFinished);
25
     static void handleMouseMotion(int x, int y);
26
     static void handleMouseMotion(int x, int y);
26
     static void handleControllerAxis(float value, KeyboardButton axis);
27
     static void handleControllerAxis(float value, KeyboardButton axis);
27
     static void handleControllerButton(KeyboardButton button, bool released);
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
     static glm::vec2 getRotation();
34
     static glm::vec2 getRotation();
33
     static glm::mat4 getProjectionMatrix() { return projection; }
35
     static glm::mat4 getProjectionMatrix() { return projection; }
49
     static void calculateFrustumPlanes();
51
     static void calculateFrustumPlanes();
50
 
52
 
51
     static glm::vec3 pos;
53
     static glm::vec3 pos;
54
+    static glm::vec3 drawPos;
52
     static glm::quat quaternion;
55
     static glm::quat quaternion;
53
     static glm::vec3 posSpeed;
56
     static glm::vec3 posSpeed;
54
     static glm::vec2 rotSpeed;
57
     static glm::vec2 rotSpeed;
55
-    static glm::vec2 lastSize;
56
     static glm::mat4 projection;
58
     static glm::mat4 projection;
57
     static glm::mat4 view;
59
     static glm::mat4 view;
58
     static float rotationDeltaX, rotationDeltaY;
60
     static float rotationDeltaX, rotationDeltaY;

+ 5
- 0
include/Log.h View File

13
 #include <vector>
13
 #include <vector>
14
 #include <glm/vec2.hpp>
14
 #include <glm/vec2.hpp>
15
 #include <glm/vec3.hpp>
15
 #include <glm/vec3.hpp>
16
+#include <glm/gtc/type_precision.hpp>
16
 
17
 
17
 class Log {
18
 class Log {
18
   public:
19
   public:
41
         return (*this) << v.x << " " << v.y;
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
     Log& operator<< (const glm::vec3& v) {
49
     Log& operator<< (const glm::vec3& v) {
45
         return (*this) << v.x << " " << v.y << " " << v.z;
50
         return (*this) << v.x << " " << v.y << " " << v.z;
46
     }
51
     }

+ 1
- 1
include/Mesh.h View File

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

+ 2
- 1
include/Render.h View File

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

+ 4
- 5
include/Room.h View File

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

+ 4
- 4
include/RoomData.h View File

10
 
10
 
11
 #include <memory>
11
 #include <memory>
12
 #include <vector>
12
 #include <vector>
13
+#include <glm/mat4x4.hpp>
13
 #include <glm/vec3.hpp>
14
 #include <glm/vec3.hpp>
14
 
15
 
15
 class BoundingBox {
16
 class BoundingBox {
50
 
51
 
51
 class StaticModel {
52
 class StaticModel {
52
   public:
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
   private:
57
   private:
57
-    glm::vec3 pos;
58
-    float angle;
59
     int id;
58
     int id;
60
     int cache;
59
     int cache;
60
+    glm::mat4 model;
61
 };
61
 };
62
 
62
 
63
 // --------------------------------------
63
 // --------------------------------------

+ 1
- 1
include/RoomMesh.h View File

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

+ 1
- 1
include/StaticMesh.h View File

16
   public:
16
   public:
17
     StaticMesh(int i, int m, BoundingBox* b1, BoundingBox* b2)
17
     StaticMesh(int i, int m, BoundingBox* b1, BoundingBox* b2)
18
         : id(i), mesh(m), bbox1(b1), bbox2(b2) { }
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
     int getID() { return id; }
21
     int getID() { return id; }
22
 
22
 

+ 3
- 0
include/UI.h View File

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

+ 3
- 2
include/system/Window.h View File

13
 #include <glm/vec2.hpp>
13
 #include <glm/vec2.hpp>
14
 #include <glm/vec3.hpp>
14
 #include <glm/vec3.hpp>
15
 #include <glm/vec4.hpp>
15
 #include <glm/vec4.hpp>
16
+#include <glm/gtc/type_precision.hpp>
16
 
17
 
17
 #include "Shader.h"
18
 #include "Shader.h"
18
 
19
 
23
     static void swapBuffers();
24
     static void swapBuffers();
24
     static void shutdown();
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
     static void setFullscreen(bool f);
30
     static void setFullscreen(bool f);
30
     static bool getFullscreen();
31
     static bool getFullscreen();

+ 6
- 3
include/system/WindowGLFW.h View File

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

+ 4
- 3
include/system/WindowSDL.h View File

9
 #define _WINDOW_SDL_H_
9
 #define _WINDOW_SDL_H_
10
 
10
 
11
 #include <glm/vec2.hpp>
11
 #include <glm/vec2.hpp>
12
+#include <glm/gtc/type_precision.hpp>
12
 
13
 
13
 #include "SDL.h"
14
 #include "SDL.h"
14
 
15
 
19
     static void swapBuffers();
20
     static void swapBuffers();
20
     static void shutdown();
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
     static void setFullscreen(bool f);
26
     static void setFullscreen(bool f);
26
     static bool getFullscreen() { return fullscreen; }
27
     static bool getFullscreen() { return fullscreen; }
32
     static bool getTextInput() { return textinput; }
33
     static bool getTextInput() { return textinput; }
33
 
34
 
34
   private:
35
   private:
35
-    static glm::vec2 size;
36
+    static glm::i32vec2 size;
36
     static bool fullscreen;
37
     static bool fullscreen;
37
     static bool mousegrab;
38
     static bool mousegrab;
38
     static bool textinput;
39
     static bool textinput;

+ 20
- 10
src/Camera.cpp View File

42
 const static glm::vec3 dirUnit(0.0f, 0.0f, -1.0f);
42
 const static glm::vec3 dirUnit(0.0f, 0.0f, -1.0f);
43
 
43
 
44
 glm::vec3 Camera::pos(0.0f, 0.0f, 0.0f);
44
 glm::vec3 Camera::pos(0.0f, 0.0f, 0.0f);
45
+glm::vec3 Camera::drawPos(0.0f, 0.0f, 0.0f);
45
 glm::quat Camera::quaternion(glm::vec3(0.0f, 0.0f, 0.0f));
46
 glm::quat Camera::quaternion(glm::vec3(0.0f, 0.0f, 0.0f));
46
 glm::vec3 Camera::posSpeed(0.0f, 0.0f, 0.0f);
47
 glm::vec3 Camera::posSpeed(0.0f, 0.0f, 0.0f);
47
 glm::vec2 Camera::rotSpeed(0.0f, 0.0f);
48
 glm::vec2 Camera::rotSpeed(0.0f, 0.0f);
48
-glm::vec2 Camera::lastSize(0.0f, 0.0f);
49
 glm::mat4 Camera::projection(1.0f);
49
 glm::mat4 Camera::projection(1.0f);
50
 glm::mat4 Camera::view(1.0f);
50
 glm::mat4 Camera::view(1.0f);
51
 float Camera::rotationDeltaX = 0.75f;
51
 float Camera::rotationDeltaX = 0.75f;
55
 
55
 
56
 void Camera::reset() {
56
 void Camera::reset() {
57
     pos = glm::vec3(0.0f, 0.0f, 0.0f);
57
     pos = glm::vec3(0.0f, 0.0f, 0.0f);
58
+    drawPos = glm::vec3(0.0f, 0.0f, 0.0f);
58
     quaternion = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
59
     quaternion = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
59
     posSpeed = glm::vec3(0.0f, 0.0f, 0.0f);
60
     posSpeed = glm::vec3(0.0f, 0.0f, 0.0f);
60
     rotSpeed = glm::vec2(0.0f, 0.0f);
61
     rotSpeed = glm::vec2(0.0f, 0.0f);
61
     dirty = true;
62
     dirty = true;
62
-    lastSize = glm::vec2(0.0f, 0.0f);
63
     projection = glm::mat4(1.0f);
63
     projection = glm::mat4(1.0f);
64
     view = glm::mat4(1.0f);
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
 void Camera::handleAction(ActionEvents action, bool isFinished) {
74
 void Camera::handleAction(ActionEvents action, bool isFinished) {
150
 }
157
 }
151
 
158
 
152
 bool Camera::update() {
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
     if ((!dirty) && equal(posSpeed, 0.0f) && equal(rotSpeed, 0.0f))
160
     if ((!dirty) && equal(posSpeed, 0.0f) && equal(rotSpeed, 0.0f))
162
         return false;
161
         return false;
163
 
162
 
259
     planes[RIGHT].set(frustumVertices[NBR], frustumVertices[NTR], frustumVertices[FBR]);
258
     planes[RIGHT].set(frustumVertices[NBR], frustumVertices[NTR], frustumVertices[FBR]);
260
     planes[NEAR].set(frustumVertices[NTL], frustumVertices[NTR], frustumVertices[NBR]);
259
     planes[NEAR].set(frustumVertices[NTL], frustumVertices[NTR], frustumVertices[NBR]);
261
     planes[FAR].set(frustumVertices[FTR], frustumVertices[FTL], frustumVertices[FBL]);
260
     planes[FAR].set(frustumVertices[FTR], frustumVertices[FTL], frustumVertices[FBL]);
261
+
262
+    drawPos = getPosition();
262
 }
263
 }
263
 
264
 
264
 bool Camera::boxInFrustum(BoundingBox b) {
265
 bool Camera::boxInFrustum(BoundingBox b) {
334
     }
335
     }
335
 
336
 
336
     Window::drawGL(verts, cols, inds, MVP);
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 View File

116
             Render::setMode(RenderMode::Texture);
116
             Render::setMode(RenderMode::Texture);
117
 
117
 
118
             Camera::setPosition(glm::vec3(getLara().getPos(0),
118
             Camera::setPosition(glm::vec3(getLara().getPos(0),
119
-                                          getLara().getPos(1) + 1024.0f,
119
+                                          getLara().getPos(1) - 1024.0f,
120
                                           getLara().getPos(2)));
120
                                           getLara().getPos(2)));
121
         }
121
         }
122
     } else {
122
     } else {

+ 1
- 3
src/Mesh.cpp View File

120
     colors = std::move(col);
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
     if (indices.size() > 0) {
124
     if (indices.size() > 0) {
127
         unsigned int indexStart = 0;
125
         unsigned int indexStart = 0;
128
         unsigned int indexPos = 1;
126
         unsigned int indexPos = 1;

+ 15
- 25
src/Render.cpp View File

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

16
 #include "Room.h"
16
 #include "Room.h"
17
 #include "TextureManager.h"
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
     for (auto& m : models) {
30
     for (auto& m : models) {
24
-        m->display(view, projection);
31
+        m->display(VP);
25
     }
32
     }
26
 
33
 
27
     if (Render::getMode() == RenderMode::Wireframe)
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
 bool Room::isWall(unsigned long sector) {
38
 bool Room::isWall(unsigned long sector) {

+ 8
- 5
src/RoomData.cpp View File

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
     if (cache < 0) {
65
     if (cache < 0) {
60
         for (int i = 0; i < getWorld().sizeStaticMesh(); i++) {
66
         for (int i = 0; i < getWorld().sizeStaticMesh(); i++) {
61
             if (getWorld().getStaticMesh(i).getID() == id) {
67
             if (getWorld().getStaticMesh(i).getID() == id) {
65
         assert(cache >= 0);
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 View File

72
     textures = std::move(tex);
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
     if (indices.size() > 0) {
76
     if (indices.size() > 0) {
79
         unsigned int indexStart = 0;
77
         unsigned int indexStart = 0;
80
         unsigned int indexPos = 1;
78
         unsigned int indexPos = 1;

+ 4
- 6
src/StaticMesh.cpp View File

10
 #include "World.h"
10
 #include "World.h"
11
 #include "StaticMesh.h"
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
     if (Render::getMode() == RenderMode::Wireframe) {
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 View File

39
 std::list<std::tuple<int, int, int, int>> UI::motionEvents;
39
 std::list<std::tuple<int, int, int, int>> UI::motionEvents;
40
 std::list<std::tuple<int, int>> UI::scrollEvents;
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
 int UI::initialize() {
47
 int UI::initialize() {
43
     iniFilename = RunTime::getBaseDir() + "/imgui.ini";
48
     iniFilename = RunTime::getBaseDir() + "/imgui.ini";
44
     logFilename = RunTime::getBaseDir() + "/imgui_log.txt";
49
     logFilename = RunTime::getBaseDir() + "/imgui_log.txt";

+ 0
- 10
src/commands/CommandRender.cpp View File

6
  */
6
  */
7
 
7
 
8
 #include "global.h"
8
 #include "global.h"
9
-#include "Game.h"
10
 #include "Log.h"
9
 #include "Log.h"
11
 #include "Render.h"
10
 #include "Render.h"
12
 #include "commands/CommandRender.h"
11
 #include "commands/CommandRender.h"
27
     getLog() << "  solid" << Log::endl;
26
     getLog() << "  solid" << Log::endl;
28
     getLog() << "  texture" << Log::endl;
27
     getLog() << "  texture" << Log::endl;
29
     getLog() << "  titlescreen" << Log::endl;
28
     getLog() << "  titlescreen" << Log::endl;
30
-    getLog() << "  disabled" << Log::endl;
31
 
29
 
32
 }
30
 }
33
 
31
 
34
 int CommandMode::execute(std::istream& args) {
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
     std::string s;
33
     std::string s;
41
     args >> s;
34
     args >> s;
42
 
35
 
52
     } else if (s == "titlescreen") {
45
     } else if (s == "titlescreen") {
53
         Render::setMode(RenderMode::LoadScreen);
46
         Render::setMode(RenderMode::LoadScreen);
54
         getLog() << "Titlescreen mode" << Log::endl;
47
         getLog() << "Titlescreen mode" << Log::endl;
55
-    } else if (s == "disabled") {
56
-        Render::setMode(RenderMode::Disabled);
57
-        getLog() << "Disabled mode" << Log::endl;
58
     } else {
48
     } else {
59
         getLog() << "Invalid use of mode command (" << s << ")!" << Log::endl;
49
         getLog() << "Invalid use of mode command (" << s << ")!" << Log::endl;
60
         return -2;
50
         return -2;

+ 2
- 0
src/main.cpp View File

9
 #include <memory>
9
 #include <memory>
10
 
10
 
11
 #include "global.h"
11
 #include "global.h"
12
+#include "Camera.h"
12
 #include "Exception.h"
13
 #include "Exception.h"
13
 #include "Game.h"
14
 #include "Game.h"
14
 #include "Log.h"
15
 #include "Log.h"
139
     }
140
     }
140
 
141
 
141
     getLog() << "Starting " << VERSION << Log::endl;
142
     getLog() << "Starting " << VERSION << Log::endl;
143
+    Camera::setSize(Window::getSize());
142
     getMenu().setVisible(true);
144
     getMenu().setVisible(true);
143
     systemTimerReset();
145
     systemTimerReset();
144
     RunTime::setRunning(true);
146
     RunTime::setRunning(true);

+ 9
- 3
src/system/Window.cpp View File

6
  */
6
  */
7
 
7
 
8
 #include "global.h"
8
 #include "global.h"
9
+#include "Camera.h"
9
 #include "Log.h"
10
 #include "Log.h"
11
+#include "UI.h"
10
 #include "utils/strings.h"
12
 #include "utils/strings.h"
11
 #include "system/Window.h"
13
 #include "system/Window.h"
12
 
14
 
58
 #endif
60
 #endif
59
 }
61
 }
60
 
62
 
61
-void Window::setSize(glm::vec2 s) {
63
+void Window::setSize(glm::i32vec2 s) {
62
 #ifdef USING_SDL
64
 #ifdef USING_SDL
63
     WindowSDL::setSize(s);
65
     WindowSDL::setSize(s);
64
 #elif defined(USING_GLFW)
66
 #elif defined(USING_GLFW)
65
     WindowGLFW::setSize(s);
67
     WindowGLFW::setSize(s);
66
 #endif
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
 #ifdef USING_SDL
77
 #ifdef USING_SDL
72
     ret = WindowSDL::getSize();
78
     ret = WindowSDL::getSize();
73
 #elif defined(USING_GLFW)
79
 #elif defined(USING_GLFW)

+ 5
- 3
src/system/WindowGLFW.cpp View File

11
 #include "Log.h"
11
 #include "Log.h"
12
 #include "RunTime.h"
12
 #include "RunTime.h"
13
 #include "UI.h"
13
 #include "UI.h"
14
+#include "system/Window.h"
14
 #include "utils/strings.h"
15
 #include "utils/strings.h"
15
 #include "system/WindowGLFW.h"
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
 bool WindowGLFW::fullscreen = false;
19
 bool WindowGLFW::fullscreen = false;
19
 bool WindowGLFW::mousegrab = false;
20
 bool WindowGLFW::mousegrab = false;
20
 bool WindowGLFW::textinput = false;
21
 bool WindowGLFW::textinput = false;
78
     }
79
     }
79
 }
80
 }
80
 
81
 
81
-void WindowGLFW::setSize(glm::vec2 s) {
82
+void WindowGLFW::setSize(glm::i32vec2 s) {
82
     assert((s.x > 0) && (s.y > 0));
83
     assert((s.x > 0) && (s.y > 0));
83
     if (window) {
84
     if (window) {
84
         if ((size.x != s.x) || (size.y != s.y)) {
85
         if ((size.x != s.x) || (size.y != s.y)) {
113
 }
114
 }
114
 
115
 
115
 void WindowGLFW::sizeCallback(GLFWwindow* w, int width, int height) {
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
 void WindowGLFW::cursorCallback(GLFWwindow* w, double xpos, double ypos) {
121
 void WindowGLFW::cursorCallback(GLFWwindow* w, double xpos, double ypos) {

+ 12
- 7
src/system/WindowSDL.cpp View File

11
 #include "Log.h"
11
 #include "Log.h"
12
 #include "RunTime.h"
12
 #include "RunTime.h"
13
 #include "UI.h"
13
 #include "UI.h"
14
+#include "system/Window.h"
14
 #include "utils/strings.h"
15
 #include "utils/strings.h"
15
 #include "system/WindowSDL.h"
16
 #include "system/WindowSDL.h"
16
 
17
 
17
 #define SUBSYSTEMS_USED (SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER)
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
 bool WindowSDL::fullscreen = false;
21
 bool WindowSDL::fullscreen = false;
21
 bool WindowSDL::mousegrab = false;
22
 bool WindowSDL::mousegrab = false;
22
 bool WindowSDL::textinput = false;
23
 bool WindowSDL::textinput = false;
457
                 break;
458
                 break;
458
 
459
 
459
             case SDL_WINDOWEVENT:
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
                 break;
465
                 break;
463
 
466
 
464
             case SDL_QUIT:
467
             case SDL_QUIT:
493
     }
496
     }
494
 }
497
 }
495
 
498
 
496
-void WindowSDL::setSize(glm::vec2 s) {
499
+void WindowSDL::setSize(glm::i32vec2 s) {
497
     assert((s.x > 0) && (s.y > 0));
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
     size = s;
506
     size = s;
500
-    if (window)
501
-        SDL_SetWindowSize(window, size.x, size.y);
502
 }
507
 }
503
 
508
 
504
 void WindowSDL::setFullscreen(bool f) {
509
 void WindowSDL::setFullscreen(bool f) {

Loading…
Cancel
Save