mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 21:35:04 +02:00
Enable the LT and RT signals, use them
A bit cleaner. Still have to keep track of which hand is the mouse, but this removes some of the hacky code.
This commit is contained in:
parent
0a018e133d
commit
1e3a00d1fb
1 changed files with 32 additions and 43 deletions
|
@ -384,12 +384,16 @@ function handleMouseMove(pickRay) { // given the pickRay, just do the hover logi
|
||||||
ExtendedOverlay.unHover();
|
ExtendedOverlay.unHover();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handy global to keep track of which hand is the mouse (if any)
|
||||||
|
var currentHandPressed = 0;
|
||||||
|
const TRIGGER_CLICK_THRESHOLD = 0.85;
|
||||||
|
const TRIGGER_PRESS_THRESHOLD = 0.05;
|
||||||
|
|
||||||
function handleMouseMoveEvent(event) { // find out which overlay (if any) is over the mouse position
|
function handleMouseMoveEvent(event) { // find out which overlay (if any) is over the mouse position
|
||||||
if (HMD.active) {
|
if (HMD.active) {
|
||||||
var hand = whichHand();
|
if (currentHandPressed != 0) {
|
||||||
if (hand != 0) {
|
pickRay = controllerComputePickRay(currentHandPressed);
|
||||||
print("pick ray for " + hand);
|
|
||||||
pickRay = controllerComputePickRay(hand);
|
|
||||||
} else {
|
} else {
|
||||||
// nothing should hover, so
|
// nothing should hover, so
|
||||||
ExtendedOverlay.unHover();
|
ExtendedOverlay.unHover();
|
||||||
|
@ -400,50 +404,27 @@ function handleMouseMoveEvent(event) { // find out which overlay (if any) is ove
|
||||||
}
|
}
|
||||||
handleMouseMove(pickRay);
|
handleMouseMove(pickRay);
|
||||||
}
|
}
|
||||||
const TRIGGER_CLICK_THRESHOLD = 0.85;
|
function handleTriggerPressed(hand, value) {
|
||||||
const TRIGGER_PRESS_THRESHOLD = 0.05;
|
// The idea is if you press one trigger, it is the one
|
||||||
// for some reason, I could not get trigger mappings for the LT and RT to fire. So, since we can read the
|
// we will consider the mouse. Even if the other is pressed,
|
||||||
// value of the RT and LT, and the messages come through as mouse moves, we have the hack below to figure out
|
// we ignore it until this one is no longer pressed.
|
||||||
// which hand is being triggered, and compute the pick ray accordingly.
|
isPressed = value > TRIGGER_PRESS_THRESHOLD;
|
||||||
//
|
if (currentHandPressed == 0) {
|
||||||
function isPressed(hand) { // helper to see if the hand passed in has the trigger pulled
|
currentHandPressed = isPressed ? hand : 0;
|
||||||
var controller = (hand === Controller.Standard.RightHand ? Controller.Standard.RT : Controller.Standard.LT);
|
return;
|
||||||
return Controller.getValue(controller) > TRIGGER_PRESS_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<hands.length; i++) {
|
|
||||||
pressed[hands[i]] = isPressed(hands[i]);
|
|
||||||
}
|
|
||||||
if (currentHandPressed != 0 && pressed[currentHandPressed] === true) {
|
|
||||||
return currentHandPressed; // nothing changed
|
|
||||||
} else {
|
|
||||||
// so now just pick the first hand that is pressed.
|
|
||||||
for (var j=0; j<hands.length; j++) {
|
|
||||||
if (pressed[hands[j]]) {
|
|
||||||
currentHandPressed = hands[j];
|
|
||||||
return currentHandPressed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
currentHandPressed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return currentHandPressed;
|
if (currentHandPressed == hand) {
|
||||||
|
currentHandPressed = isPressed ? hand : 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// otherwise, the other hand is still triggered
|
||||||
|
// so do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
// We get mouseMoveEvents from the handControllers, via handControllerPointer.
|
// We get mouseMoveEvents from the handControllers, via handControllerPointer.
|
||||||
// But we don't get mousePressEvents.
|
// But we don't get mousePressEvents.
|
||||||
var triggerMapping = Controller.newMapping(Script.resolvePath('') + '-click');
|
var triggerMapping = Controller.newMapping(Script.resolvePath('') + '-click');
|
||||||
|
var triggerPressMapping = Controller.newMapping(Script.resolvePath('') + '-press');
|
||||||
function controllerComputePickRay(hand) {
|
function controllerComputePickRay(hand) {
|
||||||
var controllerPose = getControllerWorldLocation(hand, true);
|
var controllerPose = getControllerWorldLocation(hand, true);
|
||||||
if (controllerPose.valid) {
|
if (controllerPose.valid) {
|
||||||
|
@ -458,9 +439,15 @@ function makeClickHandler(hand) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
function makePressHandler(hand) {
|
||||||
|
return function (value) {
|
||||||
|
handleTriggerPressed(hand, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
triggerMapping.from(Controller.Standard.RTClick).peek().to(makeClickHandler(Controller.Standard.RightHand));
|
triggerMapping.from(Controller.Standard.RTClick).peek().to(makeClickHandler(Controller.Standard.RightHand));
|
||||||
triggerMapping.from(Controller.Standard.LTClick).peek().to(makeClickHandler(Controller.Standard.LeftHand));
|
triggerMapping.from(Controller.Standard.LTClick).peek().to(makeClickHandler(Controller.Standard.LeftHand));
|
||||||
|
triggerPressMapping.from(Controller.Standard.RT).peek().to(makePressHandler(Controller.Standard.RightHand));
|
||||||
|
triggerPressMapping.from(Controller.Standard.LT).peek().to(makePressHandler(Controller.Standard.LeftHand));
|
||||||
//
|
//
|
||||||
// Manage the connection between the button and the window.
|
// Manage the connection between the button and the window.
|
||||||
//
|
//
|
||||||
|
@ -484,6 +471,7 @@ function off() {
|
||||||
isWired = false;
|
isWired = false;
|
||||||
}
|
}
|
||||||
triggerMapping.disable(); // It's ok if we disable twice.
|
triggerMapping.disable(); // It's ok if we disable twice.
|
||||||
|
triggerPressMapping.disable(); // see above
|
||||||
removeOverlays();
|
removeOverlays();
|
||||||
Users.requestsDomainListData = false;
|
Users.requestsDomainListData = false;
|
||||||
}
|
}
|
||||||
|
@ -497,6 +485,7 @@ function onClicked() {
|
||||||
Controller.mousePressEvent.connect(handleMouseEvent);
|
Controller.mousePressEvent.connect(handleMouseEvent);
|
||||||
Controller.mouseMoveEvent.connect(handleMouseMoveEvent);
|
Controller.mouseMoveEvent.connect(handleMouseMoveEvent);
|
||||||
triggerMapping.enable();
|
triggerMapping.enable();
|
||||||
|
triggerPressMapping.enable();
|
||||||
} else {
|
} else {
|
||||||
off();
|
off();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue