add comments and license header to reticleDepth.js

This commit is contained in:
Brad Hefta-Gaub 2016-02-23 11:22:24 -08:00
parent 71262c3e64
commit a71a78b2d3

View file

@ -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);
}
}
}