From 9b468e5c8ae46e7d1e51ba1f12ed331b569400c5 Mon Sep 17 00:00:00 2001 From: avery Date: Thu, 7 Nov 2024 02:11:30 +0000 Subject: [PATCH] fix camera movement --- src/main.cpp | 16 ++++++++-------- src/util/shaders.hpp | 2 +- src/util/unique_image.hpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 047f982..50340ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -244,24 +244,24 @@ class VulkanApp { struct Camera { glm::dvec3 position; - glm::dvec3 front; glm::dvec3 up; - f64 speed {}; + glm::dvec3 look_at; + f64 speed {1.0}; - Camera() : position(2.0, 2.0, 2.0), front(0.0, 0.0, 0.0), up(0.0, 0.0, 1.0) {} + Camera() : position(2.0, 2.0, 2.0), up(0.0, 0.0, 1.0), look_at(0.0) {} - [[nodiscard]] fn getViewMatrix() const -> glm::mat4 { return glm::lookAt(position, front, up); } + [[nodiscard]] fn getViewMatrix() const -> glm::mat4 { return glm::lookAt(position, look_at, up); } - fn moveForward(f64 deltaTime) -> void { position += speed * front * deltaTime; } + fn moveForward(f64 deltaTime) -> void { position += (look_at - position) * speed * deltaTime; } - fn moveBackward(f64 deltaTime) -> void { position -= speed * front * deltaTime; } + fn moveBackward(f64 deltaTime) -> void { position -= (look_at - position) * speed * deltaTime; } fn moveLeft(f64 deltaTime) -> void { - position -= glm::normalize(glm::cross(front, up)) * speed * deltaTime; + position -= glm::normalize(glm::cross((look_at - position), up)) * speed * deltaTime; } fn moveRight(f64 deltaTime) -> void { - position += glm::normalize(glm::cross(front, up)) * speed * deltaTime; + position += glm::normalize(glm::cross((look_at - position), up)) * speed * deltaTime; } }; diff --git a/src/util/shaders.hpp b/src/util/shaders.hpp index 3c33dbe..13b23b7 100644 --- a/src/util/shaders.hpp +++ b/src/util/shaders.hpp @@ -50,7 +50,7 @@ class ShaderCompiler { throw runtime_error("Shader compilation failed for: " + shaderName); // Cache the compiled SPIR-V binary - saveCompiledShader(spirvCode, cacheFile); + saveCompiledShader(spirvCode, cacheFile.string()); return spirvCode; } diff --git a/src/util/unique_image.hpp b/src/util/unique_image.hpp index 92c7af4..622fe9a 100644 --- a/src/util/unique_image.hpp +++ b/src/util/unique_image.hpp @@ -19,7 +19,7 @@ namespace stb { * * @param path The filesystem path to the image file to load. */ - UniqueImage(const std::filesystem::path& path) { load(path.c_str()); } + UniqueImage(const std::filesystem::path& path) { load(path.string().c_str()); } // Deleted copy constructor to prevent copying. UniqueImage(const UniqueImage&) = delete; -- 2.47.0