Hide mini tablet if lasering or grabbing something else

This commit is contained in:
David Rowe 2018-09-12 11:18:26 +12:00
parent de95ee0a18
commit a1c49bd2b6
2 changed files with 76 additions and 19 deletions

View file

@ -18,6 +18,7 @@
var // EventBridge var // EventBridge
READY_MESSAGE = "ready", // Engine <== Dialog READY_MESSAGE = "ready", // Engine <== Dialog
HOVER_MESSAGE = "hover", // Engine <== Dialog HOVER_MESSAGE = "hover", // Engine <== Dialog
UNHOVER_MESSAGE = "unhover", // Engine <== Dialog
MUTE_MESSAGE = "mute", // Engine <=> Dialog MUTE_MESSAGE = "mute", // Engine <=> Dialog
GOTO_MESSAGE = "goto", // Engine <=> Dialog GOTO_MESSAGE = "goto", // Engine <=> Dialog
EXPAND_MESSAGE = "expand", // Engine <== Dialog EXPAND_MESSAGE = "expand", // Engine <== Dialog
@ -73,9 +74,24 @@
} }
} }
function onBodyHover() {
EventBridge.emitWebEvent(JSON.stringify({
type: HOVER_MESSAGE,
target: "body"
}));
}
function onBodyUnhover() {
EventBridge.emitWebEvent(JSON.stringify({
type: UNHOVER_MESSAGE,
target: "body"
}));
}
function onButtonHover() { function onButtonHover() {
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: HOVER_MESSAGE type: HOVER_MESSAGE,
target: "button"
})); }));
clearUnhover(); clearUnhover();
} }
@ -128,6 +144,9 @@
connectEventBridge(); connectEventBridge();
document.body.addEventListener("mouseenter", onBodyHover, false);
document.body.addEventListener("mouseleave", onBodyUnhover, false);
muteButton.addEventListener("mouseenter", onButtonHover, false); muteButton.addEventListener("mouseenter", onButtonHover, false);
gotoButton.addEventListener("mouseenter", onButtonHover, false); gotoButton.addEventListener("mouseenter", onButtonHover, false);
expandButton.addEventListener("mouseenter", onButtonHover, false); expandButton.addEventListener("mouseenter", onButtonHover, false);

View file

