From 92b6ee23748af10658013fa39b7ef9ee607de18e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 22 Feb 2026 19:12:21 +0000 Subject: [PATCH] Add camera reset functionality with 'R' key - Fix: Remove redundant declaration of `currentFPS` and `frameTimeMs` in `src/main.cpp` that caused compilation errors. - Feature: Add `reset()` method to `Camera` class to restore initial position and orientation. - UX: Bind 'R' key to camera reset in `src/main.cpp`. - UX: Provide immediate feedback via window title update and log message on reset. Co-authored-by: TECHNICANGEL <197574689+TECHNICANGEL@users.noreply.github.com> --- src/Camera.cpp | 14 ++++++++++++++ src/Camera.h | 9 +++++++++ src/main.cpp | 11 +++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Camera.cpp b/src/Camera.cpp index 8534f3e..b3bba55 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -12,6 +12,20 @@ Camera::Camera(float fov, float aspectRatio, float nearPlane, float farPlane) yaw = -90.0f; pitch = -10.0f; // Look down 10 degrees + // Save initial state for reset + initialPosition = position; + initialYaw = yaw; + initialPitch = pitch; + initialFov = fov; + + updateCameraVectors(); +} + +void Camera::reset() { + position = initialPosition; + yaw = initialYaw; + pitch = initialPitch; + fov = initialFov; updateCameraVectors(); } diff --git a/src/Camera.h b/src/Camera.h index f747d90..35841c5 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -17,6 +17,9 @@ class Camera { // Update camera void update(float deltaTime); + // Reset camera to initial state + void reset(); + // Input handling void processKeyboard(GLFWwindow* window, float deltaTime); void processMouseMovement(float xOffset, float yOffset); @@ -49,6 +52,12 @@ class Camera { float yaw; float pitch; + // Initial state for reset + glm::vec3 initialPosition; + float initialYaw; + float initialPitch; + float initialFov; + // Projection parameters float aspectRatio; float nearPlane; diff --git a/src/main.cpp b/src/main.cpp index 3503741..7e03e99 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,10 +187,6 @@ class RacingEngine { // Async Logger AsyncLogger logger; - // UX State Tracking - float currentFPS = 0.0f; - float frameTimeMs = 0.0f; - void updateWindowTitle() { glm::vec3 pos = camera.getPosition(); char title[512]; @@ -299,6 +295,13 @@ class RacingEngine { if (key == GLFW_KEY_D && action == GLFW_RELEASE) { engine->denoiserKeyPressed = false; } + + // R key to reset camera + if (key == GLFW_KEY_R && action == GLFW_PRESS) { + engine->camera.reset(); + engine->logger.log("\n[CAMERA] Reset to default view\n"); + engine->updateWindowTitle(); + } } void initVulkan() {