Skip to content

Commit

Permalink
Avoid visible camera jumps because of touchscreen_threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Jan 29, 2024
1 parent 28c3fa8 commit 53dc7f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/gui/touchscreengui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
}

m_pointer_pos[event.TouchInput.ID] = touch_pos;
m_pointer_downpos[event.TouchInput.ID] = touch_pos;
}
else if (event.TouchInput.Event == ETIE_LEFT_UP) {
verbosestream << "Up event for pointerid: " << event.TouchInput.ID << std::endl;
Expand All @@ -804,24 +805,23 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
m_pointer_pos[event.TouchInput.ID] == touch_pos)
return;

const v2s32 free_joystick_center = v2s32(m_pointer_pos[event.TouchInput.ID].X,
m_pointer_pos[event.TouchInput.ID].Y);
const v2s32 free_joystick_center = m_pointer_pos[event.TouchInput.ID];
const v2s32 dir_free = touch_pos - free_joystick_center;
const v2s32 dir_free_original = touch_pos - m_pointer_downpos[event.TouchInput.ID];

const double touch_threshold_sq = m_touchscreen_threshold * m_touchscreen_threshold;

if (m_has_move_id && event.TouchInput.ID == m_move_id) {
if (dir_free.getLengthSQ() > touch_threshold_sq || m_move_has_really_moved) {
m_move_has_really_moved = true;
m_pointer_pos[event.TouchInput.ID] = touch_pos;
m_pointer_pos[event.TouchInput.ID] = touch_pos;

const double d = g_settings->getFloat("touchscreen_sensitivity", 0.001f, 10.0f)
* 6.0f / RenderingEngine::getDisplayDensity();
// update camera_yaw and camera_pitch
const double d = g_settings->getFloat("touchscreen_sensitivity", 0.001f, 10.0f)
* 6.0f / RenderingEngine::getDisplayDensity();
m_camera_yaw_change -= dir_free.X * d;
m_camera_pitch_change += dir_free.Y * d;

// update camera_yaw and camera_pitch
m_camera_yaw_change -= dir_free.X * d;
m_camera_pitch_change += dir_free.Y * d;
}
if (dir_free_original.getLengthSQ() > touch_threshold_sq)
m_move_has_really_moved = true;
}

if (m_has_joystick_id && event.TouchInput.ID == m_joystick_id) {
Expand Down
4 changes: 3 additions & 1 deletion src/gui/touchscreengui.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ class TouchScreenGUI
// apply joystick status
void applyJoystickStatus();

// array for saving last known position of a pointer
// stores the original position of each pointer
std::unordered_map<size_t, v2s32> m_pointer_downpos;
// stores the last known position of each pointer
std::unordered_map<size_t, v2s32> m_pointer_pos;

// settings bar
Expand Down

0 comments on commit 53dc7f6

Please sign in to comment.