Fix Android camera jump issue (phew)

This commit is contained in:
Gregor Parzefall 2024-05-05 19:43:11 +02:00
parent fb059f1e30
commit 3ed2e2ccbf
3 changed files with 17 additions and 4 deletions

View File

@ -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;

View File

@ -154,8 +154,11 @@ public:
//! 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 @@ private:
#endif
s32 MouseX, MouseY;
// these two only continue to exist for some Emscripten stuff idk about
s32 MouseXRel, MouseYRel;
u32 MouseButtonStates;

View File

@ -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_touchcontrols) {
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_touchcontrols)
m_first_loop_after_window_activation = true;
}
// Get the factor to multiply with sensitivity to get the same mouse/joystick