Do button mapping in C++ and simplify vive.json accordingly. Vive and

Hydra now use PrimaryThumb and SecondaryThumb. Fix warnings for Neuron.
This commit is contained in:
howard-stearns 2016-05-24 16:10:12 -07:00
parent 6b606759aa
commit a3f1ece978
7 changed files with 42 additions and 37 deletions

View file

@ -16,12 +16,10 @@
{ "from": "Hydra.L0", "to": "Standard.Back" },
{ "from": "Hydra.R0", "to": "Standard.Start" },
{ "from": [ "Hydra.L1", "Hydra.L2" ], "to": "Standard.LeftPrimaryThumb" },
{ "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.L1", "Hydra.L3" ], "to": "Standard.LeftPrimaryThumb" },
{ "from": [ "Hydra.R1", "Hydra.R3" ], "to": "Standard.RightPrimaryThumb" },
{ "from": [ "Hydra.R2", "Hydra.R4" ], "to": "Standard.RightSecondaryThumb" },
{ "from": [ "Hydra.L2", "Hydra.L4" ], "to": "Standard.LeftSecondaryThumb" },
{ "from": "Hydra.LeftHand", "to": "Standard.LeftHand" },
{ "from": "Hydra.RightHand", "to": "Standard.RightHand" }

View file

@ -1,7 +1,7 @@
{
"name": "Neuron to Standard",
"channels": [
{ "from": "Hydra.LeftHand", "to": "Standard.LeftHand" },
{ "from": "Hydra.RightHand", "to": "Standard.RightHand" }
{ "from": "Neuron.LeftHand", "to": "Standard.LeftHand" },
{ "from": "Neuron.RightHand", "to": "Standard.RightHand" }
]
}

View file

