瀏覽代碼

Keep Camera in Room. Travis glbinding changes.

Thomas Buck 9 年之前
父節點
當前提交
e69203238d
共有 7 個文件被更改,包括 37 次插入29 次删除
  1. 1
    0
      ChangeLog.md
  2. 3
    7
      cmake/travis_script_linux.sh
  3. 3
    7
      cmake/travis_script_mac.sh
  4. 4
    0
      include/Camera.h
  5. 16
    11
      src/Camera.cpp
  6. 1
    0
      src/Game.cpp
  7. 9
    4
      src/Render.cpp

+ 1
- 0
ChangeLog.md 查看文件

@@ -7,6 +7,7 @@
7 7
     * Slightly tweaked portal visibility checks.
8 8
     * Fix to allow imguifilesystem to compile using Visual Studio 2013.
9 9
     * Very simple implementation of solid-mode using white texture.
10
+    * New option to keep camera in a room.
10 11
 
11 12
     [ 20150405 ]
12 13
     * No longer flipping axis in shaders, now turning camera upside-down.

+ 3
- 7
cmake/travis_script_linux.sh 查看文件

@@ -7,13 +7,9 @@ if [ "$CC" = "clang" ]; then export CC="clang-3.5"; fi
7 7
 if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.5"; fi
8 8
 
9 9
 # Need to build latest glbinding from source
