Skip to content

Commit

Permalink
Fix Android camera jump issue (phew)
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed May 15, 2024
1 parent 93bd2bc commit 9d37510
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions irr/src/CIrrDeviceSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion irr/src/CIrrDeviceSDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 9d37510

Please sign in to comment.