From a71a78b2d344a97cf53b43c166c69b5cea39b0cd Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 23 Feb 2016 11:22:24 -0800 Subject: [PATCH] add comments and license header to reticleDepth.js --- examples/depthReticle.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/examples/depthReticle.js b/examples/depthReticle.js index 4c93f714aa..a60e61d07c 100644 --- a/examples/depthReticle.js +++ b/examples/depthReticle.js @@ -1,6 +1,19 @@ +// depthReticle.js +// examples +// +// Created by Brad Hefta-Gaub on 2/23/16. +// Copyright 2016 High Fidelity, Inc. +// +// When used in HMD, this script will make the reticle depth track to any clickable item in view. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +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; -// Do some stuff regularly, like check for placement of various overlays Script.update.connect(function(deltaTime) { var TIME_BETWEEN_DEPTH_CHECKS = 100; var timeSinceLastDepthCheck = Date.now() - lastDepthCheckTime; @@ -9,23 +22,25 @@ Script.update.connect(function(deltaTime) { // first check the 2D Overlays if (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(reticlePosition)) { - print("intersecting with 2D overlay..."); - Reticle.setDepth(1.0); + Reticle.setDepth(APPARENT_2D_OVERLAY_DEPTH); } else { var pickRay = Camera.computePickRay(reticlePosition.x, reticlePosition.y); + + // Then check the 3D overlays var result = Overlays.findRayIntersection(pickRay); if (!result.intersects) { + // finally check the entities result = Entities.findRayIntersection(pickRay, true); } + + // If either the overlays or entities intersect, then set the reticle depth to + // the distance of intersection if (result.intersects) { - // + JSON.stringify(result) - print("something hovered!! result.distance:" +result.distance); - Vec3.print("something hovered!! result.intersection:", result.intersection); Reticle.setDepth(result.distance); } else { - Reticle.setDepth(100.0); - print("NO INTERSECTION..."); + // if nothing intersects... set the depth to some sufficiently large depth + Reticle.setDepth(APPARENT_MAXIMUM_DEPTH); } } }