From f81402fb0faca55edf933daf181be6f7657e5507 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Wed, 4 Jan 2017 17:34:22 +0000 Subject: [PATCH] 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);