From 321896142cb86934ac6a758c21878bff41601a07 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Wed, 7 Mar 2018 19:52:15 -0300 Subject: [PATCH 01/13] 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); } } From 4c3ee195de5535ff0e19a637b45539ffd199b992 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Thu, 8 Mar 2018 19:58:15 -0300 Subject: [PATCH 02/13] Android - hide joystick when opening the Avatar window and disable it in cases is hidden (it was working with ui windows in front). --- .../input-plugins/TouchscreenVirtualPadDevice.cpp | 12 ++++++------ scripts/system/+android/avatarSelection.js | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index a5c6df0dba..809d553a8f 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -228,7 +228,7 @@ void TouchscreenVirtualPadDevice::touchBeginEvent(const QTouchEvent* event) { // touch begin here is a big begin -> begins both pads? maybe it does nothing debugPoints(event, " BEGIN ++++++++++++++++"); auto& virtualPadManager = VirtualPad::Manager::instance(); - if (!virtualPadManager.isEnabled()) { + if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { return; } KeyboardMouseDevice::enableTouch(false); @@ -236,7 +236,7 @@ void TouchscreenVirtualPadDevice::touchBeginEvent(const QTouchEvent* event) { void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) { auto& virtualPadManager = VirtualPad::Manager::instance(); - if (!virtualPadManager.isEnabled()) { + if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { touchLeftEnd(); touchRightEnd(); return; @@ -252,7 +252,7 @@ void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) { void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { auto& virtualPadManager = VirtualPad::Manager::instance(); - if (!virtualPadManager.isEnabled()) { + if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { touchLeftEnd(); touchRightEnd(); return; @@ -309,7 +309,7 @@ bool TouchscreenVirtualPadDevice::touchLeftBeginPointIsValid(glm::vec2 touchPoin void TouchscreenVirtualPadDevice::touchLeftBegin(glm::vec2 touchPoint) { auto& virtualPadManager = VirtualPad::Manager::instance(); - if (virtualPadManager.isEnabled()) { + if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { if (_fixedPosition) { _firstTouchLeftPoint = _fixedCenterPosition; } else { @@ -333,7 +333,7 @@ void TouchscreenVirtualPadDevice::touchLeftEnd() { void TouchscreenVirtualPadDevice::touchRightBegin(glm::vec2 touchPoint) { auto& virtualPadManager = VirtualPad::Manager::instance(); - if (virtualPadManager.isEnabled()) { + if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { _firstTouchRightPoint = touchPoint; _validTouchRight = true; } @@ -353,7 +353,7 @@ void TouchscreenVirtualPadDevice::touchRightEnd() { void TouchscreenVirtualPadDevice::touchGestureEvent(const QGestureEvent* event) { auto& virtualPadManager = VirtualPad::Manager::instance(); - if (!virtualPadManager.isEnabled()) { + if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { return; } if (QGesture* gesture = event->gesture(Qt::PinchGesture)) { diff --git a/scripts/system/+android/avatarSelection.js b/scripts/system/+android/avatarSelection.js index be58f61ac2..d87a57dfa9 100644 --- a/scripts/system/+android/avatarSelection.js +++ b/scripts/system/+android/avatarSelection.js @@ -34,6 +34,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See App.openUrl("https://metaverse.highfidelity.com/marketplace?category=avatars"); break; case 'hide': + Controller.setVPadHidden(false); module.exports.onHidden(); break; default: @@ -122,18 +123,21 @@ module.exports = { init(); }, show: function() { + Controller.setVPadHidden(true); if (window) { window.setVisible(true); isVisible = true; } }, hide: function() { + Controller.setVPadHidden(false); if (window) { window.setVisible(false); } isVisible = false; }, destroy: function() { + Controller.setVPadHidden(false); if (window) { window.fromQml.disconnect(fromQml); window.close(); @@ -155,5 +159,7 @@ module.exports = { refreshSelectedAvatar: function(currentAvatarURL) { refreshSelected(currentAvatarURL); }, - onHidden: function() { } + onHidden: function() { + Controller.setVPadHidden(false); + } }; From 3d933e1810fa6c4cb549f9da9004f3da53ea0a3b Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Fri, 9 Mar 2018 17:41:05 -0300 Subject: [PATCH 03/13] Android - Joystick hidden when opening login and shown after Cancel. --- interface/resources/qml/+android/LoginDialog.qml | 4 +++- .../resources/qml/LoginDialog/+android/LinkAccountBody.qml | 2 +- scripts/system/+android/avatarSelection.js | 2 -- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/resources/qml/+android/LoginDialog.qml b/interface/resources/qml/+android/LoginDialog.qml index 9eb2c74147..7753e9937d 100644 --- a/interface/resources/qml/+android/LoginDialog.qml +++ b/interface/resources/qml/+android/LoginDialog.qml @@ -38,7 +38,8 @@ ModalWindow { keyboardOverride: true // Disable ModalWindow's keyboard. function tryDestroy() { - root.destroy() + Controller.setVPadHidden(false); + root.destroy(); } LoginDialog { @@ -54,6 +55,7 @@ ModalWindow { this.anchors.centerIn = undefined; this.y=150; this.x=(parent.width - this.width)/2; + Controller.setVPadHidden(true); } Keys.onPressed: { diff --git a/interface/resources/qml/LoginDialog/+android/LinkAccountBody.qml b/interface/resources/qml/LoginDialog/+android/LinkAccountBody.qml index 7eced0c751..38e65af4ca 100644 --- a/interface/resources/qml/LoginDialog/+android/LinkAccountBody.qml +++ b/interface/resources/qml/LoginDialog/+android/LinkAccountBody.qml @@ -224,7 +224,7 @@ Item { onClicked: { Qt.inputMethod.hide(); - root.destroy(); + root.tryDestroy(); } } } diff --git a/scripts/system/+android/avatarSelection.js b/scripts/system/+android/avatarSelection.js index d87a57dfa9..2b28fe2c9b 100644 --- a/scripts/system/+android/avatarSelection.js +++ b/scripts/system/+android/avatarSelection.js @@ -115,8 +115,6 @@ module.exports = { qml: "hifi/avatarSelection.qml", visible: false }); - /*, - visible: false*/ if (window) { window.fromQml.connect(fromQml); } From f0e68ecffa641df8182865c7150a3532ae849ec4 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Fri, 9 Mar 2018 20:33:06 -0300 Subject: [PATCH 04/13] Android - Touch to rotate inverted X and Y axis and less sensitive. --- interface/resources/controllers/touchscreenvirtualpad.json | 4 ++-- .../src/input-plugins/TouchscreenVirtualPadDevice.cpp | 2 +- .../src/input-plugins/TouchscreenVirtualPadDevice.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/resources/controllers/touchscreenvirtualpad.json b/interface/resources/controllers/touchscreenvirtualpad.json index 8c21044c3b..772bbff39a 100644 --- a/interface/resources/controllers/touchscreenvirtualpad.json +++ b/interface/resources/controllers/touchscreenvirtualpad.json @@ -5,8 +5,8 @@ { "from": "TouchscreenVirtualPad.LX", "when": "!Application.CameraIndependent", "filters": { "type": "deadZone", "min": 0.05 }, "to": "Actions.TranslateX" }, - { "from": "TouchscreenVirtualPad.RX", "when": "!Application.CameraIndependent", "filters": { "type": "deadZone", "min": 0.05 }, "to": "Actions.Yaw" }, + { "from": "TouchscreenVirtualPad.RX", "when": "!Application.CameraIndependent", "filters": [ {"type": "deadZone", "min": 0.05} , "invert" ], "to": "Actions.Yaw" }, - { "from": "TouchscreenVirtualPad.RY", "when": "!Application.CameraIndependent", "to": "Actions.Pitch" } + { "from": "TouchscreenVirtualPad.RY", "when": "!Application.CameraIndependent", "filters": [ "invert" ], "to": "Actions.Pitch" } ] } diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index 809d553a8f..8690726db3 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -185,7 +185,7 @@ void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller // NOW BETWEEN -1 1 rightDistanceScaleX /= STICK_RADIUS_INCHES; - rightDistanceScaleY /= STICK_RADIUS_INCHES; + rightDistanceScaleY /= STICK_RADIUS_INCHES*2; // pitch is slower _inputDevice->_axisStateMap[controller::RX] = rightDistanceScaleX; _inputDevice->_axisStateMap[controller::RY] = rightDistanceScaleY; diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h index d5019da805..fe13abdd08 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h @@ -20,7 +20,7 @@ class QTouchEvent; class QGestureEvent; -const float STICK_RADIUS_INCHES = .3f; +const float STICK_RADIUS_INCHES = 1.0f; class TouchscreenVirtualPadDevice : public InputPlugin { Q_OBJECT From b24e57431533b74a7f76c96a83b0e916d68735c1 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Sat, 10 Mar 2018 00:15:19 -0300 Subject: [PATCH 05/13] TouchscreenVirtualPadDevice rename of variables related to movement or view controls instead of left-right controls --- .../TouchscreenVirtualPadDevice.cpp | 154 ++++++++---------- .../TouchscreenVirtualPadDevice.h | 36 ++-- 2 files changed, 87 insertions(+), 103 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index 8690726db3..5fca665bcf 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -73,8 +73,8 @@ void TouchscreenVirtualPadDevice::setupFixedCenter(VirtualPad::Manager& virtualP QScreen* eventScreen = qApp->primaryScreen(); // do not call every time _fixedCenterPosition = glm::vec2( _fixedRadius + margin, eventScreen->size().height() - margin - _fixedRadius - _extraBottomMargin); - _firstTouchLeftPoint = _fixedCenterPosition; - virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint); + _moveRefTouchPoint = _fixedCenterPosition; + virtualPadManager.getLeftVirtualPad()->setFirstTouch(_moveRefTouchPoint); } float clip(float n, float lower, float upper) { @@ -116,42 +116,32 @@ glm::vec2 TouchscreenVirtualPadDevice::clippedPointInCircle(float radius, glm::v return vec2(finalX, finalY); } -void TouchscreenVirtualPadDevice::processInputUseCircleMethod(VirtualPad::Manager& virtualPadManager) { - vec2 clippedPoint = clippedPointInCircle(_fixedRadiusForCalc, _firstTouchLeftPoint, _currentTouchLeftPoint); +void TouchscreenVirtualPadDevice::processInputDeviceForMove(VirtualPad::Manager& virtualPadManager) { + vec2 clippedPoint = clippedPointInCircle(_fixedRadiusForCalc, _moveRefTouchPoint, _moveCurrentTouchPoint); - _inputDevice->_axisStateMap[controller::LX] = (clippedPoint.x - _firstTouchLeftPoint.x) / _fixedRadiusForCalc; - _inputDevice->_axisStateMap[controller::LY] = (clippedPoint.y - _firstTouchLeftPoint.y) / _fixedRadiusForCalc; + _inputDevice->_axisStateMap[controller::LX] = (clippedPoint.x - _moveRefTouchPoint.x) / _fixedRadiusForCalc; + _inputDevice->_axisStateMap[controller::LY] = (clippedPoint.y - _moveRefTouchPoint.y) / _fixedRadiusForCalc; - virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint); + virtualPadManager.getLeftVirtualPad()->setFirstTouch(_moveRefTouchPoint); virtualPadManager.getLeftVirtualPad()->setCurrentTouch(clippedPoint); virtualPadManager.getLeftVirtualPad()->setBeingTouched(true); virtualPadManager.getLeftVirtualPad()->setShown(true); // If touched, show in any mode (fixed joystick position or non-fixed) } -void TouchscreenVirtualPadDevice::processInputUseSquareMethod(VirtualPad::Manager& virtualPadManager) { - float leftDistanceScaleX, leftDistanceScaleY; - leftDistanceScaleX = (_currentTouchLeftPoint.x - _firstTouchLeftPoint.x) / _screenDPIScale.x; - leftDistanceScaleY = (_currentTouchLeftPoint.y - _firstTouchLeftPoint.y) / _screenDPIScale.y; +void TouchscreenVirtualPadDevice::processInputDeviceForView() { + float rightDistanceScaleX, rightDistanceScaleY; + rightDistanceScaleX = (_viewCurrentTouchPoint.x - _viewRefTouchPoint.x) / _screenDPIScale.x; + rightDistanceScaleY = (_viewCurrentTouchPoint.y - _viewRefTouchPoint.y) / _screenDPIScale.y; - leftDistanceScaleX = clip(leftDistanceScaleX, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES); - leftDistanceScaleY = clip(leftDistanceScaleY, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES); + rightDistanceScaleX = clip(rightDistanceScaleX, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES); + rightDistanceScaleY = clip(rightDistanceScaleY, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES); // NOW BETWEEN -1 1 - leftDistanceScaleX /= STICK_RADIUS_INCHES; - leftDistanceScaleY /= STICK_RADIUS_INCHES; + rightDistanceScaleX /= STICK_RADIUS_INCHES; + rightDistanceScaleY /= STICK_RADIUS_INCHES*2; // pitch is slower - _inputDevice->_axisStateMap[controller::LX] = leftDistanceScaleX; - _inputDevice->_axisStateMap[controller::LY] = leftDistanceScaleY; - - /* Shared variables for stick rendering (clipped to the stick radius)*/ - // Prevent this for being done when not in first person view - virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint); - virtualPadManager.getLeftVirtualPad()->setCurrentTouch( - glm::vec2(clip(_currentTouchLeftPoint.x, -STICK_RADIUS_INCHES * _screenDPIScale.x + _firstTouchLeftPoint.x, STICK_RADIUS_INCHES * _screenDPIScale.x + _firstTouchLeftPoint.x), - clip(_currentTouchLeftPoint.y, -STICK_RADIUS_INCHES * _screenDPIScale.y + _firstTouchLeftPoint.y, STICK_RADIUS_INCHES * _screenDPIScale.y + _firstTouchLeftPoint.y)) - ); - virtualPadManager.getLeftVirtualPad()->setBeingTouched(true); - virtualPadManager.getLeftVirtualPad()->setShown(true); // If touched, show in any mode (fixed joystick position or non-fixed) + _inputDevice->_axisStateMap[controller::RX] = rightDistanceScaleX; + _inputDevice->_axisStateMap[controller::RY] = rightDistanceScaleY; } void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { @@ -163,8 +153,8 @@ void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller auto& virtualPadManager = VirtualPad::Manager::instance(); setupFixedCenter(virtualPadManager); - if (_validTouchLeft) { - processInputUseCircleMethod(virtualPadManager); + if (_moveHasValidTouch) { + processInputDeviceForMove(virtualPadManager); } else { virtualPadManager.getLeftVirtualPad()->setBeingTouched(false); if (_fixedPosition) { @@ -175,20 +165,8 @@ void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller } } - if (_validTouchRight) { - float rightDistanceScaleX, rightDistanceScaleY; - rightDistanceScaleX = (_currentTouchRightPoint.x - _firstTouchRightPoint.x) / _screenDPIScale.x; - rightDistanceScaleY = (_currentTouchRightPoint.y - _firstTouchRightPoint.y) / _screenDPIScale.y; - - rightDistanceScaleX = clip(rightDistanceScaleX, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES); - rightDistanceScaleY = clip(rightDistanceScaleY, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES); - - // NOW BETWEEN -1 1 - rightDistanceScaleX /= STICK_RADIUS_INCHES; - rightDistanceScaleY /= STICK_RADIUS_INCHES*2; // pitch is slower - - _inputDevice->_axisStateMap[controller::RX] = rightDistanceScaleX; - _inputDevice->_axisStateMap[controller::RY] = rightDistanceScaleY; + if (_viewHasValidTouch) { + processInputDeviceForView(); } } @@ -237,67 +215,67 @@ void TouchscreenVirtualPadDevice::touchBeginEvent(const QTouchEvent* event) { void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) { auto& virtualPadManager = VirtualPad::Manager::instance(); if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { - touchLeftEnd(); - touchRightEnd(); + moveTouchEnd(); + viewTouchEnd(); return; } // touch end here is a big reset -> resets both pads _touchPointCount = 0; KeyboardMouseDevice::enableTouch(true); debugPoints(event, " END ----------------"); - touchLeftEnd(); - touchRightEnd(); + moveTouchEnd(); + viewTouchEnd(); _inputDevice->_axisStateMap.clear(); } void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { auto& virtualPadManager = VirtualPad::Manager::instance(); if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { - touchLeftEnd(); - touchRightEnd(); + moveTouchEnd(); + viewTouchEnd(); return; } _touchPointCount = event->touchPoints().count(); const QList& tPoints = event->touchPoints(); - bool leftTouchFound = false; - bool rightTouchFound = false; + bool moveTouchFound = false; + bool viewTouchFound = false; glm::vec2 thisPoint; for (int i = 0; i < _touchPointCount; ++i) { 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) { + // movew touch and the first one detected counts + if (thisPoint.x < _screenWidthCenter && !moveTouchFound) { + if (_moveHasValidTouch) { // valid if it's an ongoing touch - leftTouchFound = true; - 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 + moveTouchFound = true; + moveTouchUpdate(thisPoint); + } else if (moveTouchBeginIsValid(thisPoint)) { + // starting point should be valid + moveTouchFound = true; + moveTouchBegin(thisPoint); + } // if it wasn't even a valid starting point, it won't count as a valid movement touch } else if (thisPoint.x >= _screenWidthCenter) { // right side - if (!rightTouchFound) { - rightTouchFound = true; - if (!_validTouchRight) { - touchRightBegin(thisPoint); + if (!viewTouchFound) { + viewTouchFound = true; + if (!_viewHasValidTouch) { + viewTouchBegin(thisPoint); } else { // as we don't have a stick on the right side, there is no condition to process right touch - touchRightUpdate(thisPoint); + viewTouchUpdate(thisPoint); } } } } - if (!leftTouchFound) { - touchLeftEnd(); + if (!moveTouchFound) { + moveTouchEnd(); } - if (!rightTouchFound) { - touchRightEnd(); + if (!viewTouchFound) { + viewTouchEnd(); } } -bool TouchscreenVirtualPadDevice::touchLeftBeginPointIsValid(glm::vec2 touchPoint) { +bool TouchscreenVirtualPadDevice::moveTouchBeginIsValid(glm::vec2 touchPoint) { if (_fixedPosition) { // inside circle return pow(touchPoint.x - _fixedCenterPosition.x,2.0) + pow(touchPoint.y - _fixedCenterPosition.y, 2.0) < pow(_fixedRadius, 2.0); @@ -307,45 +285,45 @@ bool TouchscreenVirtualPadDevice::touchLeftBeginPointIsValid(glm::vec2 touchPoin } } -void TouchscreenVirtualPadDevice::touchLeftBegin(glm::vec2 touchPoint) { +void TouchscreenVirtualPadDevice::moveTouchBegin(glm::vec2 touchPoint) { auto& virtualPadManager = VirtualPad::Manager::instance(); if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { if (_fixedPosition) { - _firstTouchLeftPoint = _fixedCenterPosition; + _moveRefTouchPoint = _fixedCenterPosition; } else { - _firstTouchLeftPoint = touchPoint; + _moveRefTouchPoint = touchPoint; } - _validTouchLeft = true; + _moveHasValidTouch = true; } } -void TouchscreenVirtualPadDevice::touchLeftUpdate(glm::vec2 touchPoint) { - _currentTouchLeftPoint = touchPoint; +void TouchscreenVirtualPadDevice::moveTouchUpdate(glm::vec2 touchPoint) { + _moveCurrentTouchPoint = touchPoint; } -void TouchscreenVirtualPadDevice::touchLeftEnd() { - if (_validTouchLeft) { // do stuff once - _validTouchLeft = false; +void TouchscreenVirtualPadDevice::moveTouchEnd() { + if (_moveHasValidTouch) { // do stuff once + _moveHasValidTouch = false; _inputDevice->_axisStateMap[controller::LX] = 0; _inputDevice->_axisStateMap[controller::LY] = 0; } } -void TouchscreenVirtualPadDevice::touchRightBegin(glm::vec2 touchPoint) { +void TouchscreenVirtualPadDevice::viewTouchBegin(glm::vec2 touchPoint) { auto& virtualPadManager = VirtualPad::Manager::instance(); if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { - _firstTouchRightPoint = touchPoint; - _validTouchRight = true; + _viewRefTouchPoint = touchPoint; + _viewHasValidTouch = true; } } -void TouchscreenVirtualPadDevice::touchRightUpdate(glm::vec2 touchPoint) { - _currentTouchRightPoint = touchPoint; +void TouchscreenVirtualPadDevice::viewTouchUpdate(glm::vec2 touchPoint) { + _viewCurrentTouchPoint = touchPoint; } -void TouchscreenVirtualPadDevice::touchRightEnd() { - if (_validTouchRight) { // do stuff once - _validTouchRight = false; +void TouchscreenVirtualPadDevice::viewTouchEnd() { + if (_viewHasValidTouch) { // do stuff once + _viewHasValidTouch = false; _inputDevice->_axisStateMap[controller::RX] = 0; _inputDevice->_axisStateMap[controller::RY] = 0; } diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h index fe13abdd08..72cd695051 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h @@ -67,12 +67,15 @@ protected: float _screenDPI; qreal _screenDPIProvided; glm::vec2 _screenDPIScale; - bool _validTouchLeft; - glm::vec2 _firstTouchLeftPoint; - glm::vec2 _currentTouchLeftPoint; - bool _validTouchRight; - glm::vec2 _firstTouchRightPoint; - glm::vec2 _currentTouchRightPoint; + + bool _moveHasValidTouch; + glm::vec2 _moveRefTouchPoint; + glm::vec2 _moveCurrentTouchPoint; + + bool _viewHasValidTouch; + glm::vec2 _viewRefTouchPoint; + glm::vec2 _viewCurrentTouchPoint; + int _touchPointCount; int _screenWidthCenter; std::shared_ptr _inputDevice { std::make_shared() }; @@ -83,18 +86,21 @@ protected: float _fixedRadiusForCalc; int _extraBottomMargin {0}; - void touchLeftBegin(glm::vec2 touchPoint); - void touchLeftUpdate(glm::vec2 touchPoint); - void touchLeftEnd(); - bool touchLeftBeginPointIsValid(glm::vec2 touchPoint); - void touchRightBegin(glm::vec2 touchPoint); - void touchRightUpdate(glm::vec2 touchPoint); - void touchRightEnd(); + void moveTouchBegin(glm::vec2 touchPoint); + void moveTouchUpdate(glm::vec2 touchPoint); + void moveTouchEnd(); + bool moveTouchBeginIsValid(glm::vec2 touchPoint); + + void viewTouchBegin(glm::vec2 touchPoint); + void viewTouchUpdate(glm::vec2 touchPoint); + void viewTouchEnd(); + void setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force = false); - void processInputUseCircleMethod(VirtualPad::Manager& virtualPadManager); - void processInputUseSquareMethod(VirtualPad::Manager& virtualPadManager); + void processInputDeviceForMove(VirtualPad::Manager& virtualPadManager); glm::vec2 clippedPointInCircle(float radius, glm::vec2 origin, glm::vec2 touchPoint); + + void processInputDeviceForView(); // just for debug private: void debugPoints(const QTouchEvent* event, QString who); From 67ae6aee33f1217a2021b16d0221163166a17236 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Sat, 10 Mar 2018 01:30:44 -0300 Subject: [PATCH 06/13] Joystick behaviour according to spec: Movement starts on joystick, rotation starts from anywhere else --- .../TouchscreenVirtualPadDevice.cpp | 80 +++++++++++++------ .../TouchscreenVirtualPadDevice.h | 3 + 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index 5fca665bcf..2bc5d374af 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -240,41 +240,71 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { const QList& tPoints = event->touchPoints(); bool moveTouchFound = false; bool viewTouchFound = false; + + int idxMoveStartingPointCandidate = -1; + int idxViewStartingPointCandidate = -1; + + bool thisPointConsumed = false; glm::vec2 thisPoint; for (int i = 0; i < _touchPointCount; ++i) { thisPoint.x = tPoints[i].pos().x(); thisPoint.y = tPoints[i].pos().y(); - // movew touch and the first one detected counts - if (thisPoint.x < _screenWidthCenter && !moveTouchFound) { - if (_moveHasValidTouch) { - // valid if it's an ongoing touch - moveTouchFound = true; - moveTouchUpdate(thisPoint); - } else if (moveTouchBeginIsValid(thisPoint)) { - // starting point should be valid - moveTouchFound = true; - moveTouchBegin(thisPoint); - } // if it wasn't even a valid starting point, it won't count as a valid movement touch - } else if (thisPoint.x >= _screenWidthCenter) { // right side - if (!viewTouchFound) { - viewTouchFound = true; - if (!_viewHasValidTouch) { - viewTouchBegin(thisPoint); - } else { - // as we don't have a stick on the right side, there is no condition to process right touch - viewTouchUpdate(thisPoint); - } - } + thisPointConsumed = false; + + if (!moveTouchFound && _moveHasValidTouch && _moveCurrentTouchId == tPoints[i].id()) { + // valid if it's an ongoing touch + moveTouchFound = true; + moveTouchUpdate(thisPoint); + thisPointConsumed = true; + } + + if (thisPointConsumed) continue; + + if (!viewTouchFound && _viewHasValidTouch && _viewCurrentTouchId == tPoints[i].id()) { + // valid if it's an ongoing touch + viewTouchFound = true; + viewTouchUpdate(thisPoint); + thisPointConsumed = true; + } + + if (thisPointConsumed) continue; + + if (!moveTouchFound && idxMoveStartingPointCandidate==-1 && moveTouchBeginIsValid(thisPoint)) { + idxMoveStartingPointCandidate = i; + thisPointConsumed = true; + } + + if (thisPointConsumed) continue; + + if (!viewTouchFound && idxViewStartingPointCandidate==-1 && viewTouchBeginIsValid(thisPoint)) { + idxViewStartingPointCandidate = i; + thisPointConsumed = true; + } + + } + + if (!moveTouchFound) { + if (idxMoveStartingPointCandidate!=-1) { + _moveCurrentTouchId = tPoints[idxMoveStartingPointCandidate].id(); + moveTouchBegin(thisPoint); + } else { + moveTouchEnd(); } } - if (!moveTouchFound) { - moveTouchEnd(); - } if (!viewTouchFound) { - viewTouchEnd(); + if (idxViewStartingPointCandidate!=-1) { + _viewCurrentTouchId = tPoints[idxViewStartingPointCandidate].id(); + viewTouchBegin(thisPoint); + } else { + viewTouchEnd(); + } } } +bool TouchscreenVirtualPadDevice::viewTouchBeginIsValid(glm::vec2 touchPoint) { + return !moveTouchBeginIsValid(touchPoint); +} + bool TouchscreenVirtualPadDevice::moveTouchBeginIsValid(glm::vec2 touchPoint) { if (_fixedPosition) { // inside circle diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h index 72cd695051..a25f0db7b1 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h @@ -71,10 +71,12 @@ protected: bool _moveHasValidTouch; glm::vec2 _moveRefTouchPoint; glm::vec2 _moveCurrentTouchPoint; + int _moveCurrentTouchId; bool _viewHasValidTouch; glm::vec2 _viewRefTouchPoint; glm::vec2 _viewCurrentTouchPoint; + int _viewCurrentTouchId; int _touchPointCount; int _screenWidthCenter; @@ -94,6 +96,7 @@ protected: void viewTouchBegin(glm::vec2 touchPoint); void viewTouchUpdate(glm::vec2 touchPoint); void viewTouchEnd(); + bool viewTouchBeginIsValid(glm::vec2 touchPoint); void setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force = false); From b87a07a7d09cb3fe56f8c84019351910c4481054 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Mon, 12 Mar 2018 14:55:20 -0300 Subject: [PATCH 07/13] Android - Improve View controller making it like a drag rather than like a joystick (reference touch is updated at every frame and is not only the initial touch anymore) --- interface/resources/controllers/touchscreenvirtualpad.json | 2 +- .../src/input-plugins/TouchscreenVirtualPadDevice.cpp | 6 +++++- .../src/input-plugins/TouchscreenVirtualPadDevice.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/interface/resources/controllers/touchscreenvirtualpad.json b/interface/resources/controllers/touchscreenvirtualpad.json index 772bbff39a..907ff8b403 100644 --- a/interface/resources/controllers/touchscreenvirtualpad.json +++ b/interface/resources/controllers/touchscreenvirtualpad.json @@ -7,6 +7,6 @@ { "from": "TouchscreenVirtualPad.RX", "when": "!Application.CameraIndependent", "filters": [ {"type": "deadZone", "min": 0.05} , "invert" ], "to": "Actions.Yaw" }, - { "from": "TouchscreenVirtualPad.RY", "when": "!Application.CameraIndependent", "filters": [ "invert" ], "to": "Actions.Pitch" } + { "from": "TouchscreenVirtualPad.RY", "when": "!Application.CameraIndependent", "filters": [ {"type": "deadZone", "min": 0.05}, "invert" ], "to": "Actions.Pitch" } ] } diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index 2bc5d374af..7f9caf193a 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -138,10 +138,13 @@ void TouchscreenVirtualPadDevice::processInputDeviceForView() { // NOW BETWEEN -1 1 rightDistanceScaleX /= STICK_RADIUS_INCHES; - rightDistanceScaleY /= STICK_RADIUS_INCHES*2; // pitch is slower + rightDistanceScaleY /= STICK_RADIUS_INCHES; _inputDevice->_axisStateMap[controller::RX] = rightDistanceScaleX; _inputDevice->_axisStateMap[controller::RY] = rightDistanceScaleY; + + // after use, save last touch point as ref + _viewRefTouchPoint = _viewCurrentTouchPoint; } void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { @@ -343,6 +346,7 @@ void TouchscreenVirtualPadDevice::viewTouchBegin(glm::vec2 touchPoint) { auto& virtualPadManager = VirtualPad::Manager::instance(); if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { _viewRefTouchPoint = touchPoint; + _viewCurrentTouchPoint = touchPoint; _viewHasValidTouch = true; } } diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h index a25f0db7b1..3f94dfef07 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h @@ -20,7 +20,7 @@ class QTouchEvent; class QGestureEvent; -const float STICK_RADIUS_INCHES = 1.0f; +const float STICK_RADIUS_INCHES = .3f; class TouchscreenVirtualPadDevice : public InputPlugin { Q_OBJECT From b8c0f4d6862a29396450b7cb4ed327c4b4a74912 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Tue, 13 Mar 2018 12:52:26 -0300 Subject: [PATCH 08/13] Android joystick - Enforce validity of touches to the ones that start in their area of activation (Movement only from joystick area, View only from outside joystick area). --- .../TouchscreenVirtualPadDevice.cpp | 47 +++++++++++++++++-- .../TouchscreenVirtualPadDevice.h | 10 ++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index 7f9caf193a..f9a712a70d 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -224,6 +224,7 @@ void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) { } // touch end here is a big reset -> resets both pads _touchPointCount = 0; + _unusedTouches.clear(); KeyboardMouseDevice::enableTouch(true); debugPoints(event, " END ----------------"); moveTouchEnd(); @@ -231,6 +232,25 @@ void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) { _inputDevice->_axisStateMap.clear(); } +void TouchscreenVirtualPadDevice::processUnusedTouches(std::map unusedTouchesInEvent) { + std::vector touchesToDelete; + for (auto const& touchEntry : _unusedTouches) { + if (!unusedTouchesInEvent.count(touchEntry.first)) { + touchesToDelete.push_back(touchEntry.first); + } + } + for (int touchToDelete : touchesToDelete) { + _unusedTouches.erase(touchToDelete); + } + + for (auto const& touchEntry : unusedTouchesInEvent) { + if (!_unusedTouches.count(touchEntry.first)) { + _unusedTouches[touchEntry.first] = touchEntry.second; + } + } + +} + void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { auto& virtualPadManager = VirtualPad::Manager::instance(); if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { @@ -249,12 +269,16 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { bool thisPointConsumed = false; glm::vec2 thisPoint; + int thisPointId; + std::map unusedTouchesInEvent; + for (int i = 0; i < _touchPointCount; ++i) { thisPoint.x = tPoints[i].pos().x(); thisPoint.y = tPoints[i].pos().y(); + thisPointId = tPoints[i].id(); thisPointConsumed = false; - if (!moveTouchFound && _moveHasValidTouch && _moveCurrentTouchId == tPoints[i].id()) { + if (!moveTouchFound && _moveHasValidTouch && _moveCurrentTouchId == thisPointId) { // valid if it's an ongoing touch moveTouchFound = true; moveTouchUpdate(thisPoint); @@ -263,7 +287,7 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { if (thisPointConsumed) continue; - if (!viewTouchFound && _viewHasValidTouch && _viewCurrentTouchId == tPoints[i].id()) { + if (!viewTouchFound && _viewHasValidTouch && _viewCurrentTouchId == thisPointId) { // valid if it's an ongoing touch viewTouchFound = true; viewTouchUpdate(thisPoint); @@ -272,23 +296,36 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { if (thisPointConsumed) continue; - if (!moveTouchFound && idxMoveStartingPointCandidate==-1 && moveTouchBeginIsValid(thisPoint)) { + if (!moveTouchFound && idxMoveStartingPointCandidate==-1 && moveTouchBeginIsValid(thisPoint) && + (!_unusedTouches.count(thisPointId) || _unusedTouches[thisPointId] == MOVE )) { idxMoveStartingPointCandidate = i; thisPointConsumed = true; } if (thisPointConsumed) continue; - if (!viewTouchFound && idxViewStartingPointCandidate==-1 && viewTouchBeginIsValid(thisPoint)) { + if (!viewTouchFound && idxViewStartingPointCandidate==-1 && viewTouchBeginIsValid(thisPoint) && + (!_unusedTouches.count(thisPointId) || _unusedTouches[thisPointId] == VIEW )) { idxViewStartingPointCandidate = i; thisPointConsumed = true; } + if (thisPointConsumed) continue; + + if (moveTouchBeginIsValid(thisPoint)) { + unusedTouchesInEvent[thisPointId] = MOVE; + } else if (viewTouchBeginIsValid(thisPoint)) { + unusedTouchesInEvent[thisPointId] = VIEW; + } + } + processUnusedTouches(unusedTouchesInEvent); + if (!moveTouchFound) { if (idxMoveStartingPointCandidate!=-1) { _moveCurrentTouchId = tPoints[idxMoveStartingPointCandidate].id(); + _unusedTouches.erase(_moveCurrentTouchId); moveTouchBegin(thisPoint); } else { moveTouchEnd(); @@ -297,11 +334,13 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { if (!viewTouchFound) { if (idxViewStartingPointCandidate!=-1) { _viewCurrentTouchId = tPoints[idxViewStartingPointCandidate].id(); + _unusedTouches.erase(_viewCurrentTouchId); viewTouchBegin(thisPoint); } else { viewTouchEnd(); } } + } bool TouchscreenVirtualPadDevice::viewTouchBeginIsValid(glm::vec2 touchPoint) { diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h index 3f94dfef07..c0f37e2e51 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h @@ -62,6 +62,12 @@ public: const std::shared_ptr& getInputDevice() const { return _inputDevice; } protected: + + enum TouchType { + MOVE = 1, + VIEW + }; + float _lastPinchScale; float _pinchScale; float _screenDPI; @@ -78,6 +84,8 @@ protected: glm::vec2 _viewCurrentTouchPoint; int _viewCurrentTouchId; + std::map _unusedTouches; + int _touchPointCount; int _screenWidthCenter; std::shared_ptr _inputDevice { std::make_shared() }; @@ -103,6 +111,8 @@ protected: void processInputDeviceForMove(VirtualPad::Manager& virtualPadManager); glm::vec2 clippedPointInCircle(float radius, glm::vec2 origin, glm::vec2 touchPoint); + void processUnusedTouches(std::map unusedTouchesInEvent); + void processInputDeviceForView(); // just for debug private: From a3811c2844fd05039d54449c3b82312ca1ded8b9 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Tue, 13 Mar 2018 15:56:13 -0300 Subject: [PATCH 09/13] Coding style corrections --- .../resources/qml/+android/LoginDialog.qml | 4 ++-- .../TouchscreenVirtualPadDevice.cpp | 23 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/interface/resources/qml/+android/LoginDialog.qml b/interface/resources/qml/+android/LoginDialog.qml index 7753e9937d..567cca9bcf 100644 --- a/interface/resources/qml/+android/LoginDialog.qml +++ b/interface/resources/qml/+android/LoginDialog.qml @@ -53,8 +53,8 @@ ModalWindow { Component.onCompleted: { this.anchors.centerIn = undefined; - this.y=150; - this.x=(parent.width - this.width)/2; + this.y = 150; + this.x = (parent.width - this.width) / 2; Controller.setVPadHidden(true); } diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index f9a712a70d..dad311ef27 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -282,36 +282,29 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { // valid if it's an ongoing touch moveTouchFound = true; moveTouchUpdate(thisPoint); - thisPointConsumed = true; + continue; } - if (thisPointConsumed) continue; - if (!viewTouchFound && _viewHasValidTouch && _viewCurrentTouchId == thisPointId) { // valid if it's an ongoing touch viewTouchFound = true; viewTouchUpdate(thisPoint); - thisPointConsumed = true; + continue; } - if (thisPointConsumed) continue; - - if (!moveTouchFound && idxMoveStartingPointCandidate==-1 && moveTouchBeginIsValid(thisPoint) && + if (!moveTouchFound && idxMoveStartingPointCandidate == -1 && moveTouchBeginIsValid(thisPoint) && (!_unusedTouches.count(thisPointId) || _unusedTouches[thisPointId] == MOVE )) { idxMoveStartingPointCandidate = i; - thisPointConsumed = true; + continue; } - if (thisPointConsumed) continue; - - if (!viewTouchFound && idxViewStartingPointCandidate==-1 && viewTouchBeginIsValid(thisPoint) && + if (!viewTouchFound && idxViewStartingPointCandidate == -1 && viewTouchBeginIsValid(thisPoint) && (!_unusedTouches.count(thisPointId) || _unusedTouches[thisPointId] == VIEW )) { idxViewStartingPointCandidate = i; thisPointConsumed = true; + continue; } - if (thisPointConsumed) continue; - if (moveTouchBeginIsValid(thisPoint)) { unusedTouchesInEvent[thisPointId] = MOVE; } else if (viewTouchBeginIsValid(thisPoint)) { @@ -323,7 +316,7 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { processUnusedTouches(unusedTouchesInEvent); if (!moveTouchFound) { - if (idxMoveStartingPointCandidate!=-1) { + if (idxMoveStartingPointCandidate != -1) { _moveCurrentTouchId = tPoints[idxMoveStartingPointCandidate].id(); _unusedTouches.erase(_moveCurrentTouchId); moveTouchBegin(thisPoint); @@ -332,7 +325,7 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { } } if (!viewTouchFound) { - if (idxViewStartingPointCandidate!=-1) { + if (idxViewStartingPointCandidate != -1) { _viewCurrentTouchId = tPoints[idxViewStartingPointCandidate].id(); _unusedTouches.erase(_viewCurrentTouchId); viewTouchBegin(thisPoint); From 80abe1865ac2467dfe7cfc6bd8e89a554b92efeb Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Wed, 14 Mar 2018 16:22:24 -0300 Subject: [PATCH 10/13] Remove unused variable thisPointConsumed --- .../src/input-plugins/TouchscreenVirtualPadDevice.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index dad311ef27..223775b222 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -267,7 +267,6 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { int idxMoveStartingPointCandidate = -1; int idxViewStartingPointCandidate = -1; - bool thisPointConsumed = false; glm::vec2 thisPoint; int thisPointId; std::map unusedTouchesInEvent; @@ -276,7 +275,6 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { thisPoint.x = tPoints[i].pos().x(); thisPoint.y = tPoints[i].pos().y(); thisPointId = tPoints[i].id(); - thisPointConsumed = false; if (!moveTouchFound && _moveHasValidTouch && _moveCurrentTouchId == thisPointId) { // valid if it's an ongoing touch @@ -301,7 +299,6 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) { if (!viewTouchFound && idxViewStartingPointCandidate == -1 && viewTouchBeginIsValid(thisPoint) && (!_unusedTouches.count(thisPointId) || _unusedTouches[thisPointId] == VIEW )) { idxViewStartingPointCandidate = i; - thisPointConsumed = true; continue; } From 379fa9783f73c1c06905ff9c81523487a477cac2 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Wed, 14 Mar 2018 19:09:21 -0300 Subject: [PATCH 11/13] No touch responsibility for KeyboardMouseDevice when TouchscreenVirtualPadDevice is initialized --- .../src/input-plugins/TouchscreenVirtualPadDevice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index 223775b222..55f06a9f4d 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -60,6 +60,8 @@ void TouchscreenVirtualPadDevice::init() { if (_fixedPosition) { virtualPadManager.getLeftVirtualPad()->setShown(virtualPadManager.isEnabled() && !virtualPadManager.isHidden()); // Show whenever it's enabled } + + KeyboardMouseDevice::enableTouch(false); // Touch for view controls is managed by this plugin } void TouchscreenVirtualPadDevice::setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force) { @@ -212,7 +214,6 @@ void TouchscreenVirtualPadDevice::touchBeginEvent(const QTouchEvent* event) { if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) { return; } - KeyboardMouseDevice::enableTouch(false); } void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) { @@ -225,7 +226,6 @@ void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) { // touch end here is a big reset -> resets both pads _touchPointCount = 0; _unusedTouches.clear(); - KeyboardMouseDevice::enableTouch(true); debugPoints(event, " END ----------------"); moveTouchEnd(); viewTouchEnd(); From f8f5655561cc1b60ec2f17e5e0a9c4fc4d7d56d8 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Thu, 15 Mar 2018 17:10:14 -0300 Subject: [PATCH 12/13] Android view control sensitivity increased. Constant replaced for a private value member. --- .../src/input-plugins/TouchscreenVirtualPadDevice.cpp | 8 ++++---- .../src/input-plugins/TouchscreenVirtualPadDevice.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp index 55f06a9f4d..fb536e65ca 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.cpp @@ -135,12 +135,12 @@ void TouchscreenVirtualPadDevice::processInputDeviceForView() { rightDistanceScaleX = (_viewCurrentTouchPoint.x - _viewRefTouchPoint.x) / _screenDPIScale.x; rightDistanceScaleY = (_viewCurrentTouchPoint.y - _viewRefTouchPoint.y) / _screenDPIScale.y; - rightDistanceScaleX = clip(rightDistanceScaleX, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES); - rightDistanceScaleY = clip(rightDistanceScaleY, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES); + rightDistanceScaleX = clip(rightDistanceScaleX, -_viewStickRadiusInches, _viewStickRadiusInches); + rightDistanceScaleY = clip(rightDistanceScaleY, -_viewStickRadiusInches, _viewStickRadiusInches); // NOW BETWEEN -1 1 - rightDistanceScaleX /= STICK_RADIUS_INCHES; - rightDistanceScaleY /= STICK_RADIUS_INCHES; + rightDistanceScaleX /= _viewStickRadiusInches; + rightDistanceScaleY /= _viewStickRadiusInches; _inputDevice->_axisStateMap[controller::RX] = rightDistanceScaleX; _inputDevice->_axisStateMap[controller::RY] = rightDistanceScaleY; diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h index c0f37e2e51..77b129f058 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h @@ -20,8 +20,6 @@ class QTouchEvent; class QGestureEvent; -const float STICK_RADIUS_INCHES = .3f; - class TouchscreenVirtualPadDevice : public InputPlugin { Q_OBJECT public: @@ -96,6 +94,8 @@ protected: float _fixedRadiusForCalc; int _extraBottomMargin {0}; + float _viewStickRadiusInches {0.17495f}; // agreed default + void moveTouchBegin(glm::vec2 touchPoint); void moveTouchUpdate(glm::vec2 touchPoint); void moveTouchEnd(); From e29fc9b46136d106f9d89f360b75ccd03e452def Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Fri, 16 Mar 2018 16:28:58 -0300 Subject: [PATCH 13/13] Android - Rotate View control increased sensitivity --- .../src/input-plugins/TouchscreenVirtualPadDevice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h index 77b129f058..3540c6d909 100644 --- a/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h +++ b/libraries/input-plugins/src/input-plugins/TouchscreenVirtualPadDevice.h @@ -94,7 +94,7 @@ protected: float _fixedRadiusForCalc; int _extraBottomMargin {0}; - float _viewStickRadiusInches {0.17495f}; // agreed default + float _viewStickRadiusInches {0.1333f}; // agreed default void moveTouchBegin(glm::vec2 touchPoint); void moveTouchUpdate(glm::vec2 touchPoint);