diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 22987245a4..13789a4a8e 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -236,6 +236,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); RayPick.getPrevRayPickResult(_this.leftControllerHudRayPick), RayPick.getPrevRayPickResult(_this.rightControllerHudRayPick) ]; + var mouseRayPick = RayPick.getPrevRayPickResult(_this.mouseRayPick); // if the pickray hit something very nearby, put it into the nearby entities list for (h = LEFT_HAND; h <= RIGHT_HAND; h++) { @@ -274,7 +275,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); nearbyEntityPropertiesByID: nearbyEntityPropertiesByID, nearbyOverlayIDs: nearbyOverlayIDs, rayPicks: rayPicks, - hudRayPicks: hudRayPicks + hudRayPicks: hudRayPicks, + mouseRayPick: mouseRayPick }; if (PROFILE) { Script.endProfileRange("dispatch.gather"); @@ -390,6 +392,11 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); maxDistance: DEFAULT_SEARCH_SPHERE_DISTANCE, posOffset: getGrabPointSphereOffset(Controller.Standard.RightHand, true) }); + this.mouseRayPick = RayPick.createRayPick({ + joint: "Mouse", + filter: RayPick.PICK_ENTITIES | RayPick.PICK_OVERLAYS, + enabled: true + }); this.handleHandMessage = function(channel, message, sender) { var data; diff --git a/scripts/system/controllers/controllerModules/mouseHMD.js b/scripts/system/controllers/controllerModules/mouseHMD.js index 10fe714348..f60136ed4e 100644 --- a/scripts/system/controllers/controllerModules/mouseHMD.js +++ b/scripts/system/controllers/controllerModules/mouseHMD.js @@ -58,6 +58,16 @@ } }; + this.adjustReticleDepth = function(controllerData) { + if (Reticle.isPointingAtSystemOverlay(Reticle.position)) { + var reticlePositionOnHUD = HMD.worldPointFromOverlay(Reticle.position); + Reticle.depth = Vec3.distance(reticlePositionOnHUD, HMD.position); + } else { + var APPARENT_MAXIMUM_DEPTH = 100.0; + var result = controllerData.mouseRayPick; + Reticle.depth = result.intersects ? result.distance : APPARENT_MAXIMUM_DEPTH; + } + } this.ignoreMouseActivity = function() { if (!Reticle.allowMouseCapture) { return true; @@ -98,7 +108,7 @@ return ControllerDispatcherUtils.makeRunningValues(true, [], []); } if (HMD.active) { - Reticle.visble = false; + Reticle.visible = false; } return ControllerDispatcherUtils.makeRunningValues(false, [], []); @@ -110,6 +120,7 @@ Reticle.visible = false; return ControllerDispatcherUtils.makeRunningValues(false, [], []); } + this.adjustReticleDepth(controllerData); return ControllerDispatcherUtils.makeRunningValues(true, [], []); }; }