From 9aa738fcacc4ff70d328ca491262d4ba8417a229 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall Date: Sun, 5 May 2024 19:43:11 +0200 Subject: [PATCH] Fix Android camera jump issue (phew) --- irr/src/CIrrDeviceSDL.cpp | 11 +++++++++-- irr/src/CIrrDeviceSDL.h | 6 +++++- src/client/game.cpp | 4 +++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index b50fd4b4a17a7..92311a787c5b3 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -652,10 +652,17 @@ bool CIrrDeviceSDL::run() irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; - MouseX = irrevent.MouseInput.X = SDL_event.motion.x; - MouseY = irrevent.MouseInput.Y = SDL_event.motion.y; + + if (!SDL_GetRelativeMouseMode()) { + MouseX = irrevent.MouseInput.X = SDL_event.motion.x; + MouseY = irrevent.MouseInput.Y = SDL_event.motion.y; + } else { + MouseX = irrevent.MouseInput.X = MouseX + SDL_event.motion.xrel; + MouseY = irrevent.MouseInput.Y = MouseY + SDL_event.motion.yrel; + } MouseXRel = SDL_event.motion.xrel; MouseYRel = SDL_event.motion.yrel; + irrevent.MouseInput.ButtonStates = MouseButtonStates; irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0; irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0; diff --git a/irr/src/CIrrDeviceSDL.h b/irr/src/CIrrDeviceSDL.h index a83e8cf5e5805..7ec397b82cfe0 100644 --- a/irr/src/CIrrDeviceSDL.h +++ b/irr/src/CIrrDeviceSDL.h @@ -154,8 +154,11 @@ class CIrrDeviceSDL : public CIrrDeviceStub //! Sets the new position of the cursor. void setPosition(s32 x, s32 y) override { +#ifndef __ANDROID__ + // On Android, this somehow results in a camera jump when enabling + // relative mouse mode and it isn't supported anyway. SDL_WarpMouseInWindow(Device->Window, x, y); - +#endif if (SDL_GetRelativeMouseMode()) { // There won't be an event for this warp (details on libsdl-org/SDL/issues/6034) Device->MouseX = x; @@ -292,6 +295,7 @@ class CIrrDeviceSDL : public CIrrDeviceStub #endif s32 MouseX, MouseY; + // these two only continue to exist for some Emscripten stuff idk about s32 MouseXRel, MouseYRel; u32 MouseButtonStates; diff --git a/src/client/game.cpp b/src/client/game.cpp index 001e4b5eecc01..f58e9b72fb205 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2637,7 +2637,7 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime) cur_control->setVisible(false); } - if (m_first_loop_after_window_activation) { + if (m_first_loop_after_window_activation && !g_touchscreengui) { m_first_loop_after_window_activation = false; input->setMousePos(driver->getScreenSize().Width / 2, @@ -2653,6 +2653,8 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime) m_first_loop_after_window_activation = true; } + if (g_touchscreengui) + m_first_loop_after_window_activation = true; } // Get the factor to multiply with sensitivity to get the same mouse/joystick