From 6d9c5856041ffd26eb1f06bbe03a463fb6fecb47 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 26 Feb 2016 12:01:59 -0800 Subject: [PATCH 1/3] add fade between depths in depth reticle --- examples/depthReticle.js | 47 +++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/examples/depthReticle.js b/examples/depthReticle.js index a60e61d07c..a8afb80df2 100644 --- a/examples/depthReticle.js +++ b/examples/depthReticle.js @@ -12,17 +12,24 @@ var APPARENT_2D_OVERLAY_DEPTH = 1.0; var APPARENT_MAXIMUM_DEPTH = 100.0; // this is a depth at which things all seem sufficiently distant -var lastDepthCheckTime = 0; +var lastDepthCheckTime = Date.now(); +var desiredDepth = APPARENT_2D_OVERLAY_DEPTH; +var wasDepth = Reticle.depth; // depth at the time we changed our desired depth +var desiredDepthLastSet = lastDepthCheckTime; // time we changed our desired depth +var TIME_BETWEEN_DEPTH_CHECKS = 100; +var TIME_TO_FADE_DEPTH = 50; Script.update.connect(function(deltaTime) { - var TIME_BETWEEN_DEPTH_CHECKS = 100; - var timeSinceLastDepthCheck = Date.now() - lastDepthCheckTime; + var now = Date.now(); + var timeSinceLastDepthCheck = now - lastDepthCheckTime; if (timeSinceLastDepthCheck > TIME_BETWEEN_DEPTH_CHECKS) { + var newDesiredDepth = desiredDepth; + lastDepthCheckTime = now; var reticlePosition = Reticle.position; // first check the 2D Overlays if (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(reticlePosition)) { - Reticle.setDepth(APPARENT_2D_OVERLAY_DEPTH); + newDesiredDepth = APPARENT_2D_OVERLAY_DEPTH; } else { var pickRay = Camera.computePickRay(reticlePosition.x, reticlePosition.y); @@ -37,11 +44,39 @@ Script.update.connect(function(deltaTime) { // If either the overlays or entities intersect, then set the reticle depth to // the distance of intersection if (result.intersects) { - Reticle.setDepth(result.distance); + newDesiredDepth = result.distance; } else { // if nothing intersects... set the depth to some sufficiently large depth - Reticle.setDepth(APPARENT_MAXIMUM_DEPTH); + newDesiredDepth = APPARENT_MAXIMUM_DEPTH; } } + + // If the desired depth has changed, reset our fade start time + if (desiredDepth != newDesiredDepth) { + desiredDepthLastSet = now; + desiredDepth = newDesiredDepth; + wasDepth = Reticle.depth; + } + } + + // move the reticle toward the desired depth + if (desiredDepth != Reticle.depth) { + + // determine the time between now, and when we set our determined our desiredDepth + var elapsed = now - desiredDepthLastSet; + var distanceToFade = desiredDepth - wasDepth; + var percentElapsed = Math.min(1, elapsed / TIME_TO_FADE_DEPTH); + + // special case to handle no fade settings + if (TIME_TO_FADE_DEPTH == 0) { + percentElapsed = 1; + } + var depthDelta = distanceToFade * percentElapsed; + + var newDepth = wasDepth + depthDelta; + if (percentElapsed == 1) { + newDepth = desiredDepth; + } + Reticle.setDepth(newDepth); } }); From e403c990d96f8c174ecb97b82e0ed906b7ed5159 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sat, 27 Feb 2016 17:13:09 -0800 Subject: [PATCH 2/3] make fade non-linear --- examples/depthReticle.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/examples/depthReticle.js b/examples/depthReticle.js index a8afb80df2..4b649f49b6 100644 --- a/examples/depthReticle.js +++ b/examples/depthReticle.js @@ -14,10 +14,9 @@ var APPARENT_2D_OVERLAY_DEPTH = 1.0; var APPARENT_MAXIMUM_DEPTH = 100.0; // this is a depth at which things all seem sufficiently distant var lastDepthCheckTime = Date.now(); var desiredDepth = APPARENT_2D_OVERLAY_DEPTH; -var wasDepth = Reticle.depth; // depth at the time we changed our desired depth -var desiredDepthLastSet = lastDepthCheckTime; // time we changed our desired depth var TIME_BETWEEN_DEPTH_CHECKS = 100; -var TIME_TO_FADE_DEPTH = 50; +var MINIMUM_DEPTH_ADJUST = 0.01; +var NON_LINEAR_DIVISOR = 2; Script.update.connect(function(deltaTime) { var now = Date.now(); @@ -53,30 +52,21 @@ Script.update.connect(function(deltaTime) { // If the desired depth has changed, reset our fade start time if (desiredDepth != newDesiredDepth) { - desiredDepthLastSet = now; desiredDepth = newDesiredDepth; - wasDepth = Reticle.depth; } } // move the reticle toward the desired depth if (desiredDepth != Reticle.depth) { - // determine the time between now, and when we set our determined our desiredDepth - var elapsed = now - desiredDepthLastSet; - var distanceToFade = desiredDepth - wasDepth; - var percentElapsed = Math.min(1, elapsed / TIME_TO_FADE_DEPTH); - - // special case to handle no fade settings - if (TIME_TO_FADE_DEPTH == 0) { - percentElapsed = 1; - } - var depthDelta = distanceToFade * percentElapsed; - - var newDepth = wasDepth + depthDelta; - if (percentElapsed == 1) { + // cut distance between desiredDepth and current depth in half until we're close enough + var distanceToAdjustThisCycle = (desiredDepth - Reticle.depth) / NON_LINEAR_DIVISOR; + if (Math.abs(distanceToAdjustThisCycle) < MINIMUM_DEPTH_ADJUST) { newDepth = desiredDepth; + } else { + newDepth = Reticle.depth + distanceToAdjustThisCycle; } + Reticle.setDepth(newDepth); } }); From 188cf3694b83f36a6808bac3659ff7f1958f2f99 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sat, 27 Feb 2016 17:31:35 -0800 Subject: [PATCH 3/3] fix rotation of depth reticle --- interface/src/ui/ApplicationCompositor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/ApplicationCompositor.cpp b/interface/src/ui/ApplicationCompositor.cpp index 99f0b4fdc4..59d794d7cb 100644 --- a/interface/src/ui/ApplicationCompositor.cpp +++ b/interface/src/ui/ApplicationCompositor.cpp @@ -301,7 +301,7 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int // look at borrowed from overlays float elevation = -asinf(relativePosition.y / glm::length(relativePosition)); float azimuth = atan2f(relativePosition.x, relativePosition.z); - glm::quat faceCamera = glm::quat(glm::vec3(elevation, azimuth, 0)) * quat(vec3(0, 0, -1)); // this extra *quat(vec3(0,0,-1)) was required to get the quad to flip this seems like we could optimize + glm::quat faceCamera = glm::quat(glm::vec3(elevation, azimuth, 0)) * quat(vec3(0, -PI, 0)); // this extra *quat(vec3(0,-PI,0)) was required to get the quad to flip this seems like we could optimize Transform transform; transform.setTranslation(relativePosition);