@ -1,23 +1,25 @@
{
"name": "Vive to Standard",
"channels": [
{ "from": "Vive.LY", "when": "Vive.LS", "filters": ["invert" ,{ "type": "deadZone", "min": 0.6 }], "to": "Standard.LY" },
{ "from": "Vive.LX", "when": "Vive.LS", "filters": [{ "type": "deadZone", "min": 0.6 }], "to": "Standard.LX" },
{ "from": "Vive.LY", "when": "Vive.LSOuter", "filters": ["invert"], "to": "Standard.LY" },
{ "from": "Vive.LX", "when": "Vive.LSOuter", "to": "Standard.LX" },
{ "from": "Vive.LT", "to": "Standard.LT" },
{ "from": "Vive.LeftGrip", "to": "Standard.LB" },
{ "from": "Vive.LS", "to": "Standard.LS" },
{ "from": "Vive.LSTouch", "to": "Standard.LSTouch" },
{ "from": "Vive.RY", "when": "Vive.RS", "filters": ["invert", { "type": "deadZone", "min": 0.6 }], "to": "Standard.RY" },
{ "from": "Vive.RX", "when": "Vive.RS", "filters": [{ "type": "deadZone", "min": 0.6 }], "to": "Standard.RX" },
{ "from": "Vive.RY", "when": "Vive.RSOuter", "filters": ["invert"], "to": "Standard.RY" },
{ "from": "Vive.RX", "when": "Vive.RSOuter", "to": "Standard.RX" },
{ "from": "Vive.RT", "to": "Standard.RT" },
{ "from": "Vive.RightGrip", "to": "Standard.RB" },
{ "from": "Vive.RS", "to": "Standard.RS" },
{ "from": "Vive.RSTouch", "to": "Standard.RSTouch" },
{ "from": "Vive.LSCenter", "to": "Standard.LeftPrimaryThumb" },
{ "from": "Vive.LeftApplicationMenu", "to": "Standard.LeftSecondaryThumb" },
{ "from": "Vive.RSCenter", "to": "Standard.RightPrimaryThumb" },
{ "from": "Vive.RightApplicationMenu", "to": "Standard.RightSecondaryThumb" },
{ "from": "Vive.LeftHand", "to": "Standard.LeftHand" },

View file

@ -43,6 +43,8 @@ namespace controller {
LEFT_SECONDARY_THUMB_TOUCH,
LS_TOUCH,
LEFT_THUMB_UP,
LS_CENTER,
LS_OUTER,
RIGHT_PRIMARY_THUMB,
RIGHT_SECONDARY_THUMB,
@ -50,6 +52,8 @@ namespace controller {
RIGHT_SECONDARY_THUMB_TOUCH,
RS_TOUCH,
RIGHT_THUMB_UP,
RS_CENTER,
RS_OUTER,
LEFT_PRIMARY_INDEX,
LEFT_SECONDARY_INDEX,

View file

@ -282,7 +282,22 @@ void ViveControllerManager::InputDevice::handleHandController(float deltaTime, u
for (uint32_t i = 0; i < vr::k_unControllerStateAxisCount; i++) {
handleAxisEvent(deltaTime, i, controllerState.rAxis[i].x, controllerState.rAxis[i].y, isLeftHand);
}
}
// pseudo buttons the depend on both of the above for-loops
partitionTouchpad(controller::LS, controller::LX, controller::LY, controller::LS_CENTER, controller::LS_OUTER);
partitionTouchpad(controller::RS, controller::RX, controller::RY, controller::RS_CENTER, controller::RS_OUTER);
}
}
}
void ViveControllerManager::InputDevice::partitionTouchpad(int sButton, int xAxis, int yAxis, int centerPseudoButton, int outerPseudoButton) {
// Populate the L/RS_CENTER/OUTER pseudo buttons, corresponding to a partition of the L/RS space based on the X/Y values.
const float CENTER_DEADBAND = 0.6f;
if (_buttonPressedMap.find(sButton) != _buttonPressedMap.end()) {
float absX = abs(_axisStateMap[xAxis]);
float absY = abs(_axisStateMap[yAxis]);
bool isCenter = (absX < CENTER_DEADBAND) && (absY < CENTER_DEADBAND); // square deadband
_buttonPressedMap.insert(isCenter ? centerPseudoButton : outerPseudoButton);
}
}
@ -443,6 +458,11 @@ controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableI
// touch pad press
makePair(LS, "LS"),
makePair(RS, "RS"),
// Differentiate where we are in the touch pad click
makePair(LS_CENTER, "LSCenter"),
makePair(LS_OUTER, "LSOuter"),
makePair(RS_CENTER, "RSCenter"),
makePair(RS_OUTER, "RSOuter"),
// triggers
makePair(LT, "LT"),

View file

@ -61,6 +61,7 @@ private:
void handleAxisEvent(float deltaTime, uint32_t axis, float x, float y, bool isLeftHand);
void handlePoseEvent(float deltaTime, const controller::InputCalibrationData& inputCalibrationData, const mat4& mat,
const vec3& linearVelocity, const vec3& angularVelocity, bool isLeftHand);
void ViveControllerManager::InputDevice::partitionTouchpad(int sButton, int xAxis, int yAxis, int centerPsuedoButton, int outerPseudoButton);
class FilteredStick {
public:

View file

@ -266,39 +266,19 @@ function toggleHand() {
}
}
// Create clickMappings as needed, on demand.
var clickMapping = Controller.newMapping(Script.resolvePath('') + '-click');
Script.scriptEnding.connect(clickMapping.disable);
// Move these to vive.json
function makeCenterClickWhen(click, x, y) {
var clickKey = Controller.Standard[click],
xKey = Controller.Standard[x], // Standard after filtering by mapping
yKey = Controller.Standard[y];
return function () {
var clickValue = Controller.getValue(clickKey);
var xValue = Controller.getValue(xKey);
var yValue = Controller.getValue(yKey);
var answer = clickValue && !xValue && !yValue;
return answer;
};
}
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.RightPrimaryThumb).peek().to(Controller.Actions.ReticleClick);
clickMapping.from(Controller.Standard.LeftPrimaryThumb).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) {
clickMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(function (on) {
if (on && (activeHand !== Controller.Standard.RightHand)) {
toggleHand();
}
});
clickMapping.from(Controller.Standard.L3).peek().to(function (on) {
clickMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(function (on) {
if (on && (activeHand !== Controller.Standard.LeftHand)) {
toggleHand();
}