From de5f0ad987acaecbe1c34429394f751e6193d201 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 13 Sep 2017 12:01:41 -0700 Subject: [PATCH] WebTablet.js: calcSpawnInfo works more consistently. --- scripts/system/libraries/WebTablet.js | 13 +++++++++---- scripts/system/tablet-ui/tabletUI.js | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 71d3a14845..bbc8d1268f 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -42,7 +42,7 @@ var LOCAL_TABLET_MODEL_PATH = Script.resourcesPath() + "meshes/tablet-with-home- // returns object with two fields: // * position - position in front of the user // * rotation - rotation of entity so it faces the user. -function calcSpawnInfo(hand, height, landscape) { +function calcSpawnInfo(hand, landscape) { var finalPosition; var headPos = (HMD.active && Camera.mode === "first person") ? HMD.position : Camera.position; @@ -76,7 +76,12 @@ function calcSpawnInfo(hand, height, landscape) { var TABLET_RAKE_ANGLE = 30; rotation = Quat.multiply(Quat.angleAxis(TABLET_RAKE_ANGLE, Vec3.multiplyQbyV(lookAt, Vec3.UNIT_X)), lookAt); + var sensorScaleFactor = MyAvatar.sensorToWorldScale; + var tabletWidth = getTabletWidthFromSettings() * sensorScaleFactor; + var tabletScaleFactor = tabletWidth / TABLET_NATURAL_DIMENSIONS.x; + var height = TABLET_NATURAL_DIMENSIONS.y * tabletScaleFactor; var RELATIVE_SPAWN_OFFSET = { x: 0, y: 0.6 * height, z: 0.1 * height }; + position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, RELATIVE_SPAWN_OFFSET)); return { @@ -320,7 +325,7 @@ WebTablet.prototype.destroy = function () { WebTablet.prototype.geometryChanged = function (geometry) { if (!HMD.active) { - var tabletProperties = { dimensions: Overlays.getProperty(HMD.tabletID, "dimensions") }; + var tabletProperties = {}; // compute position, rotation & parentJointIndex of the tablet this.calculateTabletAttachmentProperties(NO_HANDS, false, tabletProperties); Overlays.editOverlay(HMD.tabletID, tabletProperties); @@ -397,7 +402,7 @@ WebTablet.prototype.calculateTabletAttachmentProperties = function (hand, useMou tabletProperties.parentJointIndex = SENSOR_TO_ROOM_MATRIX; // compute the appropriate position of the tablet, near the hand controller that was used to spawn it. - var spawnInfo = calcSpawnInfo(hand, tabletProperties.dimensions.y, this.landscape); + var spawnInfo = calcSpawnInfo(hand, this.landscape); tabletProperties.position = spawnInfo.position; tabletProperties.rotation = spawnInfo.rotation; } else { @@ -420,7 +425,7 @@ WebTablet.prototype.calculateTabletAttachmentProperties = function (hand, useMou }; WebTablet.prototype.onHmdChanged = function () { - var tabletProperties = { dimensions: Overlays.getProperty(HMD.tabletID, "dimensions") }; + var tabletProperties = {}; // compute position, rotation & parentJointIndex of the tablet this.calculateTabletAttachmentProperties(NO_HANDS, false, tabletProperties); Overlays.editOverlay(HMD.tabletID, tabletProperties); diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index 4fedd4354c..e52d0b530b 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -120,7 +120,7 @@ if (debugTablet) { print("TABLET in showTabletUI, already rezzed"); } - var tabletProperties = { dimensions: Overlays.getProperty(HMD.tabletID, "dimensions") }; + var tabletProperties = {}; UIWebTablet.calculateTabletAttachmentProperties(activeHand, true, tabletProperties); tabletProperties.visible = true; Overlays.editOverlay(HMD.tabletID, tabletProperties);