diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index 97dfe1e80f..458dc64983 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) { ; @@ -88,8 +88,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 +101,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 +171,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..265ff48fd5 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -109,9 +109,9 @@ signals: */ void webEventReceived(QVariant msg); -protected: - +private slots: void addButtonsToHomeScreen(); +protected: void removeButtonsFromHomeScreen(); QQuickItem* getQmlTablet() const; 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..42fbbe106a 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -10,28 +10,31 @@ 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}; -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. -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,18 +43,18 @@ 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; 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; 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); @@ -96,7 +93,7 @@ WebTablet = function (url, width, dpi, location, 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", 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);