From 8f362861eb19a8fd636c1c6d52b252615877f77d Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 31 Jan 2017 16:53:25 -0800 Subject: [PATCH 1/5] tablet-ui: button icon images now work with http urls. --- interface/resources/qml/hifi/tablet/TabletButton.qml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/TabletButton.qml b/interface/resources/qml/hifi/tablet/TabletButton.qml index 9ad8d1476c..c6c810d25e 100644 --- a/interface/resources/qml/hifi/tablet/TabletButton.qml +++ b/interface/resources/qml/hifi/tablet/TabletButton.qml @@ -75,6 +75,14 @@ Item { source: buttonOutline } + function urlHelper(src) { + if (src.match(/\bhttp/)) { + return src; + } else { + return "../../../" + src; + } + } + Image { id: icon width: 50 @@ -84,7 +92,7 @@ Item { anchors.bottomMargin: 5 anchors.horizontalCenter: parent.horizontalCenter fillMode: Image.Stretch - source: "../../../" + tabletButton.icon + source: tabletButton.urlHelper(tabletButton.icon) } ColorOverlay { @@ -185,7 +193,7 @@ Item { PropertyChanges { target: icon - source: "../../../" + tabletButton.activeIcon + source: tabletButton.urlHelper(tabletButton.activeIcon) } }, State { From cf855391af34d47a44e0ca5e46a7b9da534701c2 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 31 Jan 2017 16:54:15 -0800 Subject: [PATCH 2/5] Added jsdocs for all button properties --- .../script-engine/src/TabletScriptingInterface.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libraries/script-engine/src/TabletScriptingInterface.h b/libraries/script-engine/src/TabletScriptingInterface.h index b0b2d00e0f..0b7829c7fb 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -119,7 +119,7 @@ public: * @param msg {object|string} */ Q_INVOKABLE void emitScriptEvent(QVariant msg); - + Q_INVOKABLE bool onHomeScreen(); QObject* getTabletSurface(); @@ -170,14 +170,14 @@ public: /**jsdoc * Returns the current value of this button's properties * @function TabletButtonProxy#getProperties - * @returns {object} + * @returns {ButtonProperties} */ Q_INVOKABLE QVariantMap getProperties() const; /**jsdoc * Replace the values of some of this button's properties * @function TabletButtonProxy#editProperties - * @param properties {object} set of properties to change + * @param {ButtonProperties} properties - set of properties to change */ Q_INVOKABLE void editProperties(QVariantMap properties); @@ -199,4 +199,13 @@ protected: QVariantMap _properties; }; +/**jsdoc + * @typedef TabletButtonProxy.ButtonProperties + * @property {string} text - button caption + * @property {string} icon - url to button icon. (50 x 50) + * @property {string} activeText - button caption when button is active + * @property {string} activeIcon - url to button icon used when button is active. (50 x 50) + * @property {string} isActive - true when button is active. + */ + #endif // hifi_TabletScriptingInterface_h From c147b9bec0672aa9253c406ab0a2f75005906adc Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 31 Jan 2017 18:00:18 -0800 Subject: [PATCH 3/5] Fix for tablets in third-person HMD mode. --- scripts/system/libraries/WebTablet.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 65551b2140..edb637d9a2 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -198,6 +198,11 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { _this.geometryChanged(geometry); }; Window.geometryChanged.connect(this.myGeometryChanged); + + this.myCameraModeChanged = function(newMode) { + _this.cameraModeChanged(newMode); + }; + Camera.modeUpdated.connect(this.myCameraModeChanged); }; WebTablet.prototype.setHomeButtonTexture = function() { @@ -228,6 +233,7 @@ WebTablet.prototype.destroy = function () { Controller.mouseReleaseEvent.disconnect(this.myMouseReleaseEvent); Window.geometryChanged.disconnect(this.myGeometryChanged); + Camera.modeUpdated.disconnect(this.myCameraModeChanged); }; WebTablet.prototype.geometryChanged = function (geometry) { @@ -370,6 +376,19 @@ WebTablet.prototype.mousePressEvent = function (event) { } }; +WebTablet.prototype.cameraModeChanged = function (newMode) { + // reposition the tablet, after a small delay. + // This allows HMD.position to reflect the new camera mode. + var self = this; + Script.setTimeout(function () { + var NO_HANDS = -1; + var tabletProperties = {}; + // compute position, rotation & parentJointIndex of the tablet + self.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties); + Entities.editEntity(self.tabletEntityID, tabletProperties); + }, 10); +}; + function rayIntersectPlane(planePosition, planeNormal, rayStart, rayDirection) { var rayDirectionDotPlaneNormal = Vec3.dot(rayDirection, planeNormal); if (rayDirectionDotPlaneNormal > 0.00001 || rayDirectionDotPlaneNormal < -0.00001) { From 008a58f9d708e00ce4d8de9de1d9ff70805bb903 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 31 Jan 2017 18:03:48 -0800 Subject: [PATCH 4/5] Only reposition the tablet when camera mode changes, in HMD mode. --- scripts/system/libraries/WebTablet.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index edb637d9a2..52912337a1 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -379,14 +379,16 @@ WebTablet.prototype.mousePressEvent = function (event) { WebTablet.prototype.cameraModeChanged = function (newMode) { // reposition the tablet, after a small delay. // This allows HMD.position to reflect the new camera mode. - var self = this; - Script.setTimeout(function () { - var NO_HANDS = -1; - var tabletProperties = {}; - // compute position, rotation & parentJointIndex of the tablet - self.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties); - Entities.editEntity(self.tabletEntityID, tabletProperties); - }, 10); + if (HMD.active) { + var self = this; + Script.setTimeout(function () { + var NO_HANDS = -1; + var tabletProperties = {}; + // compute position, rotation & parentJointIndex of the tablet + self.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties); + Entities.editEntity(self.tabletEntityID, tabletProperties); + }, 10); + } }; function rayIntersectPlane(planePosition, planeNormal, rayStart, rayDirection) { From 3c04f54e7509b08c36eff7311f16a3f6b636c391 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 31 Jan 2017 18:22:38 -0800 Subject: [PATCH 5/5] more fixes to third person tablet usage. --- scripts/system/libraries/WebTablet.js | 31 +++++++++++++-------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 52912337a1..75ca2e514f 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -24,6 +24,7 @@ var CAMERA_MATRIX = -7; var ROT_Y_180 = {x: 0, y: 1, z: 0, w: 0}; var TABLET_TEXTURE_RESOLUTION = { x: 480, y: 706 }; var INCHES_TO_METERS = 1 / 39.3701; +var NO_HANDS = -1; var TABLET_URL = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx"; @@ -35,18 +36,21 @@ var TABLET_MODEL_PATH = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-wi // * position - position in front of the user // * rotation - rotation of entity so it faces the user. function calcSpawnInfo(hand, height) { - var noHands = -1; var finalPosition; - if (HMD.active && hand !== noHands) { + + var headPos = (HMD.active && Camera.mode === "first person") ? HMD.position : Camera.position; + var headRot = (HMD.active && Camera.mode === "first person") ? HMD.orientation : Camera.orientation; + + if (HMD.active && hand !== NO_HANDS) { var handController = getControllerWorldLocation(hand, true); var controllerPosition = handController.position; // compute the angle of the chord with length (height / 2) - var theta = Math.asin(height / (2 * Vec3.distance(HMD.position, controllerPosition))); + var theta = Math.asin(height / (2 * Vec3.distance(headPos, controllerPosition))); // then we can use this angle to rotate the vector between the HMD position and the center of the tablet. // this vector, u, will become our new look at direction. - var d = Vec3.normalize(Vec3.subtract(HMD.position, controllerPosition)); + var d = Vec3.normalize(Vec3.subtract(headPos, controllerPosition)); var w = Vec3.normalize(Vec3.cross(Y_AXIS, d)); var q = Quat.angleAxis(theta * (180 / Math.PI), w); var u = Vec3.multiplyQbyV(q, d); @@ -64,8 +68,8 @@ function calcSpawnInfo(hand, height) { rotation: lookAtRot }; } else { - var front = Quat.getFront(Camera.orientation); - finalPosition = Vec3.sum(Camera.position, Vec3.multiply(0.6, front)); + var front = Quat.getFront(headRot); + finalPosition = Vec3.sum(headPos, Vec3.multiply(0.6, front)); var orientation = Quat.lookAt({x: 0, y: 0, z: 0}, front, {x: 0, y: 1, z: 0}); return { position: finalPosition, @@ -238,7 +242,6 @@ WebTablet.prototype.destroy = function () { WebTablet.prototype.geometryChanged = function (geometry) { if (!HMD.active) { - var NO_HANDS = -1; var tabletProperties = {}; // compute position, rotation & parentJointIndex of the tablet this.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties); @@ -294,7 +297,6 @@ WebTablet.prototype.onHmdChanged = function () { Controller.mouseReleaseEvent.connect(this.myMouseReleaseEvent); } - var NO_HANDS = -1; var tabletProperties = {}; // compute position, rotation & parentJointIndex of the tablet this.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties); @@ -377,17 +379,14 @@ WebTablet.prototype.mousePressEvent = function (event) { }; WebTablet.prototype.cameraModeChanged = function (newMode) { - // reposition the tablet, after a small delay. + // reposition the tablet. // This allows HMD.position to reflect the new camera mode. if (HMD.active) { var self = this; - Script.setTimeout(function () { - var NO_HANDS = -1; - var tabletProperties = {}; - // compute position, rotation & parentJointIndex of the tablet - self.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties); - Entities.editEntity(self.tabletEntityID, tabletProperties); - }, 10); + var tabletProperties = {}; + // compute position, rotation & parentJointIndex of the tablet + self.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties); + Entities.editEntity(self.tabletEntityID, tabletProperties); } };