From 0d1fae46c9d8e6a276c6cbc6d3723695f2ca3f5d Mon Sep 17 00:00:00 2001 From: "Benedikt S. Vogler" Date: Thu, 10 Jul 2025 13:48:22 +0200 Subject: [PATCH] add rotation keys q and e key to rotate camera along the Z axis --- .gitignore | 3 ++- src/GUIManager.cpp | 2 ++ src/Renderer.cpp | 6 ++++++ src/vulkan/Window.h | 2 +- src/vulkan/windowing/GLFWWindow.cpp | 6 ++++-- src/vulkan/windowing/GLFWWindow.h | 2 +- 6 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 692201a..4c04705 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,5 @@ apps/apple/VulkanSplatting/ThirdParty # xcuserdata under any directory is ignored xcuserdata/ -project.xcconfig \ No newline at end of file +project.xcconfig +/build diff --git a/src/GUIManager.cpp b/src/GUIManager.cpp index 72ff7f4..e5a6a8d 100644 --- a/src/GUIManager.cpp +++ b/src/GUIManager.cpp @@ -89,6 +89,8 @@ void GUIManager::buildGui() { ImGui::Text("WASD: move"); ImGui::Text("Space: up"); ImGui::Text("Shift: down"); + ImGui::Text("Q: rotate left"); + ImGui::Text("E: rotate right"); ImGui::Text("Left click: capture mouse"); ImGui::Text("ESC: release mouse"); ImGui::Text("Mouse captured: %s", mouseCapture ? "true" : "false"); diff --git a/src/Renderer.cpp b/src/Renderer.cpp index fe7e4e4..afbe8f7 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -75,6 +75,12 @@ void Renderer::handleInput() { window->mouseCapture(false); guiManager.mouseCapture = false; } + if (keys[7]) { + camera.rotation = glm::rotate(camera.rotation, -0.05f, glm::vec3(0.0f, 0.0f, 1.0f)); + } + if (keys[8]) { + camera.rotation = glm::rotate(camera.rotation, 0.05f, glm::vec3(0.0f, 0.0f, 1.0f)); + } if (direction != glm::vec3(0.0f, 0.0f, 0.0f)) { direction = glm::normalize(direction); camera.position += (glm::mat4_cast(camera.rotation) * glm::vec4(direction, 1.0f)).xyz() * 0.3f; diff --git a/src/vulkan/Window.h b/src/vulkan/Window.h index 71932d0..1124c72 100644 --- a/src/vulkan/Window.h +++ b/src/vulkan/Window.h @@ -19,7 +19,7 @@ class Window { virtual std::array getCursorTranslation() { return {0, 0}; } - virtual std::array getKeys() { return {false, false, false, false, false, false, false}; } + virtual std::array getKeys() { return {false, false, false, false, false, false, false, false, false}; } virtual void mouseCapture(bool capture) { } diff --git a/src/vulkan/windowing/GLFWWindow.cpp b/src/vulkan/windowing/GLFWWindow.cpp index 576982d..a93ced4 100644 --- a/src/vulkan/windowing/GLFWWindow.cpp +++ b/src/vulkan/windowing/GLFWWindow.cpp @@ -53,7 +53,7 @@ std::array GLFWWindow::getCursorTranslation() { return translation; } -std::array GLFWWindow::getKeys() { +std::array GLFWWindow::getKeys() { return { glfwGetKey(static_cast(window), GLFW_KEY_W) == GLFW_PRESS, glfwGetKey(static_cast(window), GLFW_KEY_A) == GLFW_PRESS, @@ -61,7 +61,9 @@ std::array GLFWWindow::getKeys() { glfwGetKey(static_cast(window), GLFW_KEY_D) == GLFW_PRESS, glfwGetKey(static_cast(window), GLFW_KEY_SPACE) == GLFW_PRESS, glfwGetKey(static_cast(window), GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS, - glfwGetKey(static_cast(window), GLFW_KEY_ESCAPE) == GLFW_PRESS + glfwGetKey(static_cast(window), GLFW_KEY_ESCAPE) == GLFW_PRESS, + glfwGetKey(static_cast(window), GLFW_KEY_Q) == GLFW_PRESS, + glfwGetKey(static_cast(window), GLFW_KEY_E) == GLFW_PRESS }; } diff --git a/src/vulkan/windowing/GLFWWindow.h b/src/vulkan/windowing/GLFWWindow.h index 25ff327..767b9e4 100644 --- a/src/vulkan/windowing/GLFWWindow.h +++ b/src/vulkan/windowing/GLFWWindow.h @@ -17,7 +17,7 @@ class GLFWWindow final : public Window { std::array getCursorTranslation() override; - std::array getKeys() override; + std::array getKeys() override; void mouseCapture(bool capture) override;