From 501d23021ffef607d83e75c7c15916dfd2c90f21 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Mon, 29 Feb 2016 20:53:18 -0800 Subject: [PATCH] slight improvement to Away to have the paused overlay follow your view in HMD --- examples/away.js | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/examples/away.js b/examples/away.js index f22f9662a7..9b84f46742 100644 --- a/examples/away.js +++ b/examples/away.js @@ -13,7 +13,9 @@ // // Goes into "paused" when the '.' key (and automatically when started in HMD), and normal when pressing any key. // See MAIN CONTROL, below, for what "paused" actually does. -var OVERLAY_RATIO = 1920 / 1080; +var OVERLAY_WIDTH = 1920; +var OVERLAY_HEIGHT = 1080; +var OVERLAY_RATIO = OVERLAY_WIDTH / OVERLAY_HEIGHT; var OVERLAY_DATA = { imageURL: "http://hifi-content.s3.amazonaws.com/alan/production/images/images/Overlay-Viz-blank.png", color: {red: 255, green: 255, blue: 255}, @@ -69,16 +71,25 @@ function showOverlay() { // Update for current screen size, keeping overlay proportions constant. screen = Controller.getViewportDimensions(), screenRatio = screen.x / screen.y; - if (screenRatio < OVERLAY_RATIO) { - properties.width = screen.x; - properties.height = screen.x / OVERLAY_RATIO; - properties.x = 0; - properties.y = (screen.y - properties.height) / 2; + + if (HMD.active) { + var lookAt = HMD.getHUDLookAtPosition2D(); + properties.width = OVERLAY_WIDTH; + properties.height = OVERLAY_HEIGHT; + properties.x = lookAt.x - OVERLAY_WIDTH / 2; + properties.y = lookAt.y - OVERLAY_HEIGHT / 2; } else { - properties.height = screen.y; - properties.width = screen.y * OVERLAY_RATIO; - properties.y = 0; - properties.x = (screen.x - properties.width) / 2; + if (screenRatio < OVERLAY_RATIO) { + properties.width = screen.x; + properties.height = screen.x / OVERLAY_RATIO; + properties.x = 0; + properties.y = (screen.y - properties.height) / 2; + } else { + properties.height = screen.y; + properties.width = screen.y * OVERLAY_RATIO; + properties.y = 0; + properties.x = (screen.x - properties.width) / 2; + } } Overlays.editOverlay(overlay, properties); } @@ -87,6 +98,17 @@ function hideOverlay() { } hideOverlay(); +function maybeMoveOverlay() { + if (HMD.active && isAway) { + var lookAt = HMD.getHUDLookAtPosition2D(); + var properties = {visible: true}; + properties.width = OVERLAY_WIDTH; + properties.height = OVERLAY_HEIGHT; + properties.x = lookAt.x - OVERLAY_WIDTH / 2; + properties.y = lookAt.y - OVERLAY_HEIGHT / 2; + Overlays.editOverlay(overlay, properties); + } +} // MAIN CONTROL var wasMuted, isAway; @@ -164,6 +186,8 @@ function maybeGoAway() { } } +Script.update.connect(maybeMoveOverlay); + Script.update.connect(maybeGoAway); Controller.mousePressEvent.connect(goActive); Controller.keyPressEvent.connect(maybeGoActive);