From 9315c08a69674ea8a97e239d1f08f7bcbf1a1ae3 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Fri, 10 Mar 2023 21:37:54 +0800 Subject: [PATCH] Mouse centering velocity calculation corrected --- SHADE_Engine/src/Input/SHInputManager.cpp | 40 +++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index dd3cfe80..6645aa1b 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -798,17 +798,45 @@ namespace SHADE //Get cursor position, even when it is outside window POINT p; - GetCursorPos(&p); + GetCursorPos(&p); //This point is WRT the screen, not the window + //ScreenToClient(GetActiveWindow(), &p); mouseScreenX = p.x; mouseScreenY = p.y; + //SHLOGV_INFO("MouseScreenY = {}", mouseScreenY); - //Velocity - mouseVelocityX = static_cast(mouseScreenX - mouseScreenXLast) / dt; - mouseVelocityY = static_cast(mouseScreenY - mouseScreenYLast) / dt; + if (!mouseCentering) + { + //Velocity + mouseVelocityX = static_cast(mouseScreenX - mouseScreenXLast) / dt; + mouseVelocityY = static_cast(mouseScreenY - mouseScreenYLast) / dt; + } + else + { + //Mouse centering + //uint32_t width = SHADE::SHGraphicsSystemInterface::GetWindowWidth(); + //uint32_t height = SHADE::SHGraphicsSystemInterface::GetWindowHeight(); + int mouseCenterX = 0; + int mouseCenterY = 0; + RECT wndRect = { NULL }; //4th quadrant + if (GetWindowRect(GetActiveWindow(), &wndRect)) + { + mouseCenterX = wndRect.left + (wndRect.right - wndRect.left) / 2; + mouseCenterY = wndRect.top + (wndRect.bottom - wndRect.top) / 2; + //SHLOGV_INFO("W: {0}, H: {1}", (wndRect.right - wndRect.left), (wndRect.bottom - wndRect.top)); + } + //Velocity + mouseVelocityX = static_cast(mouseScreenX - mouseCenterX) / dt; + mouseVelocityY = static_cast(mouseScreenY - mouseCenterY) / dt; + //SHLOGV_INFO("mouseScreenY = {0:0}, mouseCenterY = {1:0}", mouseScreenY, mouseCenterY); + //SHLOGV_INFO("{0.0}", mouseVelocityY); + + SetMouseScreenPosition(mouseCenterX, mouseCenterY); + } + //Mouse Centering - if (mouseCentering) + /*if (mouseCentering) { uint32_t width = SHADE::SHGraphicsSystemInterface::GetWindowWidth(); uint32_t height = SHADE::SHGraphicsSystemInterface::GetWindowHeight(); @@ -819,7 +847,7 @@ namespace SHADE GetCursorPos(&p); mouseVelocityX -= static_cast(p.x - mouseScreenX) / dt; mouseVelocityY -= static_cast(p.y - mouseScreenY) / dt; - } + }*/ if (mouseVelocityX != 0.0 || mouseVelocityY != 0.0) controllerInUse = false; -- 2.40.1