From 514f46875b92ebef93f463d2d88fada6b93ff1cb Mon Sep 17 00:00:00 2001 From: Hjalte Sorgenfrei Mac Dalland Date: Fri, 30 Sep 2022 16:19:17 +0200 Subject: [PATCH] Shift modifier to set "sprint" in camera --- src/Application.cpp | 11 ++++++++++- src/Application.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Application.cpp b/src/Application.cpp index 6d49d2a..cdaa76a 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -87,6 +87,12 @@ void App::keyCallback(GLFWwindow* window, int key, int scancode, int action, int if(key == GLFW_KEY_E && action == GLFW_PRESS) { app->showImguizmo = !app->showImguizmo; } + if(key == GLFW_KEY_LEFT_SHIFT && action != GLFW_RELEASE) { + app->shiftPressed = true; + } + if(key == GLFW_KEY_LEFT_SHIFT && action == GLFW_RELEASE) { + app->shiftPressed = false; + } } void App::mainLoop() { @@ -124,7 +130,10 @@ void App::drawImGuizmo(glm::mat4* matrix) { void App::processPressedKeys(double delta) { auto glfw_window = window->getGLFWwindow(); - const float cameraSpeed = 0.005f * static_cast(delta); + float cameraSpeed = 0.005f * static_cast(delta); + if (shiftPressed) { + cameraSpeed *= 4; + } if (glfwGetKey(glfw_window, GLFW_KEY_W) == GLFW_PRESS) model->moveCameraForward(cameraSpeed); if (glfwGetKey(glfw_window, GLFW_KEY_S) == GLFW_PRESS) diff --git a/src/Application.h b/src/Application.h index 97ff287..fa122f5 100644 --- a/src/Application.h +++ b/src/Application.h @@ -29,4 +29,6 @@ class App { static void cursorEnterCallback(GLFWwindow *window, int enter); static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods); static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); + + bool shiftPressed = false; };