mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
Android: Fix camera jump when switching to mouse mode
Easy way to reproduce: 1. Connect a bluetooth mouse to your Android phone with Minetest installed 2. Play Minetest 3. Slowly move the mouse to the right so that the camera rotates continously 4. While still moving the mouse continously, tap the screen a few times per second Before this commit: The camera jumps around randomly. After this commit: The camera moves like it should. This is a combination of two Irrlicht changes copied from MoNTE48/irrlicht and one Minetest change authored by me. I have no idea why this works, but it does work and I have spent way too much time on this bug already.
This commit is contained in:
parent
4952f17df4
commit
f5076723e8
3 changed files with 19 additions and 5 deletions
|
@ -721,12 +721,19 @@ bool CIrrDeviceSDL::run()
|
||||||
|
|
||||||
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
|
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
|
||||||
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
|
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
|
||||||
MouseX = irrevent.MouseInput.X =
|
|
||||||
static_cast<s32>(SDL_event.motion.x * ScaleX);
|
|
||||||
MouseY = irrevent.MouseInput.Y =
|
|
||||||
static_cast<s32>(SDL_event.motion.y * ScaleY);
|
|
||||||
MouseXRel = static_cast<s32>(SDL_event.motion.xrel * ScaleX);
|
MouseXRel = static_cast<s32>(SDL_event.motion.xrel * ScaleX);
|
||||||
MouseYRel = static_cast<s32>(SDL_event.motion.yrel * ScaleY);
|
MouseYRel = static_cast<s32>(SDL_event.motion.yrel * ScaleY);
|
||||||
|
if (!SDL_GetRelativeMouseMode()) {
|
||||||
|
MouseX = static_cast<s32>(SDL_event.motion.x * ScaleX);
|
||||||
|
MouseY = static_cast<s32>(SDL_event.motion.y * ScaleY);
|
||||||
|
} else {
|
||||||
|
MouseX += MouseXRel;
|
||||||
|
MouseY += MouseYRel;
|
||||||
|
}
|
||||||
|
irrevent.MouseInput.X = MouseX;
|
||||||
|
irrevent.MouseInput.Y = MouseY;
|
||||||
|
|
||||||
irrevent.MouseInput.ButtonStates = MouseButtonStates;
|
irrevent.MouseInput.ButtonStates = MouseButtonStates;
|
||||||
irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;
|
irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;
|
||||||
irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;
|
irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;
|
||||||
|
|
|
@ -158,9 +158,13 @@ public:
|
||||||
//! Sets the new position of the cursor.
|
//! Sets the new position of the cursor.
|
||||||
void setPosition(s32 x, s32 y) override
|
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,
|
SDL_WarpMouseInWindow(Device->Window,
|
||||||
static_cast<int>(x / Device->ScaleX),
|
static_cast<int>(x / Device->ScaleX),
|
||||||
static_cast<int>(y / Device->ScaleY));
|
static_cast<int>(y / Device->ScaleY));
|
||||||
|
#endif
|
||||||
|
|
||||||
if (SDL_GetRelativeMouseMode()) {
|
if (SDL_GetRelativeMouseMode()) {
|
||||||
// There won't be an event for this warp (details on libsdl-org/SDL/issues/6034)
|
// There won't be an event for this warp (details on libsdl-org/SDL/issues/6034)
|
||||||
|
@ -298,6 +302,7 @@ private:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
s32 MouseX, MouseY;
|
s32 MouseX, MouseY;
|
||||||
|
// these two only continue to exist for some Emscripten stuff idk about
|
||||||
s32 MouseXRel, MouseYRel;
|
s32 MouseXRel, MouseYRel;
|
||||||
u32 MouseButtonStates;
|
u32 MouseButtonStates;
|
||||||
|
|
||||||
|
|
|
@ -2679,7 +2679,7 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
|
||||||
cur_control->setVisible(false);
|
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;
|
m_first_loop_after_window_activation = false;
|
||||||
|
|
||||||
input->setMousePos(driver->getScreenSize().Width / 2,
|
input->setMousePos(driver->getScreenSize().Width / 2,
|
||||||
|
@ -2695,6 +2695,8 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
|
||||||
|
|
||||||
m_first_loop_after_window_activation = true;
|
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
|
// Get the factor to multiply with sensitivity to get the same mouse/joystick
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue