From 39654779fbfa9ca1015b65c3595623877f7921b4 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 24 May 2017 13:35:00 +1200 Subject: [PATCH 1/6] Position tablet relative to hand --- scripts/system/libraries/WebTablet.js | 33 ++++++++++++--------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 757743accc..88e6ec763b 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -41,7 +41,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) { +function calcSpawnInfo(hand, tabletHeight) { var finalPosition; var headPos = (HMD.active && Camera.mode === "first person") ? HMD.position : Camera.position; @@ -52,29 +52,24 @@ function calcSpawnInfo(hand, height) { } if (HMD.active && hand !== NO_HANDS) { - var handController = getControllerWorldLocation(hand, true); + // Orient tablet per hand orientation. + // Angle it back similar to holding it like a book. + // Move tablet up so that hand is at bottom. + // Move tablet back so that hand is in front. - var TABLET_UP_OFFSET = 0.1; - var TABLET_FORWARD_OFFSET = 0.1; - var normal = Vec3.multiplyQbyV(handController.rotation, {x: 0, y: -1, z: 0}); - var pitch = Math.asin(normal.y); - var MAX_PITCH = Math.PI / 4; - if (pitch < -MAX_PITCH) { - pitch = -MAX_PITCH; - } else if (pitch > MAX_PITCH) { - pitch = MAX_PITCH; + var handController = getControllerWorldLocation(hand, true); + var position = handController.position; + var rotation = handController.rotation; + if (hand === Controller.Standard.LeftHand) { + rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(-60, 90, 0)); + } else { + rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(-60, -90, 0)); } - // rebuild normal from pitch and heading. - var heading = Math.atan2(normal.z, normal.x); - normal = {x: Math.cos(heading), y: Math.sin(pitch), z: Math.sin(heading)}; - - var position = Vec3.sum(handController.position, {x: 0, y: TABLET_UP_OFFSET, z: 0}); - var rotation = Quat.lookAt({x: 0, y: 0, z: 0}, normal, Y_AXIS); - var offset = Vec3.multiplyQbyV(rotation, {x: 0, y: height / 2, z: TABLET_FORWARD_OFFSET}); + position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, { x: 0, y: tabletHeight * 0.4, z: tabletHeight * 0.05 })); return { - position: Vec3.sum(offset, position), + position: position, rotation: rotation }; } else { From 925cca97db51bbfabd30160d15259c0540208591 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 25 May 2017 09:16:17 +1200 Subject: [PATCH 2/6] Make the tablet horizontal --- scripts/system/libraries/WebTablet.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 88e6ec763b..a3090f05e7 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -54,17 +54,21 @@ function calcSpawnInfo(hand, tabletHeight) { if (HMD.active && hand !== NO_HANDS) { // Orient tablet per hand orientation. // Angle it back similar to holding it like a book. + // Make it horizontal. // Move tablet up so that hand is at bottom. // Move tablet back so that hand is in front. var handController = getControllerWorldLocation(hand, true); var position = handController.position; var rotation = handController.rotation; + if (hand === Controller.Standard.LeftHand) { rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(-60, 90, 0)); } else { rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(-60, -90, 0)); } + var eulers = Quat.safeEulerAngles(rotation); + rotation = Quat.fromPitchYawRollDegrees(eulers.x, eulers.y, 0); position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, { x: 0, y: tabletHeight * 0.4, z: tabletHeight * 0.05 })); From 6452e92ac9436b712a47c51aade2b656f5f4917e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 25 May 2017 11:28:26 +1200 Subject: [PATCH 3/6] Hand controller data may not be valid --- scripts/system/libraries/WebTablet.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index a3090f05e7..5168e2340d 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -51,14 +51,18 @@ function calcSpawnInfo(hand, tabletHeight) { hand = NO_HANDS; } + var handController = null; if (HMD.active && hand !== NO_HANDS) { + handController = getControllerWorldLocation(hand, true); + } + + if (handController && handController.valid) { // Orient tablet per hand orientation. // Angle it back similar to holding it like a book. // Make it horizontal. // Move tablet up so that hand is at bottom. // Move tablet back so that hand is in front. - var handController = getControllerWorldLocation(hand, true); var position = handController.position; var rotation = handController.rotation; From f1dca5019a6f79209b167102cd61cdfc12312855 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 25 May 2017 11:48:28 +1200 Subject: [PATCH 4/6] Fix making the tablet horizontal --- scripts/system/libraries/WebTablet.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 5168e2340d..c9918589f6 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -57,9 +57,8 @@ function calcSpawnInfo(hand, tabletHeight) { } if (handController && handController.valid) { - // Orient tablet per hand orientation. + // Orient tablet per hand pitch and yaw. // Angle it back similar to holding it like a book. - // Make it horizontal. // Move tablet up so that hand is at bottom. // Move tablet back so that hand is in front. @@ -67,12 +66,13 @@ function calcSpawnInfo(hand, tabletHeight) { var rotation = handController.rotation; if (hand === Controller.Standard.LeftHand) { - rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(-60, 90, 0)); + rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(0, 90, 0)); } else { - rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(-60, -90, 0)); + rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(0, -90, 0)); } - var eulers = Quat.safeEulerAngles(rotation); - rotation = Quat.fromPitchYawRollDegrees(eulers.x, eulers.y, 0); + var normal = Vec3.multiplyQbyV(rotation, Vec3.UNIT_NEG_Y); + var lookAt = Quat.lookAt({x: 0, y: 0, z: 0}, normal, Vec3.UNIT_Y); + rotation = Quat.multiply(lookAt, Quat.fromPitchYawRollDegrees(30, 0, 0)); position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, { x: 0, y: tabletHeight * 0.4, z: tabletHeight * 0.05 })); From 367b3ec603c889021c23601db78e0fe11bfd4047 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 28 May 2017 09:59:32 +1200 Subject: [PATCH 5/6] Handle nonvertical avatar orientation --- scripts/system/libraries/WebTablet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index c9918589f6..9a000d551e 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -71,8 +71,8 @@ function calcSpawnInfo(hand, tabletHeight) { rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(0, -90, 0)); } var normal = Vec3.multiplyQbyV(rotation, Vec3.UNIT_NEG_Y); - var lookAt = Quat.lookAt({x: 0, y: 0, z: 0}, normal, Vec3.UNIT_Y); - rotation = Quat.multiply(lookAt, Quat.fromPitchYawRollDegrees(30, 0, 0)); + var lookAt = Quat.lookAt({x: 0, y: 0, z: 0}, normal, Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.UNIT_Y)); + rotation = Quat.multiply(Quat.angleAxis(30, Vec3.multiplyQbyV(lookAt, Vec3.UNIT_X)), lookAt); position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, { x: 0, y: tabletHeight * 0.4, z: tabletHeight * 0.05 })); From fff8876b21154e7c260d4929e017099a88bec45c Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 10 Jun 2017 09:33:45 +1200 Subject: [PATCH 6/6] Code review --- scripts/system/libraries/WebTablet.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 9a000d551e..f8f4e96f25 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -71,10 +71,12 @@ function calcSpawnInfo(hand, tabletHeight) { rotation = Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(0, -90, 0)); } var normal = Vec3.multiplyQbyV(rotation, Vec3.UNIT_NEG_Y); - var lookAt = Quat.lookAt({x: 0, y: 0, z: 0}, normal, Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.UNIT_Y)); - rotation = Quat.multiply(Quat.angleAxis(30, Vec3.multiplyQbyV(lookAt, Vec3.UNIT_X)), lookAt); + var lookAt = Quat.lookAt(Vec3.ZERO, normal, Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.UNIT_Y)); + var TABLET_RAKE_ANGLE = 30; + rotation = Quat.multiply(Quat.angleAxis(TABLET_RAKE_ANGLE, Vec3.multiplyQbyV(lookAt, Vec3.UNIT_X)), lookAt); - position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, { x: 0, y: tabletHeight * 0.4, z: tabletHeight * 0.05 })); + var RELATIVE_SPAWN_OFFSET = { x: 0, y: 0.4, z: 0.05 }; + position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, Vec3.multiply(tabletHeight, RELATIVE_SPAWN_OFFSET))); return { position: position,