From 5c6ae6fe95ca1a6d71799f139f8d7484173a8dad Mon Sep 17 00:00:00 2001 From: David Kelly Date: Tue, 10 Jan 2017 14:47:34 -0700 Subject: [PATCH] HMD hover working now Had to hack a bit -- the trigger mappings were not firing so instead I just get the hand that is triggering (when HMD is active) and handle the hover almost as before, with mouse move events. Some thought about how to map a 'mouse move' event into something where 2 triggers can both be pressed at same time was in order. --- scripts/system/pal.js | 71 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/scripts/system/pal.js b/scripts/system/pal.js index 6a9ac1195b..ef65fb0a88 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -120,6 +120,11 @@ ExtendedOverlay.some = function (iterator) { // Bails early as soon as iterator } } }; +ExtendedOverlay.unHover = function () { // calls hover(false) on lastHoveringId (if any) + if (lastHoveringId) { + ExtendedOverlay.get(lastHoveringId).hover(false); + } +}; // hit(overlay) on the one overlay intersected by pickRay, if any. // noHit() if no ExtendedOverlay was intersected (helps with hover) @@ -366,16 +371,70 @@ function handleMouseEvent(mousePressEvent) { // handleClick if we get one. } handleClick(Camera.computePickRay(mousePressEvent.x, mousePressEvent.y)); } -function handleMouseMoveEvent(event) { - // find out which overlay (if any) is over the mouse position - // var overlayAtPoint = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - var pickRay = Camera.computePickRay(event.x, event.y); +function handleMouseMoveEvent(event) { // find out which overlay (if any) is over the mouse position + if (HMD.active) { + var hand = whichHand(); + if (hand != 0) { + print("pick ray for " + hand); + pickRay = controllerComputePickRay(hand); + } else { + // nothing should hover, so + ExtendedOverlay.unHover(); + return; + } + } else { + pickRay = Camera.computePickRay(event.x, event.y); + } + handleMouseMove(pickRay); +} +const TRIGGER_THRESHOLD = 0.85; +// for some reason, I could not get trigger mappings for the LT and RT to fire. So, since we can read the +// value of the RT and LT, and the messages come through as mouse moves, we have the hack below to figure out +// which hand is being triggered, and compute the pick ray accordingly. +// +function isPressed(hand) { // helper to see if the hand passed in has the trigger pulled + var controller = (hand === Controller.Standard.RightHand ? Controller.Standard.RT : Controller.Standard.LT); + return Controller.getValue(controller) > TRIGGER_THRESHOLD; +} +// helpful globals +var currentHandPressed = 0; +var hands = [Controller.Standard.RightHand, Controller.Standard.LeftHand]; + +function whichHand() { + // for HMD, decide which hand is the "mouse". The 'logic' is to use the first one that + // is triggered, until that one is released. There are interesting effects when both + // are held that this avoids. Mapping the 2 triggers and their lasers to one mouse move + // message is a bit problematic, this mitigates some of it. + if (HMD.active) { + var pressed = {}; + for (var i = 0; i 0.85) { + if (clicked > TRIGGER_THRESHOLD) { var pickRay = controllerComputePickRay(hand); handleClick(pickRay); }