@ -8,13 +8,14 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
/* global getTabletWidthFromSettings */ /* global getTabletWidthFromSettings, TRIGGER_OFF_VALUE */
(function () { (function () {
"use strict"; "use strict";
Script.include("./libraries/utils.js"); Script.include("./libraries/utils.js");
Script.include("./libraries/controllerDispatcherUtils.js");
var UI, var UI,
ui = null, ui = null,
@ -147,9 +148,13 @@
miniTargetWidth, miniTargetWidth,
miniTargetLocalRotation, miniTargetLocalRotation,
// Laser pointing at.
isBodyHovered = false,
// EventBridge. // EventBridge.
READY_MESSAGE = "ready", // Engine <== Dialog READY_MESSAGE = "ready", // Engine <== Dialog
HOVER_MESSAGE = "hover", // Engine <== Dialog HOVER_MESSAGE = "hover", // Engine <== Dialog
UNHOVER_MESSAGE = "unhover", // Engine <== Dialog
MUTE_MESSAGE = "mute", // Engine <=> Dialog MUTE_MESSAGE = "mute", // Engine <=> Dialog
GOTO_MESSAGE = "goto", // Engine <=> Dialog GOTO_MESSAGE = "goto", // Engine <=> Dialog
EXPAND_MESSAGE = "expand", // Engine <== Dialog EXPAND_MESSAGE = "expand", // Engine <== Dialog
@ -196,8 +201,19 @@
setGotoIcon(); setGotoIcon();
break; break;
case HOVER_MESSAGE: case HOVER_MESSAGE:
// Audio feedback. if (message.target === "body") {
playSound(hoverSound, HOVER_VOLUME); // Laser status.
isBodyHovered = true;
} else if (message.target === "button") {
// Audio feedback.
playSound(hoverSound, HOVER_VOLUME);
}
break;
case UNHOVER_MESSAGE:
if (message.target === "body") {
// Laser status.
isBodyHovered = false;
}
break; break;
case MUTE_MESSAGE: case MUTE_MESSAGE:
// Toggle mute. // Toggle mute.
@ -253,6 +269,10 @@
}; };
} }
function isLaserPointingAt() {
return isBodyHovered;
}
function show(hand) { function show(hand) {
var initialScale = 0.01; // Start very small. var initialScale = 0.01; // Start very small.
@ -420,6 +440,7 @@
getUIPositionAndRotation: getUIPositionAndRotation, getUIPositionAndRotation: getUIPositionAndRotation,
getMiniTabletID: getMiniTabletID, getMiniTabletID: getMiniTabletID,
getMiniTabletProperties: getMiniTabletProperties, getMiniTabletProperties: getMiniTabletProperties,
isLaserPointingAt: isLaserPointingAt,
updateMutedStatus: updateMutedStatus, updateMutedStatus: updateMutedStatus,
show: show, show: show,
size: size, size: size,
@ -509,32 +530,49 @@
function shouldShowMini(hand) { function shouldShowMini(hand) {
// Should show mini tablet if it would be oriented toward the camera. // Should show mini tablet if it would be oriented toward the camera.
var pose, var show,
pose,
jointIndex, jointIndex,
handPosition, handPosition,
handOrientation, handOrientation,
uiPositionAndOrientation, uiPositionAndOrientation,
miniPosition, miniPosition,
miniOrientation, miniOrientation,
miniToCameraDirection; miniToCameraDirection,
cameraToHand;
// Shouldn't show mini tablet if hand isn't being controlled.
pose = Controller.getPoseValue(hand === LEFT_HAND ? Controller.Standard.LeftHand : Controller.Standard.RightHand); pose = Controller.getPoseValue(hand === LEFT_HAND ? Controller.Standard.LeftHand : Controller.Standard.RightHand);
if (!pose.valid) { show = pose.valid;
return false;
// Shouldn't show mini tablet on hand if that hand's trigger is pressed (i.e., laser is searching or grabbing
// something) or the other hand's trigger is pressed unless it is pointing at the mini tablet.
if (show) {
show = Controller.getValue(hand === LEFT_HAND ? Controller.Standard.LT : Controller.Standard.RT) <
TRIGGER_OFF_VALUE
&& (Controller.getValue(hand === LEFT_HAND ? Controller.Standard.RT : Controller.Standard.LT) <
TRIGGER_OFF_VALUE || ui.isLaserPointingAt());
}
// Should show mini tablet if it would be oriented toward the camera.
if (show) {
jointIndex = handJointIndex(hand);
handPosition = Vec3.sum(MyAvatar.position,
Vec3.multiplyQbyV(MyAvatar.orientation, MyAvatar.getAbsoluteJointTranslationInObjectFrame(jointIndex)));
handOrientation =
Quat.multiply(MyAvatar.orientation, MyAvatar.getAbsoluteJointRotationInObjectFrame(jointIndex));
uiPositionAndOrientation = ui.getUIPositionAndRotation(hand);
miniPosition = Vec3.sum(handPosition, Vec3.multiply(MyAvatar.scale,
Vec3.multiplyQbyV(handOrientation, uiPositionAndOrientation.position)));
miniOrientation = Quat.multiply(handOrientation, uiPositionAndOrientation.rotation);
miniToCameraDirection = Vec3.normalize(Vec3.subtract(Camera.position, miniPosition));
show = Vec3.dot(miniToCameraDirection, Quat.getForward(miniOrientation)) > MIN_HAND_CAMERA_ANGLE_COS;
cameraToHand = -Vec3.dot(miniToCameraDirection, Quat.getForward(Camera.orientation));
} }
jointIndex = handJointIndex(hand);
handPosition = Vec3.sum(MyAvatar.position,
Vec3.multiplyQbyV(MyAvatar.orientation, MyAvatar.getAbsoluteJointTranslationInObjectFrame(jointIndex)));
handOrientation = Quat.multiply(MyAvatar.orientation, MyAvatar.getAbsoluteJointRotationInObjectFrame(jointIndex));
uiPositionAndOrientation = ui.getUIPositionAndRotation(hand);
miniPosition = Vec3.sum(handPosition, Vec3.multiply(MyAvatar.scale,
Vec3.multiplyQbyV(handOrientation, uiPositionAndOrientation.position)));
miniOrientation = Quat.multiply(handOrientation, uiPositionAndOrientation.rotation);
miniToCameraDirection = Vec3.normalize(Vec3.subtract(Camera.position, miniPosition));
return { return {
show: Vec3.dot(miniToCameraDirection, Quat.getForward(miniOrientation)) > MIN_HAND_CAMERA_ANGLE_COS, show: show,
cameraToHand: -Vec3.dot(miniToCameraDirection, Quat.getForward(Camera.orientation)) cameraToHand: cameraToHand
}; };
} }