From a30ad2709bdd69a87057b3c3739875a8ce5fc7a5 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 4 Jan 2017 00:17:16 +0000 Subject: [PATCH 1/5] Home button fix --- .../script-engine/src/TabletScriptingInterface.cpp | 11 +++++++++-- .../script-engine/src/TabletScriptingInterface.h | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index 97dfe1e80f..f2639f9f2a 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -44,7 +44,7 @@ void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qm static const char* TABLET_SOURCE_URL = "Tablet.qml"; static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml"; -static const char* LOADER_SOURCE_PROPERTY_NAME = "loaderSource"; +static const char* LOADER_SOURCE_PROPERTY_NAME = "LoaderSource"; TabletProxy::TabletProxy(QString name) : _name(name) { ; @@ -79,6 +79,8 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr if (_qmlTabletRoot && _qmlOffscreenSurface) { QObject::connect(_qmlOffscreenSurface, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant))); gotoHomeScreen(); + //auto loader = _qmlTabletRoot->findChild("loader"); + //QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen())); } else { removeButtonsFromHomeScreen(); } @@ -88,8 +90,10 @@ void TabletProxy::gotoHomeScreen() { if (_qmlTabletRoot) { QString tabletSource = _qmlTabletRoot->property(LOADER_SOURCE_PROPERTY_NAME).toString(); if (tabletSource != TABLET_SOURCE_URL) { + _qmlTabletRoot->setProperty(LOADER_SOURCE_PROPERTY_NAME, TABLET_SOURCE_URL); + auto loader = _qmlTabletRoot->findChild("loader"); + QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen())); QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL))); - addButtonsToHomeScreen(); } } } @@ -99,6 +103,7 @@ void TabletProxy::gotoWebScreen(const QString& url) { removeButtonsFromHomeScreen(); QString tabletSource = _qmlTabletRoot->property(LOADER_SOURCE_PROPERTY_NAME).toString(); if (tabletSource != WEB_VIEW_SOURCE_URL) { + _qmlTabletRoot->setProperty(LOADER_SOURCE_PROPERTY_NAME, WEB_VIEW_SOURCE_URL); QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL))); // TABLET_UI_HACK: TODO: addEventBridge to tablet.... } @@ -168,6 +173,8 @@ void TabletProxy::addButtonsToHomeScreen() { for (auto& buttonProxy : _tabletButtonProxies) { addButtonProxyToQmlTablet(tablet, buttonProxy.data()); } + auto loader = _qmlTabletRoot->findChild("loader"); + QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen())); } void TabletProxy::removeButtonsFromHomeScreen() { diff --git a/libraries/script-engine/src/TabletScriptingInterface.h b/libraries/script-engine/src/TabletScriptingInterface.h index 7268a3520c..cc8b38ebff 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -109,9 +109,11 @@ signals: */ void webEventReceived(QVariant msg); -protected: - +private slots: void addButtonsToHomeScreen(); + +protected: + void removeButtonsFromHomeScreen(); QQuickItem* getQmlTablet() const; From f81402fb0faca55edf933daf181be6f7657e5507 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 4 Jan 2017 17:34:22 +0000 Subject: [PATCH 2/5] improved tablet position --- .../controllers/handControllerPointer.js | 2 ++ scripts/system/libraries/WebTablet.js | 31 +++++++++---------- scripts/system/tablet-ui/tabletUI.js | 10 +++++- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/scripts/system/controllers/handControllerPointer.js b/scripts/system/controllers/handControllerPointer.js index 0623ddf100..507b93f834 100644 --- a/scripts/system/controllers/handControllerPointer.js +++ b/scripts/system/controllers/handControllerPointer.js @@ -437,12 +437,14 @@ clickMapping.from(function () { return wantsMenu; }).to(Controller.Actions.Conte clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(function (clicked) { if (clicked) { activeHudPoint2d(Controller.Standard.RightHand); + Messages.sendLocalMessage("toggleHand", Controller.Standard.RightHand); } wantsMenu = clicked; }); clickMapping.from(Controller.Standard.LeftSecondaryThumb).peek().to(function (clicked) { if (clicked) { activeHudPoint2d(Controller.Standard.LeftHand); + Messages.sendLocalMessage("toggleHand", Controller.Standard.LeftHand); } wantsMenu = clicked; }); diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index b169a644bb..c6fc7b58f2 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -10,6 +10,7 @@ Script.include(Script.resolvePath("../libraries/utils.js")); +Script.include(Script.resolvePath("../libraries/controllers.js")); var RAD_TO_DEG = 180 / Math.PI; var X_AXIS = {x: 1, y: 0, z: 0}; var Y_AXIS = {x: 0, y: 1, z: 0}; @@ -20,18 +21,20 @@ var TABLET_URL = "https://s3.amazonaws.com/hifi-public/tony/tablet.fbx"; // returns object with two fields: // * position - position in front of the user // * rotation - rotation of entity so it faces the user. -function calcSpawnInfo() { - var front; +function calcSpawnInfo(hand) { var pitchBackRotation = Quat.angleAxis(20.0, X_AXIS); if (HMD.active) { - front = Quat.getFront(HMD.orientation); - var yawOnlyRotation = Quat.angleAxis(Math.atan2(front.x, front.z) * RAD_TO_DEG, Y_AXIS); + var handController = getControllerWorldLocation(hand, false); + var front = Quat.getFront(handController.orientation); + var up = Quat.getUp(handController.orientation); + var frontOffset = Vec3.sum(handController.position, Vec3.multiply(0.4, up)); + var finalOffset = Vec3.sum(frontOffset, Vec3.multiply(-0.3, front)); return { - position: Vec3.sum(Vec3.sum(HMD.position, Vec3.multiply(0.6, front)), Vec3.multiply(-0.5, Y_AXIS)), - rotation: Quat.multiply(yawOnlyRotation, pitchBackRotation) + position: finalOffset, + rotation: Quat.lookAt(finalOffset, HMD.position, Y_AXIS) }; } else { - front = Quat.getFront(MyAvatar.orientation); + var front = Quat.getFront(MyAvatar.orientation); return { position: Vec3.sum(Vec3.sum(MyAvatar.position, Vec3.multiply(0.6, front)), {x: 0, y: 0.6, z: 0}), rotation: Quat.multiply(MyAvatar.orientation, pitchBackRotation) @@ -40,7 +43,7 @@ function calcSpawnInfo() { } // ctor -WebTablet = function (url, width, dpi, location, clientOnly) { +WebTablet = function (url, width, dpi, hand, clientOnly) { var _this = this; var ASPECT = 4.0 / 3.0; @@ -51,7 +54,7 @@ WebTablet = function (url, width, dpi, location, clientOnly) { var DPI = dpi || DEFAULT_DPI; var SENSOR_TO_ROOM_MATRIX = -2; - var spawnInfo = calcSpawnInfo(); + var spawnInfo = calcSpawnInfo(hand); var tabletEntityPosition = spawnInfo.position; var tabletEntityRotation = spawnInfo.rotation; @@ -67,14 +70,8 @@ WebTablet = function (url, width, dpi, location, clientOnly) { parentJointIndex: SENSOR_TO_ROOM_MATRIX } - if (location) { - tabletProperties.localPosition = location.localPosition; - tabletProperties.localRotation = location.localRotation; - } else { - var spawnInfo = calcSpawnInfo(); - tabletProperties.position = spawnInfo.position; - tabletProperties.rotation = spawnInfo.rotation; - } + tabletProperties.position = spawnInfo.position; + tabletProperties.rotation = spawnInfo.rotation; this.tabletEntityID = Entities.addEntity(tabletProperties, clientOnly); diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index 4c365836a2..4f2b5ed94a 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -17,13 +17,14 @@ (function() { // BEGIN LOCAL_SCOPE var tabletShown = false; var tabletLocation = null; + var activeHand = null; Script.include("../libraries/WebTablet.js"); function showTabletUI() { tabletShown = true; print("show tablet-ui"); - UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml", null, null, tabletLocation); + UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml", null, null, activeHand); UIWebTablet.register(); HMD.tabletID = UIWebTablet.webEntityID; } @@ -52,6 +53,13 @@ } } + function toggleHand(channel, hand, senderUUID, localOnly) { + activeHand = JSON.parse(hand); + } + + Messages.subscribe("toggleHand"); + Messages.messageReceived.connect(toggleHand); + Script.update.connect(updateShowTablet); // Script.setInterval(updateShowTablet, 1000); From 3f34cb863e0c853e2dcfba6ba120ba41e3174036 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 4 Jan 2017 17:40:09 +0000 Subject: [PATCH 3/5] removed whitespace --- libraries/script-engine/src/TabletScriptingInterface.h | 2 -- scripts/system/libraries/WebTablet.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/script-engine/src/TabletScriptingInterface.h b/libraries/script-engine/src/TabletScriptingInterface.h index cc8b38ebff..265ff48fd5 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -111,9 +111,7 @@ signals: private slots: void addButtonsToHomeScreen(); - protected: - void removeButtonsFromHomeScreen(); QQuickItem* getQmlTablet() const; diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index c6fc7b58f2..db94b46b8f 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -31,7 +31,7 @@ function calcSpawnInfo(hand) { var finalOffset = Vec3.sum(frontOffset, Vec3.multiply(-0.3, front)); return { position: finalOffset, - rotation: Quat.lookAt(finalOffset, HMD.position, Y_AXIS) + rotation: Quat.lookAt(finalOffset, HMD.position, Y_AXIS) }; } else { var front = Quat.getFront(MyAvatar.orientation); From 4dd8a8aa0dea91b0e44147dedc52988a6edbbbbb Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 4 Jan 2017 19:04:01 +0000 Subject: [PATCH 4/5] added new model --- scripts/system/libraries/WebTablet.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index db94b46b8f..42fbbe106a 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -14,10 +14,10 @@ Script.include(Script.resolvePath("../libraries/controllers.js")); var RAD_TO_DEG = 180 / Math.PI; var X_AXIS = {x: 1, y: 0, z: 0}; var Y_AXIS = {x: 0, y: 1, z: 0}; -var DEFAULT_DPI = 30; -var DEFAULT_WIDTH = 0.5; +var DEFAULT_DPI = 32; +var DEFAULT_WIDTH = 0.43; -var TABLET_URL = "https://s3.amazonaws.com/hifi-public/tony/tablet.fbx"; +var TABLET_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Tablet-Model-v1-x.fbx"; // returns object with two fields: // * position - position in front of the user // * rotation - rotation of entity so it faces the user. @@ -48,7 +48,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { var _this = this; var ASPECT = 4.0 / 3.0; var WIDTH = width || DEFAULT_WIDTH; - var TABLET_HEIGHT_SCALE = 640 / 680; // Screen size of tablet entity isn't quite the desired aspect. + var TABLET_HEIGHT_SCALE = 650 / 680; // Screen size of tablet entity isn't quite the desired aspect. var HEIGHT = WIDTH * ASPECT * TABLET_HEIGHT_SCALE; var DEPTH = 0.025; var DPI = dpi || DEFAULT_DPI; @@ -93,7 +93,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { parentJointIndex: -1 }); - var HOME_BUTTON_Y_OFFSET = -0.32; + var HOME_BUTTON_Y_OFFSET = -0.25; this.homeButtonEntity = Entities.addEntity({ name: "homeButton", type: "Sphere", From 8327df55e4cff454a5aed5c9b8e0f842030d9a26 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 4 Jan 2017 19:21:03 +0000 Subject: [PATCH 5/5] removed commented out code --- libraries/script-engine/src/TabletScriptingInterface.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index f2639f9f2a..458dc64983 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -79,8 +79,6 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr if (_qmlTabletRoot && _qmlOffscreenSurface) { QObject::connect(_qmlOffscreenSurface, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant))); gotoHomeScreen(); - //auto loader = _qmlTabletRoot->findChild("loader"); - //QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen())); } else { removeButtonsFromHomeScreen(); }