From 321896142cb86934ac6a758c21878bff41601a07 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Wed, 7 Mar 2018 19:52:15 -0300 Subject: [PATCH] Android - Make it possible to look around and move with touchscreen controls. Zoom-in not in 'My View' mode. --- .../src/input-plugins/InputPlugin.cpp | 3 ++- .../TouchscreenVirtualPadDevice.cpp | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/InputPlugin.cpp b/libraries/input-plugins/src/input-plugins/InputPlugin.cpp index 96f1daba8c..6f94e7592c 100644 --- a/libraries/input-plugins/src/input-plugins/InputPlugin.cpp +++ b/libraries/input-plugins/src/input-plugins/InputPlugin.cpp @@ -20,9 +20,10 @@ InputPluginList getInputPlugins() { InputPlugin* PLUGIN_POOL[] = { new KeyboardMouseDevice(), - new TouchscreenDevice(), #if defined(Q_OS_ANDROID) new TouchscreenVirtualPadDevice(), +#else + new TouchscreenDevice(), // Touchscreen and Controller Scripts take care on Android #endif nullptr }; diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index e323ed8fbc..a5c6df0dba 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -262,22 +262,28 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { const QList& tPoints = event->touchPoints(); bool leftTouchFound = false; bool rightTouchFound = false; + glm::vec2 thisPoint; for (int i = 0; i < _touchPointCount; ++i) { - glm::vec2 thisPoint(tPoints[i].pos().x(), tPoints[i].pos().y()); - if (_validTouchLeft) { - leftTouchFound = true; - touchLeftUpdate(thisPoint); - } else if (touchLeftBeginPointIsValid(thisPoint)) { - if (!leftTouchFound) { + thisPoint.x = tPoints[i].pos().x(); + thisPoint.y = tPoints[i].pos().y(); + // left side and the first one detected counts + if (thisPoint.x < _screenWidthCenter && !leftTouchFound) { + if (_validTouchLeft) { + // valid if it's an ongoing touch leftTouchFound = true; - touchLeftBegin(thisPoint); - } - } else { + touchLeftUpdate(thisPoint); + } else if (touchLeftBeginPointIsValid(thisPoint)) { + // valid if it's start point is valid + leftTouchFound = true; + touchLeftBegin(thisPoint); + } // if it wasn't even a valid starting point, it won't count as left touch valid + } else if (thisPoint.x >= _screenWidthCenter) { // right side if (!rightTouchFound) { rightTouchFound = true; if (!_validTouchRight) { touchRightBegin(thisPoint); } else { + // as we don't have a stick on the right side, there is no condition to process right touch touchRightUpdate(thisPoint); } }