Detect button press

This commit is contained in:
David Rowe 2017-07-26 22:30:52 +12:00
parent 3566609173
commit d4b872d9e1
3 changed files with 33 additions and 7 deletions

View file

@ -28,6 +28,7 @@ Hand = function (side) {
isTriggerClicked, isTriggerClicked,
TRIGGER_ON_VALUE = 0.15, // Per handControllerGrab.js. TRIGGER_ON_VALUE = 0.15, // Per handControllerGrab.js.
TRIGGER_OFF_VALUE = 0.1, // Per handControllerGrab.js. TRIGGER_OFF_VALUE = 0.1, // Per handControllerGrab.js.
TRIGGER_CLICKED_VALUE = 1.0,
NEAR_GRAB_RADIUS = 0.1, // Per handControllerGrab.js. NEAR_GRAB_RADIUS = 0.1, // Per handControllerGrab.js.
NEAR_HOVER_RADIUS = 0.025, NEAR_HOVER_RADIUS = 0.025,
@ -108,7 +109,7 @@ Hand = function (side) {
// Controller trigger. // Controller trigger.
isTriggerPressed = Controller.getValue(controllerTrigger) > (isTriggerPressed isTriggerPressed = Controller.getValue(controllerTrigger) > (isTriggerPressed
? TRIGGER_OFF_VALUE : TRIGGER_ON_VALUE); ? TRIGGER_OFF_VALUE : TRIGGER_ON_VALUE);
isTriggerClicked = Controller.getValue(controllerTriggerClicked); isTriggerClicked = Controller.getValue(controllerTriggerClicked) === TRIGGER_CLICKED_VALUE;
// Controller grip. // Controller grip.
gripValue = Controller.getValue(controllerGrip); gripValue = Controller.getValue(controllerGrip);

View file

@ -70,12 +70,25 @@ ToolMenu = function (side, scaleModeChangedCallback) {
isDisplaying = false, isDisplaying = false,
isHighlightingButton = false, isHighlightingButton = false,
isButtonPressed = false,
SCALE_MODE_DIRECT = 0, SCALE_MODE_DIRECT = 0,
SCALE_MODE_HANDLES = 1; SCALE_MODE_HANDLES = 1,
function setHand(hand) { // References.
side = hand; leftInputs,
rightInputs,
controlHand;
function setReferences(left, right) {
leftInputs = left;
rightInputs = right;
controlHand = side === LEFT_HAND ? rightInputs.hand() : leftInputs.hand();
}
function setHand(uiSide) {
side = uiSide;
controlHand = side === LEFT_HAND ? rightInputs.hand() : leftInputs.hand();
if (isDisplaying) { if (isDisplaying) {
// TODO: Move UI to other hand. // TODO: Move UI to other hand.
@ -92,6 +105,11 @@ ToolMenu = function (side, scaleModeChangedCallback) {
isHighlightingButton = !isHighlightingButton; isHighlightingButton = !isHighlightingButton;
Overlays.editOverlay(buttonHighlightOverlay, { visible: isHighlightingButton }); Overlays.editOverlay(buttonHighlightOverlay, { visible: isHighlightingButton });
} }
// Button click.
if (isHighlightingButton && controlHand.triggerClicked() !== isButtonPressed) {
isButtonPressed = controlHand.triggerClicked();
}
} }
function display() { function display() {
@ -153,6 +171,7 @@ ToolMenu = function (side, scaleModeChangedCallback) {
} }
return { return {
setReferences: setReferences,
setHand: setHand, setHand: setHand,
getEntityIDs: getEntityIDs, getEntityIDs: getEntityIDs,
update: update, update: update,

View file

@ -155,7 +155,7 @@
}; };
UI = function (side) { UI = function (side, setAppScaleWithHandlesCallback) {
// Tool menu and Create palette. // Tool menu and Create palette.
var // Primary objects. var // Primary objects.
@ -170,13 +170,15 @@
getIntersection, // Function. getIntersection, // Function.
intersection; intersection;
toolMenu = new ToolMenu(side); toolMenu = new ToolMenu(side, setAppScaleWithHandlesCallback);
function setReferences(left, right) { function setReferences(left, right) {
leftInputs = left; leftInputs = left;
rightInputs = right; rightInputs = right;
getIntersection = side === LEFT_HAND ? rightInputs.getIntersection : leftInputs.getIntersection; getIntersection = side === LEFT_HAND ? rightInputs.getIntersection : leftInputs.getIntersection;
toolMenu.setReferences(left, right);
} }
function setHand(side) { function setHand(side) {
@ -959,6 +961,10 @@
Settings.setValue(VR_EDIT_SETTING, isAppActive); Settings.setValue(VR_EDIT_SETTING, isAppActive);
} }
function setAppScaleWithHandles(appScaleWithHandles) {
isAppScaleWithHandles = appScaleWithHandles;
}
function onAppButtonClicked() { function onAppButtonClicked() {
// Application tablet/toolbar button clicked. // Application tablet/toolbar button clicked.
isAppActive = !isAppActive; isAppActive = !isAppActive;
@ -1023,7 +1029,7 @@
inputs[RIGHT_HAND] = new Inputs(RIGHT_HAND); inputs[RIGHT_HAND] = new Inputs(RIGHT_HAND);
// UI object. // UI object.
ui = new UI(otherHand(dominantHand)); ui = new UI(otherHand(dominantHand), setAppScaleWithHandles);
ui.setReferences(inputs[LEFT_HAND], inputs[RIGHT_HAND]); ui.setReferences(inputs[LEFT_HAND], inputs[RIGHT_HAND]);
// Editor objects. // Editor objects.