prevent accidental dragging by locking cursor in place while mouse movement is small

This commit is contained in:
Crispy 2023-05-01 18:21:28 +02:00
parent 0b7f841fbf
commit 8b7a3e0067
3 changed files with 17 additions and 7 deletions

View file

@ -142,6 +142,7 @@ void App::InitRootOverlay()
_root_overlay.SetWidth(0.25f);
_root_overlay.SetTransformWorld(&root_start_pose);
_root_overlay.SetTextureToColor(110, 30, 190);
_root_overlay.SetHidden(true);
}
void App::Update(float dtime)

View file

@ -7,7 +7,8 @@
const float LASER_WIDTH = 0.004f;
const Color EDIT_COLOR{1, 0.6f, 1};
const Color CURSOR_COLOR{0.3f, 1, 1};
const float SCROLL_SPEED = 48.0f;
const float SCROLL_SPEED = 48;
const float MOUSE_DRAG_THRESHOLD = 48;
Controller::Controller(App *app, ControllerSide side)
{
@ -16,8 +17,6 @@ Controller::Controller(App *app, ControllerSide side)
_input_handle = 0;
_is_connected = false;
_side = side;
_cursor_active = false;
_last_sent_scroll = 0;
std::string laser_name = "controller_laser_";
if (side == ControllerSide::Left)
@ -126,7 +125,6 @@ void Controller::Update(float dtime)
}
if (_cursor_active)
{
// printf("update cursor on hand %d\n", _side);
if (_last_ray.overlay != nullptr && _last_ray.hit_panel != nullptr)
{
auto pos = glm::vec2(_last_ray.local_pos.x, _last_ray.local_pos.y);
@ -139,7 +137,15 @@ void Controller::Update(float dtime)
pos.y += 0.5f * _last_ray.overlay->Ratio();
pos *= _last_ray.hit_panel->Width();
_last_ray.hit_panel->SetCursor(pos.x, pos.y);
if (glm::length(pos - _last_set_mouse_pos) > MOUSE_DRAG_THRESHOLD)
{
_mouse_drag_lock = false;
}
if (!_mouse_drag_lock)
{
_last_ray.hit_panel->SetCursor(pos.x, pos.y);
_last_set_mouse_pos = pos;
}
}
UpdateMouseButton(_app->_input_handles.cursor.mouse_left, 1);
UpdateMouseButton(_app->_input_handles.cursor.mouse_middle, 2);
@ -173,6 +179,7 @@ void Controller::UpdateMouseButton(vr::VRActionHandle_t binding, unsigned int bu
if (state.bChanged)
{
_app->SendMouseInput(button, state.bState);
_mouse_drag_lock = state.bState;
}
}

View file

@ -28,7 +28,7 @@ class Controller
void Update(float dtime);
bool _cursor_active;
bool _cursor_active = false;
private:
void UpdateStatus();
@ -50,5 +50,7 @@ class Controller
glm::vec3 _last_rotation;
glm::vec3 _last_pos;
float _last_sent_scroll;
float _last_sent_scroll = 0;
bool _mouse_drag_lock = false;
glm::vec2 _last_set_mouse_pos;
};