From 5e7f68d4b7c7d080a4ee7316b0e09f111b84c8d3 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 21 Aug 2018 14:00:20 +1200 Subject: [PATCH] Use a smaller near grab radius for tablet and mini-tablet --- .../controllers/controllerDispatcher.js | 23 +++++++++++++++++++ scripts/system/miniTablet.js | 8 +++++++ 2 files changed, 31 insertions(+) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 7a916392b9..f71af03e26 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -25,7 +25,9 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); (function() { Script.include("/~/system/libraries/pointersUtils.js"); + var NEAR_MAX_RADIUS = 0.1; + var NEAR_TABLET_MAX_RADIUS = 0.05; var TARGET_UPDATE_HZ = 60; // 50hz good enough, but we're using update var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ; @@ -49,6 +51,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.tabletID = null; this.blacklist = []; this.pointerManager = new PointerManager(); + this.miniTabletID = null; // a module can occupy one or more "activity" slots while it's running. If all the required slots for a module are // not set to false (not in use), a module cannot start. When a module is using a slot, that module's name @@ -211,6 +214,22 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); if (controllerLocations[h].valid) { var nearbyOverlays = Overlays.findOverlays(controllerLocations[h].position, NEAR_MAX_RADIUS * sensorScaleFactor); + + // Tablet and mini-tablet must be within NEAR_TABLET_MAX_RADIUS in order to be grabbed. + var tabletIndex = nearbyOverlays.indexOf(HMD.tabletID); + var miniTabletIndex = nearbyOverlays.indexOf(_this.miniTabletID); + if (tabletIndex !== -1 || miniTabletIndex !== -1) { + var closebyOverlays = + Overlays.findOverlays(controllerLocations[h].position, NEAR_TABLET_MAX_RADIUS * sensorScaleFactor); + // Assumes that the tablet and mini-tablet are not displayed at the same time. + if (tabletIndex !== -1 && closebyOverlays.indexOf(HMD.tabletID) === -1) { + nearbyOverlays.splice(tabletIndex, 1); + } + if (miniTabletIndex !== -1 && closebyOverlays.indexOf(_this.miniTabletID) === -1) { + nearbyOverlays.splice(miniTabletIndex, 1); + } + } + nearbyOverlays.sort(function (a, b) { var aPosition = Overlays.getProperty(a, "position"); var aDistance = Vec3.distance(aPosition, controllerLocations[h].position); @@ -218,6 +237,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); var bDistance = Vec3.distance(bPosition, controllerLocations[h].position); return aDistance - bDistance; }); + nearbyOverlayIDs.push(nearbyOverlays); } else { nearbyOverlayIDs.push([]); @@ -470,6 +490,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); _this.setBlacklist(); } } + } else if (channel === 'Hifi-MiniTablet-ID') { + _this.miniTabletID = message; } } catch (e) { @@ -508,6 +530,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Entities.mousePressOnEntity.connect(mousePress); var controllerDispatcher = new ControllerDispatcher(); Messages.subscribe('Hifi-Hand-RayPick-Blacklist'); + Messages.subscribe('Hifi-MiniTablet-ID'); Messages.messageReceived.connect(controllerDispatcher.handleHandMessage); Script.scriptEnding.connect(controllerDispatcher.cleanup); Script.setTimeout(controllerDispatcher.update, BASIC_TIMER_INTERVAL_MS); diff --git a/scripts/system/miniTablet.js b/scripts/system/miniTablet.js index 6d6180a964..fdfa92d98a 100644 --- a/scripts/system/miniTablet.js +++ b/scripts/system/miniTablet.js @@ -169,6 +169,11 @@ // #region Communications ================================================================================================== + function updateMiniTabletID() { + // Send mini-tablet overlay ID to controllerDispatcher so that it can use a smaller near grab distance. + Messages.sendLocalMessage("Hifi-MiniTablet-ID", proxyOverlay); + } + function updateMutedStatus() { var isMuted = Audio.muted; proxyOverlayObject.emitScriptEvent(JSON.stringify({ @@ -257,6 +262,8 @@ proxyOverlayObject = Overlays.getOverlayObject(proxyUIOverlay); proxyOverlayObject.webEventReceived.connect(onWebEventReceived); + + updateMiniTabletID(); } function showUI(hand) { @@ -320,6 +327,7 @@ proxyOverlayObject = null; proxyUIOverlay = null; proxyOverlay = null; + updateMiniTabletID(); } }