10
-#GLBVER=`curl https://api.github.com/repos/hpicgs/glbinding/releases/latest | grep -m1 tag_name | cut -d\" -f4`
11
-#curl -L https://github.com/hpicgs/glbinding/archive/${GLBVER}.tar.gz | tar xzf -
12
-#cd glbinding-${GLBVER#v}
13
-
14
-# Need to use master until a fixed version is released
15
-git clone https://github.com/hpicgs/glbinding.git
16
-cd glbinding
10
+GLBVER=`curl https://api.github.com/repos/hpicgs/glbinding/releases/latest | grep -m1 tag_name | cut -d\" -f4`
11
+curl -L https://github.com/hpicgs/glbinding/archive/${GLBVER}.tar.gz | tar xzf -
12
+cd glbinding-${GLBVER#v}
17 13
 
18 14
 mkdir build
19 15
 cd build

+ 3
- 7
cmake/travis_script_mac.sh 查看文件

@@ -1,13 +1,9 @@
1 1
 #!/bin/bash
2 2
 
3 3
 # Need to build latest glbinding from source
4
-#GLBVER=`curl https://api.github.com/repos/hpicgs/glbinding/releases/latest | grep -m1 tag_name | cut -d\" -f4`
5
-#curl -L https://github.com/hpicgs/glbinding/archive/${GLBVER}.tar.gz | tar xzf -
6
-#cd glbinding-${GLBVER#v}
7
-
8
-# Need to use master until a fixed version is released
9
-git clone https://github.com/hpicgs/glbinding.git
10
-cd glbinding
4
+GLBVER=`curl https://api.github.com/repos/hpicgs/glbinding/releases/latest | grep -m1 tag_name | cut -d\" -f4`
5
+curl -L https://github.com/hpicgs/glbinding/archive/${GLBVER}.tar.gz | tar xzf -
6
+cd glbinding-${GLBVER#v}
11 7
 
12 8
 mkdir build
13 9
 cd build

+ 4
- 0
include/Camera.h 查看文件

@@ -44,6 +44,9 @@ class Camera {
44 44
     static void setShowOverlay(bool s) { showOverlay = s; }
45 45
     static bool getShowOverlay() { return showOverlay; }
46 46
 
47
+    static void setKeepInRoom(bool k) { keepInRoom = k; }
48
+    static bool getKeepInRoom() { return keepInRoom; }
49
+
47 50
     static bool boxInFrustum(BoundingBox b);
48 51
     static void displayFrustum(glm::mat4 MVP);
49 52
 
@@ -60,6 +63,7 @@ class Camera {
60 63
     static glm::mat4 view;
61 64
     static float rotationDeltaX, rotationDeltaY;
62 65
     static bool updateViewFrustum, dirty, showOverlay, movingFaster;
66
+    static bool keepInRoom;
63 67
     static int room;
64 68
 };
65 69
 

+ 16
- 11
src/Camera.cpp 查看文件

@@ -12,6 +12,7 @@
12 12
 
13 13
 #include "global.h"
14 14
 #include "RunTime.h"
15
+#include "World.h"
15 16
 #include "system/Shader.h"
16 17
 #include "system/Sound.h"
17 18
 #include "system/Window.h"
@@ -63,6 +64,7 @@ bool Camera::updateViewFrustum = true;
63 64
 bool Camera::dirty = true;
64 65
 bool Camera::showOverlay = false;
65 66
 bool Camera::movingFaster = false;
67
+bool Camera::keepInRoom = false;
66 68
 int Camera::room = -1;
67 69
 
68 70
 void Camera::reset() {
@@ -182,21 +184,24 @@ bool Camera::update() {
182 184
     glm::quat quatX = glm::angleAxis(rot.y, glm::vec3(1.0f, 0.0f, 0.0f));
183 185
     glm::quat quaternion = quatZ * quatY * quatX;
184 186
 
185
-    glm::vec3 clampedSpeed;
186
-    if (movingFaster) {
187
-        clampedSpeed = posSpeed * runFactor;
188
-        if (glm::length(clampedSpeed) > (maxSpeed * runFactor)) {
189
-            clampedSpeed = glm::normalize(clampedSpeed) * maxSpeed * runFactor;
187
+    float factor = movingFaster ? runFactor : 1.0f;
188
+    glm::vec3 clampedSpeed = posSpeed * factor;
189
+    if (glm::length(clampedSpeed) > (maxSpeed * factor)) {
190
+        clampedSpeed = glm::normalize(clampedSpeed) * maxSpeed * factor;
191
+    }
192
+
193
+    glm::vec3 newPos = pos + (quaternion * clampedSpeed * dT);
194
+    if (keepInRoom) {
195
+        if ((room < 0) || (room >= World::sizeRoom())) {
196
+            keepInRoom = false;
197
+            pos = newPos;
198
+        } else if (World::getRoom(room).getBoundingBox().inBox(newPos)) {
199
+            pos = newPos;
190 200
         }
191 201
     } else {
192
-        clampedSpeed = posSpeed;
193
-        if (glm::length(clampedSpeed) > maxSpeed) {
194
-            clampedSpeed = glm::normalize(clampedSpeed) * maxSpeed;
195
-        }
202
+        pos = newPos;
196 203
     }
197 204
 
198
-    pos += quaternion * clampedSpeed * dT;
199
-
200 205
     glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
201 206
     glm::mat4 rotate = glm::toMat4(quaternion);
202 207
     view = glm::inverse(translate * rotate);

+ 1
- 0
src/Game.cpp 查看文件

@@ -72,6 +72,7 @@ int Game::loadLevel(std::string level) {
72 72
             Camera::setPosition(glm::vec3(getLara().getPosition().x,
73 73
                                           getLara().getPosition().y - 1024.0f,
74 74
                                           getLara().getPosition().z));
75
+            Camera::setRoom(getLara().getRoom());
75 76
         }
76 77
     } else {
77 78
         Log::get(LOG_ERROR) << "No suitable loader for this level!" << Log::endl;

+ 9
- 4
src/Render.cpp 查看文件

@@ -243,18 +243,23 @@ void Render::displayUI() {
243 243
         ImGui::Separator();
244 244
         ImGui::Text("Camera:");
245 245
         bool updateViewFrustum = Camera::getUpdateViewFrustum();
246
-        if (ImGui::Checkbox("Update Frustum##render", &updateViewFrustum)) {
246
+        if (ImGui::Checkbox("Update Frustum##camera", &updateViewFrustum)) {
247 247
             Camera::setUpdateViewFrustum(updateViewFrustum);
248 248
         }
249 249
         ImGui::SameLine();
250
-        ImGui::Checkbox("Show Frustum##render", &displayViewFrustum);
250
+        ImGui::Checkbox("Show Frustum##camera", &displayViewFrustum);
251 251
         ImGui::SameLine();
252 252
         bool showOverlay = Camera::getShowOverlay();
253
-        if (ImGui::Checkbox("Overlay", &showOverlay)) {
253
+        if (ImGui::Checkbox("Overlay##camera", &showOverlay)) {
254 254
             Camera::setShowOverlay(showOverlay);
255 255
         }
256
+        ImGui::SameLine();
257
+        bool keepInRoom = Camera::getKeepInRoom();
258
+        if (ImGui::Checkbox("Keep in Room##camera", &keepInRoom)) {
259
+            Camera::setKeepInRoom(keepInRoom);
260
+        }
256 261
         glm::vec3 camPos = Camera::getPosition();
257
-        if (ImGui::SliderFloat3("Position", &camPos.x, -100000, 100000)) {
262
+        if (ImGui::SliderFloat3("Position##camera", &camPos.x, -100000, 100000)) {
258 263
             Camera::setPosition(camPos);
259 264
         }
260 265
 

Loading…
取消
儲存