From 0e572d7f8957aa25ed1597244df8de22def6b825 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Wed, 22 Feb 2023 15:15:38 +0800 Subject: [PATCH] progress --- SHADE_Engine/src/Input/SHInputManager.cpp | 6 +++--- SHADE_Engine/src/Input/SHInputManager.h | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index d3ce59d5..c28636d3 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -24,6 +24,7 @@ namespace SHADE /* Static defines */ /*------------------------------------------------------------------------*/ + bool SHInputManager::mouseCentering = false; bool SHInputManager::controllerInUse = false; std::map SHInputManager::bindings; @@ -806,16 +807,15 @@ namespace SHADE //Mouse Centering - if (GetKey(SH_KEYCODE::Q)) + if (mouseCentering) { uint32_t width = SHADE::SHGraphicsSystemInterface::GetWindowWidth(); uint32_t height = SHADE::SHGraphicsSystemInterface::GetWindowHeight(); SetMouseWindowPosition(width / 2, height / 2); - //This four lines help a lot + //These four lines help a lot POINT p; GetCursorPos(&p); - mouseVelocityX -= static_cast(p.x - mouseScreenX) / dt; mouseVelocityY -= static_cast(p.y - mouseScreenY) / dt; } diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 1bcafa7d..dcfcdf57 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -1074,6 +1074,18 @@ namespace SHADE SetCursorPos(p.x, p.y); } + //Call to set the flag to start mouse centering every frame + static inline void SetMouseCentering(bool state) noexcept + { + mouseCentering = state; + } + + //Get the flag whether mouse centering is on or not + static inline bool GetMouseCentering() noexcept + { + return mouseCentering; + } + private: /*------------------------------------------------------------------------*/ /* Constants */ @@ -1097,6 +1109,9 @@ namespace SHADE /* Data Members */ /*------------------------------------------------------------------------*/ + //Whether mouse centering will be called every frame or not + static bool mouseCentering; + //If the last input is from controller(s) or KB/M //True if from controller(s), False if from KB/M //Useful for switching control hints between controllers and KB/M