mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
Fix hand controller pointer after input changes.
This commit is contained in:
parent
72dc24178f
commit
fdcd667d3c
3 changed files with 46 additions and 78 deletions
|
@ -16,8 +16,12 @@
|
||||||
{ "from": "Hydra.L0", "to": "Standard.Back" },
|
{ "from": "Hydra.L0", "to": "Standard.Back" },
|
||||||
{ "from": "Hydra.R0", "to": "Standard.Start" },
|
{ "from": "Hydra.R0", "to": "Standard.Start" },
|
||||||
|
|
||||||
{ "from": [ "Hydra.L1", "Hydra.L2", "Hydra.L3", "Hydra.L4" ], "to": "Standard.LeftPrimaryThumb" },
|
{ "from": [ "Hydra.L1", "Hydra.L2" ], "to": "Standard.LeftPrimaryThumb" },
|
||||||
{ "from": [ "Hydra.R1", "Hydra.R2", "Hydra.R3", "Hydra.R4" ], "to": "Standard.RightPrimaryThumb" },
|
{ "from": [ "Hydra.R1", "Hydra.R2" ], "to": "Standard.RightPrimaryThumb" },
|
||||||
|
{ "from": [ "Hydra.L3" ], "to": "Standard.L3" },
|
||||||
|
{ "from": [ "Hydra.R3" ], "to": "Standard.R3" },
|
||||||
|
{ "from": [ "Hydra.R4" ], "to": "Standard.RightSecondaryThumb" },
|
||||||
|
{ "from": [ "Hydra.L4" ], "to": "Standard.LeftSecondaryThumb" },
|
||||||
|
|
||||||
{ "from": "Hydra.LeftHand", "to": "Standard.LeftHand" },
|
{ "from": "Hydra.LeftHand", "to": "Standard.LeftHand" },
|
||||||
{ "from": "Hydra.RightHand", "to": "Standard.RightHand" }
|
{ "from": "Hydra.RightHand", "to": "Standard.RightHand" }
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
{ "from": "Vive.RS", "to": "Standard.RS" },
|
{ "from": "Vive.RS", "to": "Standard.RS" },
|
||||||
{ "from": "Vive.RSTouch", "to": "Standard.RSTouch" },
|
{ "from": "Vive.RSTouch", "to": "Standard.RSTouch" },
|
||||||
|
|
||||||
{ "from": "Vive.LeftApplicationMenu", "to": "Standard.Back" },
|
{ "from": "Vive.LeftApplicationMenu", "to": "Standard.LeftSecondaryThumb" },
|
||||||
{ "from": "Vive.RightApplicationMenu", "to": "Standard.Start" },
|
{ "from": "Vive.RightApplicationMenu", "to": "Standard.RightSecondaryThumb" },
|
||||||
|
|
||||||
{ "from": "Vive.LeftHand", "to": "Standard.LeftHand" },
|
{ "from": "Vive.LeftHand", "to": "Standard.LeftHand" },
|
||||||
{ "from": "Vive.RightHand", "to": "Standard.RightHand" }
|
{ "from": "Vive.RightHand", "to": "Standard.RightHand" }
|
||||||
|
|
|
@ -22,10 +22,7 @@
|
||||||
// (For now, the thumb buttons on both controllers are always on.)
|
// (For now, the thumb buttons on both controllers are always on.)
|
||||||
// When over a HUD element, the reticle is shown where the active hand controller beam intersects the HUD.
|
// When over a HUD element, the reticle is shown where the active hand controller beam intersects the HUD.
|
||||||
// Otherwise, the active hand controller shows a red ball where a click will act.
|
// Otherwise, the active hand controller shows a red ball where a click will act.
|
||||||
//
|
|
||||||
// Bugs:
|
|
||||||
// On Windows, the upper left corner of Interface must be in the upper left corner of the screen, and the title bar must be 50px high. (System bug.)
|
|
||||||
// While hardware mouse move switches to mouse move, hardware mouse click (without amove) does not.
|
|
||||||
|
|
||||||
|
|
||||||
// UTILITIES -------------
|
// UTILITIES -------------
|
||||||
|
@ -270,75 +267,43 @@ function toggleHand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create clickMappings as needed, on demand.
|
// Create clickMappings as needed, on demand.
|
||||||
var clickMappings = {}, clickMapping, clickMapToggle;
|
var clickMapping = Controller.newMapping(Script.resolvePath('') + '-click');
|
||||||
var hardware; // undefined
|
Script.scriptEnding.connect(clickMapping.disable);
|
||||||
function checkHardware() {
|
|
||||||
var newHardware = Controller.Hardware.Hydra ? 'Hydra' : (Controller.Hardware.Vive ? 'Vive' : null); // not undefined
|
|
||||||
if (hardware === newHardware) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
print('Setting mapping for new controller hardware:', newHardware);
|
|
||||||
if (clickMapToggle) {
|
|
||||||
clickMapToggle.setState(false);
|
|
||||||
}
|
|
||||||
hardware = newHardware;
|
|
||||||
if (clickMappings[hardware]) {
|
|
||||||
clickMapping = clickMappings[hardware];
|
|
||||||
} else {
|
|
||||||
clickMapping = Controller.newMapping(Script.resolvePath('') + '-click-' + hardware);
|
|
||||||
Script.scriptEnding.connect(clickMapping.disable);
|
|
||||||
function mapToAction(button, action) {
|
|
||||||
clickMapping.from(Controller.Hardware[hardware][button]).peek().to(Controller.Actions[action]);
|
|
||||||
}
|
|
||||||
function makeHandToggle(button, hand, optionalWhen) {
|
|
||||||
var whenThunk = optionalWhen || function () {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
function maybeToggle() {
|
|
||||||
if (activeHand !== Controller.Standard[hand]) {
|
|
||||||
toggleHand();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
// Move these to vive.json
|
||||||
clickMapping.from(Controller.Hardware[hardware][button]).peek().when(whenThunk).to(maybeToggle);
|
function makeCenterClickWhen(click, x, y) {
|
||||||
}
|
var clickKey = Controller.Standard[click],
|
||||||
function makeViveWhen(click, x, y) {
|
xKey = Controller.Standard[x], // Standard after filtering by mapping
|
||||||
var viveClick = Controller.Hardware.Vive[click],
|
yKey = Controller.Standard[y];
|
||||||
viveX = Controller.Standard[x], // Standard after filtering by mapping
|
return function () {
|
||||||
viveY = Controller.Standard[y];
|
var clickValue = Controller.getValue(clickKey);
|
||||||
return function () {
|
var xValue = Controller.getValue(xKey);
|
||||||
var clickValue = Controller.getValue(viveClick);
|
var yValue = Controller.getValue(yKey);
|
||||||
var xValue = Controller.getValue(viveX);
|
var answer = clickValue && !xValue && !yValue;
|
||||||
var yValue = Controller.getValue(viveY);
|
return answer;
|
||||||
return clickValue && !xValue && !yValue;
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
switch (hardware) {
|
|
||||||
case 'Hydra':
|
|
||||||
makeHandToggle('R3', 'RightHand');
|
|
||||||
makeHandToggle('L3', 'LeftHand');
|
|
||||||
|
|
||||||
mapToAction('R3', 'ReticleClick');
|
|
||||||
mapToAction('L3', 'ReticleClick');
|
|
||||||
mapToAction('R4', 'ContextMenu');
|
|
||||||
mapToAction('L4', 'ContextMenu');
|
|
||||||
break;
|
|
||||||
case 'Vive':
|
|
||||||
// When touchpad click is NOT treated as movement, treat as left click
|
|
||||||
makeHandToggle('RS', 'RightHand', makeViveWhen('RS', 'RX', 'RY'));
|
|
||||||
makeHandToggle('LS', 'LeftHand', makeViveWhen('LS', 'LX', 'LY'));
|
|
||||||
clickMapping.from(Controller.Hardware.Vive.RS).when(makeViveWhen('RS', 'RX', 'RY')).to(Controller.Actions.ReticleClick);
|
|
||||||
clickMapping.from(Controller.Hardware.Vive.LS).when(makeViveWhen('LS', 'LX', 'LY')).to(Controller.Actions.ReticleClick);
|
|
||||||
mapToAction('RightApplicationMenu', 'ContextMenu');
|
|
||||||
mapToAction('LeftApplicationMenu', 'ContextMenu');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
clickMappings[hardware] = clickMapping;
|
|
||||||
}
|
|
||||||
clickMapToggle = new LatchedToggle(clickMapping.enable, clickMapping.disable);
|
|
||||||
clickMapToggle.setState(true);
|
|
||||||
}
|
}
|
||||||
checkHardware();
|
if (Controller.Hardware.Vive) {
|
||||||
|
clickMapping.from(Controller.Hardware.Vive.RS).when(makeCenterClickWhen('RS', 'RX', 'RY')).to(Controller.Standard.R3);
|
||||||
|
clickMapping.from(Controller.Hardware.Vive.LS).when(makeCenterClickWhen('LS', 'LX', 'LY')).to(Controller.Standard.L3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
clickMapping.from(Controller.Standard.R3).peek().to(Controller.Actions.ReticleClick);
|
||||||
|
clickMapping.from(Controller.Standard.L3).peek().to(Controller.Actions.ReticleClick);
|
||||||
|
clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(Controller.Actions.ContextMenu);
|
||||||
|
clickMapping.from(Controller.Standard.LeftSecondaryThumb).peek().to(Controller.Actions.ContextMenu);
|
||||||
|
clickMapping.from(Controller.Standard.R3).peek().to(function (on) {
|
||||||
|
if (on && (activeHand !== Controller.Standard.RightHand)) {
|
||||||
|
toggleHand();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clickMapping.from(Controller.Standard.L3).peek().to(function (on) {
|
||||||
|
if (on && (activeHand !== Controller.Standard.LeftHand)) {
|
||||||
|
toggleHand();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clickMapping.enable();
|
||||||
|
|
||||||
// VISUAL AID -----------
|
// VISUAL AID -----------
|
||||||
// Same properties as handControllerGrab search sphere
|
// Same properties as handControllerGrab search sphere
|
||||||
|
@ -415,8 +380,8 @@ function update() {
|
||||||
return turnOffVisualization();
|
return turnOffVisualization();
|
||||||
}
|
}
|
||||||
var controllerPose = Controller.getPoseValue(activeHand);
|
var controllerPose = Controller.getPoseValue(activeHand);
|
||||||
// Vive is effectively invalid when not in HMD
|
// Valid if any plugged-in hand controller is "on". (uncradled Hydra, green-lighted Vive...)
|
||||||
if (!controllerPose.valid || ((hardware === 'Vive') && !HMD.active)) {
|
if (!controllerPose.valid) {
|
||||||
return turnOffVisualization();
|
return turnOffVisualization();
|
||||||
} // Controller is cradled.
|
} // Controller is cradled.
|
||||||
var controllerPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, controllerPose.translation),
|
var controllerPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, controllerPose.translation),
|
||||||
|
@ -458,7 +423,6 @@ Script.scriptEnding.connect(function () {
|
||||||
var SETTINGS_CHANGE_RECHECK_INTERVAL = 10 * 1000; // milliseconds
|
var SETTINGS_CHANGE_RECHECK_INTERVAL = 10 * 1000; // milliseconds
|
||||||
function checkSettings() {
|
function checkSettings() {
|
||||||
updateFieldOfView();
|
updateFieldOfView();
|
||||||
checkHardware();
|
|
||||||
}
|
}
|
||||||
checkSettings();
|
checkSettings();
|
||||||
var settingsChecker = Script.setInterval(checkSettings, SETTINGS_CHANGE_RECHECK_INTERVAL);
|
var settingsChecker = Script.setInterval(checkSettings, SETTINGS_CHANGE_RECHECK_INTERVAL);
|
||||||
|
|
Loading…
Reference in a new issue