Просмотр исходного кода

Keep Camera in Room. Travis glbinding changes.

Thomas Buck 9 лет назад
Родитель
Сommit
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
     * Slightly tweaked portal visibility checks.
7
     * Slightly tweaked portal visibility checks.
8
     * Fix to allow imguifilesystem to compile using Visual Studio 2013.
8
     * Fix to allow imguifilesystem to compile using Visual Studio 2013.
9
     * Very simple implementation of solid-mode using white texture.
9
     * Very simple implementation of solid-mode using white texture.
10
+    * New option to keep camera in a room.
10
 
11
 
11
     [ 20150405 ]
12
     [ 20150405 ]
12
     * No longer flipping axis in shaders, now turning camera upside-down.
13
     * No longer flipping axis in shaders, now turning camera upside-down.

+ 3
- 7
cmake/travis_script_linux.sh Просмотреть файл

7
 if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.5"; fi
7
 if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.5"; fi
8
 
8
 
9
 # Need to build latest glbinding from source
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
 mkdir build
14
 mkdir build
19
 cd build
15
 cd build

+ 3
- 7
cmake/travis_script_mac.sh Просмотреть файл

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
 # Need to build latest glbinding from source
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
 mkdir build
8
 mkdir build
13
 cd build
9
 cd build

+ 4
- 0
include/Camera.h Просмотреть файл

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

+ 16
- 11
src/Camera.cpp Просмотреть файл

12
 
12
 
13
 #include "global.h"
13
 #include "global.h"
14
 #include "RunTime.h"
14
 #include "RunTime.h"
15
+#include "World.h"
15
 #include "system/Shader.h"
16
 #include "system/Shader.h"
16
 #include "system/Sound.h"
17
 #include "system/Sound.h"
17
 #include "system/Window.h"
18
 #include "system/Window.h"
63
 bool Camera::dirty = true;
64
 bool Camera::dirty = true;
64
 bool Camera::showOverlay = false;
65
 bool Camera::showOverlay = false;
65
 bool Camera::movingFaster = false;
66
 bool Camera::movingFaster = false;
67
+bool Camera::keepInRoom = false;
66
 int Camera::room = -1;
68
 int Camera::room = -1;
67
 
69
 
68
 void Camera::reset() {
70
 void Camera::reset() {
182
     glm::quat quatX = glm::angleAxis(rot.y, glm::vec3(1.0f, 0.0f, 0.0f));
184
     glm::quat quatX = glm::angleAxis(rot.y, glm::vec3(1.0f, 0.0f, 0.0f));
183
     glm::quat quaternion = quatZ * quatY * quatX;
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
     } else {
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
     glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
205
     glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
201
     glm::mat4 rotate = glm::toMat4(quaternion);
206
     glm::mat4 rotate = glm::toMat4(quaternion);
202
     view = glm::inverse(translate * rotate);
207
     view = glm::inverse(translate * rotate);

+ 1
- 0
src/Game.cpp Просмотреть файл

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

+ 9
- 4
src/Render.cpp Просмотреть файл

243
         ImGui::Separator();
243
         ImGui::Separator();
244
         ImGui::Text("Camera:");
244
         ImGui::Text("Camera:");
245
         bool updateViewFrustum = Camera::getUpdateViewFrustum();
245
         bool updateViewFrustum = Camera::getUpdateViewFrustum();
246
-        if (ImGui::Checkbox("Update Frustum##render", &updateViewFrustum)) {
246
+        if (ImGui::Checkbox("Update Frustum##camera", &updateViewFrustum)) {
247
             Camera::setUpdateViewFrustum(updateViewFrustum);
247
             Camera::setUpdateViewFrustum(updateViewFrustum);
248
         }
248
         }
249
         ImGui::SameLine();
249
         ImGui::SameLine();
250
-        ImGui::Checkbox("Show Frustum##render", &displayViewFrustum);
250
+        ImGui::Checkbox("Show Frustum##camera", &displayViewFrustum);
251
         ImGui::SameLine();
251
         ImGui::SameLine();
252
         bool showOverlay = Camera::getShowOverlay();
252
         bool showOverlay = Camera::getShowOverlay();
253
-        if (ImGui::Checkbox("Overlay", &showOverlay)) {
253
+        if (ImGui::Checkbox("Overlay##camera", &showOverlay)) {
254
             Camera::setShowOverlay(showOverlay);
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
         glm::vec3 camPos = Camera::getPosition();
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
             Camera::setPosition(camPos);
263
             Camera::setPosition(camPos);
259
         }
264
         }
260
 
265
 

Загрузка…
Отмена
Сохранить