Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touchscreen: Camera movement improvements #14301

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/gui/touchscreengui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id)

// By the way: Android reuses pointer IDs, so m_pointer_pos[evt_id]
// will be overwritten soon anyway.
m_pointer_downpos.erase(evt_id);
m_pointer_pos.erase(evt_id);
}

Expand Down Expand Up @@ -808,6 +809,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
}
}

m_pointer_downpos[event.TouchInput.ID] = touch_pos;
m_pointer_pos[event.TouchInput.ID] = touch_pos;
}
else if (event.TouchInput.Event == ETIE_LEFT_UP) {
Expand All @@ -820,27 +822,24 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
m_pointer_pos[event.TouchInput.ID] == touch_pos)
return;

const v2s32 dir_free_original = touch_pos - m_pointer_downpos[event.TouchInput.ID];
const v2s32 free_joystick_center = m_pointer_pos[event.TouchInput.ID];
const v2s32 dir_free = touch_pos - free_joystick_center;

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_move_pos = touch_pos;
m_pointer_pos[event.TouchInput.ID] = touch_pos;
m_move_pos = touch_pos;
m_pointer_pos[event.TouchInput.ID] = touch_pos;

if (m_tap_state == TapState::None || m_draw_crosshair) {
// adapt to similar behavior as pc screen
const double d = g_settings->getFloat("touchscreen_sensitivity", 0.001f, 10.0f) * 3.0f;
// 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
2 changes: 2 additions & 0 deletions src/gui/touchscreengui.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ class TouchScreenGUI
// apply joystick status
void applyJoystickStatus();

// map to store the IDs and original positions of currently pressed pointers
std::unordered_map<size_t, v2s32> m_pointer_downpos;
// map to store the IDs and positions of currently pressed pointers
std::unordered_map<size_t, v2s32> m_pointer_pos;

Expand Down