fix trigger clicks on vive

This commit is contained in:
David Back 2018-07-30 13:21:09 -07:00
parent bec54cc182
commit b420ef8cf2

View file

@ -761,13 +761,13 @@ SelectionDisplay = (function() {
// We get mouseMoveEvents from the handControllers, via handControllerPointer. // We get mouseMoveEvents from the handControllers, via handControllerPointer.
// But we dont' get mousePressEvents. // But we dont' get mousePressEvents.
that.triggerMapping = Controller.newMapping(Script.resolvePath('') + '-click'); that.triggerMapping = Controller.newMapping(Script.resolvePath('') + '-click');
that.triggerPressMapping = Controller.newMapping(Script.resolvePath('') + '-press');
Script.scriptEnding.connect(that.triggerMapping.disable); Script.scriptEnding.connect(that.triggerMapping.disable);
that.triggeredHand = NO_TRIGGER_HAND; that.triggeredHand = NO_TRIGGER_HAND;
that.triggered = function() { that.triggered = function() {
return that.triggeredHand !== NO_TRIGGER_HAND; return that.triggeredHand !== NO_TRIGGER_HAND;
} }
function triggerPress(hand) { function triggerPress(hand) {
that.triggeredHand = hand;
var pointingAtDesktopWindow = (hand === Controller.Standard.RightHand && var pointingAtDesktopWindow = (hand === Controller.Standard.RightHand &&
SelectionManager.pointingAtDesktopWindowRight) || SelectionManager.pointingAtDesktopWindowRight) ||
(hand === Controller.Standard.LeftHand && (hand === Controller.Standard.LeftHand &&
@ -777,6 +777,7 @@ SelectionDisplay = (function() {
if (pointingAtDesktopWindow || pointingAtTablet) { if (pointingAtDesktopWindow || pointingAtTablet) {
return; return;
} }
that.triggeredHand = hand;
that.mousePressEvent({}); that.mousePressEvent({});
} }
function triggerRelease(hand) { function triggerRelease(hand) {
@ -791,23 +792,33 @@ SelectionDisplay = (function() {
triggerPress(otherHand); triggerPress(otherHand);
} }
} }
function makeTriggerHandler(hand) { function handleTriggerPress(hand, triggerClicked) {
return function () { // Don't allow both hands to trigger at the same time
// Don't allow both hands to trigger at the same time if (that.triggered() && hand !== that.triggeredHand) {
if (that.triggered() && hand !== that.triggeredHand) { return;
return; }
} if (!that.triggered() && triggerClicked) {
triggerPress(hand);
} else if (that.triggered() && !triggerClicked) {
triggerRelease(hand);
}
}
function makePressHandler(hand) {
return function (value) {
var triggerClicked = hand == Controller.Standard.RightHand ? SelectionManager.triggerClickedRight : var triggerClicked = hand == Controller.Standard.RightHand ? SelectionManager.triggerClickedRight :
SelectionManager.triggerClickedLeft; SelectionManager.triggerClickedLeft;
if (!that.triggered() && triggerClicked) { handleTriggerPress(hand, triggerClicked);
triggerPress(hand);
} else if (that.triggered() && !triggerClicked) {
triggerRelease(hand);
}
}; };
} }
that.triggerMapping.from(Controller.Standard.RT).peek().to(makeTriggerHandler(Controller.Standard.RightHand)); function makeClickHandler(hand) {
that.triggerMapping.from(Controller.Standard.LT).peek().to(makeTriggerHandler(Controller.Standard.LeftHand)); return function (clicked) {
handleTriggerPress(hand, clicked);
};
}
that.triggerPressMapping.from(Controller.Standard.RT).peek().to(makePressHandler(Controller.Standard.RightHand));
that.triggerPressMapping.from(Controller.Standard.LT).peek().to(makePressHandler(Controller.Standard.LeftHand));
that.triggerMapping.from(Controller.Standard.RTClick).peek().to(makeClickHandler(Controller.Standard.RightHand));
that.triggerMapping.from(Controller.Standard.LTClick).peek().to(makeClickHandler(Controller.Standard.LeftHand));
// FUNCTION DEF(s): Intersection Check Helpers // FUNCTION DEF(s): Intersection Check Helpers
function testRayIntersect(queryRay, overlayIncludes, overlayExcludes) { function testRayIntersect(queryRay, overlayIncludes, overlayExcludes) {