From c49c947984ba05c2f50be1dc7f8427fd96a2d1aa Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Fri, 1 Sep 2023 23:43:22 +0200 Subject: [PATCH] Fixed llack of precision in mouse look mode --- interface/src/Application.cpp | 3 +++ .../src/input-plugins/KeyboardMouseDevice.cpp | 10 +++++++--- .../src/input-plugins/KeyboardMouseDevice.h | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 35df55ddf2..0ca518d44d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6326,6 +6326,9 @@ void Application::update(float deltaTime) { if (QCursor::pos() != point) { _mouseCaptureTarget = point; _ignoreMouseMove = true; + if (_captureMouse) { + _keyboardMouseDevice->updateMousePositionForCapture(QCursor::pos(), _mouseCaptureTarget); + } QCursor::setPos(point); } } diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp index 88994ddd92..b0bf8198fc 100644 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp @@ -113,14 +113,18 @@ void KeyboardMouseDevice::eraseMouseClicked() { _inputDevice->_buttonPressedMap.erase(_inputDevice->makeInput(Qt::RightButton, true).getChannel()); } +void KeyboardMouseDevice::updateMousePositionForCapture(QPoint globalPos, QPointF captureTarget) { + if (!isNaN(captureTarget.x())) { + QPointF change = globalPos - captureTarget; + _accumulatedMove += QPoint(change.x(), change.y()); + } +} + void KeyboardMouseDevice::mouseMoveEvent(QMouseEvent* event, bool capture, QPointF captureTarget) { QPoint currentPos = event->pos(); if (!capture) { _accumulatedMove += currentPos - _lastCursor; - } else if (!isNaN(captureTarget.x())) { - QPointF change = event->globalPos() - captureTarget; - _accumulatedMove += QPoint(change.x(), change.y()); } // FIXME - this has the characteristic that it will show large jumps when you move the cursor diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h index 216194a712..d33ced6a47 100644 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h @@ -93,6 +93,9 @@ public: void wheelEvent(QWheelEvent* event); bool isWheelByTouchPad(QWheelEvent* event); + // This gets called from Application::update just before resetting cursor position when mouse capture is enabled + void updateMousePositionForCapture(QPoint globalPos, QPointF captureTarget); + static void enableTouch(bool enableTouch) { _enableTouch = enableTouch; } static const char* NAME;