From 2c389af751d4710c1556eeb7e1183783b4f0b156 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 17 Aug 2018 16:18:22 +1200 Subject: [PATCH] Display mini tablet only if camera is also looking at the hand --- scripts/system/tabletRezzer.js | 44 ++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/scripts/system/tabletRezzer.js b/scripts/system/tabletRezzer.js index 1779defb28..8fe206e9e0 100644 --- a/scripts/system/tabletRezzer.js +++ b/scripts/system/tabletRezzer.js @@ -124,6 +124,29 @@ // #region State Machine =================================================================================================== + function shouldShowProxy(hand) { + // Should show tablet proxy if hand is oriented toward the camera and the camera is oriented toward the proxy tablet. + var pose, + jointIndex, + handPosition, + handOrientation, + cameraToHandDirection; + + pose = Controller.getPoseValue(hand === LEFT_HAND ? Controller.Standard.LeftHand : Controller.Standard.RightHand); + if (!pose.valid) { + return false; + } + + jointIndex = handJointIndex(hand); + handPosition = Vec3.sum(MyAvatar.position, + Vec3.multiplyQbyV(MyAvatar.orientation, MyAvatar.getAbsoluteJointTranslationInObjectFrame(jointIndex))); + handOrientation = Quat.multiply(MyAvatar.orientation, MyAvatar.getAbsoluteJointRotationInObjectFrame(jointIndex)); + cameraToHandDirection = Vec3.normalize(Vec3.subtract(handPosition, Camera.position)); + + return Vec3.dot(cameraToHandDirection, Quat.getForward(handOrientation)) > MIN_HAND_CAMERA_ANGLE_COS + && Vec3.dot(cameraToHandDirection, Quat.getForward(Camera.orientation)) > MIN_HAND_CAMERA_ANGLE_COS; + } + function enterProxyHidden() { if (proxyOverlay) { Overlays.deleteOverlay(proxyOverlay); @@ -287,27 +310,6 @@ // #region Events ========================================================================================================== - function shouldShowProxy(hand) { - // Should show tablet proxy if hand is oriented towards the camera. - var pose, - jointIndex, - handPosition, - handOrientation; - - pose = Controller.getPoseValue(hand === LEFT_HAND ? Controller.Standard.LeftHand : Controller.Standard.RightHand); - if (!pose.valid) { - return false; - } - - jointIndex = handJointIndex(hand); - handPosition = Vec3.sum(MyAvatar.position, - Vec3.multiplyQbyV(MyAvatar.orientation, MyAvatar.getAbsoluteJointTranslationInObjectFrame(jointIndex))); - handOrientation = Quat.multiply(MyAvatar.orientation, MyAvatar.getAbsoluteJointRotationInObjectFrame(jointIndex)); - - return Vec3.dot(Vec3.normalize(Vec3.subtract(handPosition, Camera.position)), Quat.getForward(handOrientation)) - > MIN_HAND_CAMERA_ANGLE_COS; - } - function update() { // Assumes that is HMD.mounted. updateState();