From e341419090ea4305b123b0b7713e0d00fabc5711 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 11 Mar 2016 11:56:39 -0800 Subject: [PATCH] enter away mode when you remove the Vive HMD --- examples/away.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/examples/away.js b/examples/away.js index 840c5ab48a..6bd685fcff 100644 --- a/examples/away.js +++ b/examples/away.js @@ -156,6 +156,15 @@ var wasOverlaysVisible = Menu.isOptionChecked("Overlays"); var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too. var eventMapping = Controller.newMapping(eventMappingName); +// backward compatible version of getting HMD.mounted, so it works in old clients +function safeGetHMDMounted() { + if (HMD.mounted === undefined) { + return true; + } + return HMD.mounted; +} +var wasHmdMounted = safeGetHMDMounted(); + function goAway() { if (isAway) { return; @@ -182,7 +191,9 @@ function goAway() { if (HMD.active) { Reticle.visible = false; } + wasHmdMounted = safeGetHMDMounted(); // always remember the correct state } + function goActive() { if (!isAway) { return; @@ -205,6 +216,7 @@ function goActive() { if (HMD.active) { Reticle.position = HMD.getHUDLookAtPosition2D(); } + wasHmdMounted = safeGetHMDMounted(); // always remember the correct state } function maybeGoActive(event) { @@ -217,6 +229,7 @@ function maybeGoActive(event) { goActive(); } } + var wasHmdActive = HMD.active; var wasMouseCaptured = Reticle.mouseCaptured; @@ -236,6 +249,13 @@ function maybeGoAway() { goAway(); } } + + // If you've removed your HMD from your head, and we can detect it, we will also go away... + var hmdMounted = safeGetHMDMounted(); + if (HMD.active && !hmdMounted && wasHmdMounted) { + wasHmdMounted = hmdMounted; + goAway(); + } } Script.update.connect(maybeMoveOverlay);