summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2016-06-11 15:42:04 +0100
committerSean Harmer <sean.harmer@kdab.com>2016-06-11 18:33:09 +0000
commit71b117154b12a52d25369b29ebababc841d80bca (patch)
tree7a7dc44ca19fcf6483bc9b50b188168de7379eda /src/input
parent76010b7e3733a2c9f0cbf264123d043de2ceed6c (diff)
Avoiding badly quantized axis input values
When moving rapidly Qt may generate multiple mouse events per frame. The old logic was to overwrite the axis values calculated from each mouse event. It is more correct to accumulate the axis values from all events in a frame, which is exactly what this patch does. With this commit, the camera controllers are now much more smooth and feel more natural to control. Change-Id: I50c25609702e5f16e303abf8fb9e7697838f7e2e Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r--src/input/backend/mousedevice.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/input/backend/mousedevice.cpp b/src/input/backend/mousedevice.cpp
index c4dfc1819..376000fce 100644
--- a/src/input/backend/mousedevice.cpp
+++ b/src/input/backend/mousedevice.cpp
@@ -124,14 +124,18 @@ QVector<Qt3DCore::QNodeId> MouseDevice::mouseInputs() const
void MouseDevice::updateMouseEvents(const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> &events)
{
if (!events.isEmpty()) {
+ // Reset axis values before we accumulate new values for this frame
+ m_mouseState.xAxis = 0.0f;
+ m_mouseState.yAxis = 0.0f;
+
for (const QT_PREPEND_NAMESPACE(QMouseEvent) &e : events) {
m_mouseState.leftPressed = e.buttons() & (Qt::LeftButton);
m_mouseState.centerPressed = e.buttons() & (Qt::MiddleButton);
m_mouseState.rightPressed = e.buttons() & (Qt::RightButton);
bool pressed = m_mouseState.leftPressed || m_mouseState.centerPressed || m_mouseState.rightPressed;
if (m_wasPressed && pressed) {
- m_mouseState.xAxis = m_sensitivity * (e.screenPos().x() - m_previousPos.x());
- m_mouseState.yAxis = m_sensitivity * (m_previousPos.y() - e.screenPos().y());
+ m_mouseState.xAxis += m_sensitivity * (e.screenPos().x() - m_previousPos.x());
+ m_mouseState.yAxis += m_sensitivity * (m_previousPos.y() - e.screenPos().y());
}
m_wasPressed = pressed;
m_previousPos = e.screenPos();