mirror of
https://github.com/overte-org/overte.git
synced 2025-04-11 04:12:09 +02:00
Hide mini tablet if lasering or grabbing something else
This commit is contained in:
parent
de95ee0a18
commit
a1c49bd2b6
2 changed files with 76 additions and 19 deletions
scripts/system
|
@ -18,6 +18,7 @@
|
|||
var // EventBridge
|
||||
READY_MESSAGE = "ready", // Engine <== Dialog
|
||||
HOVER_MESSAGE = "hover", // Engine <== Dialog
|
||||
UNHOVER_MESSAGE = "unhover", // Engine <== Dialog
|
||||
MUTE_MESSAGE = "mute", // Engine <=> Dialog
|
||||
GOTO_MESSAGE = "goto", // 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() {
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
type: HOVER_MESSAGE
|
||||
type: HOVER_MESSAGE,
|
||||
target: "button"
|
||||
}));
|
||||
clearUnhover();
|
||||
}
|
||||
|
@ -128,6 +144,9 @@
|
|||
|
||||
connectEventBridge();
|
||||
|
||||
document.body.addEventListener("mouseenter", onBodyHover, false);
|
||||
document.body.addEventListener("mouseleave", onBodyUnhover, false);
|
||||
|
||||
muteButton.addEventListener("mouseenter", onButtonHover, false);
|
||||
gotoButton.addEventListener("mouseenter", onButtonHover, false);
|
||||
expandButton.addEventListener("mouseenter", onButtonHover, false);
|
||||
|
|
|
@ -8,13 +8,14 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
/* global getTabletWidthFromSettings */
|
||||
/* global getTabletWidthFromSettings, TRIGGER_OFF_VALUE */
|
||||
|
||||
(function () {
|
||||
|
||||
"use strict";
|
||||
|
||||
Script.include("./libraries/utils.js");
|
||||
Script.include("./libraries/controllerDispatcherUtils.js");
|
||||
|
||||
var UI,
|
||||
ui = null,
|
||||
|
@ -147,9 +148,13 @@
|
|||
miniTargetWidth,
|
||||
miniTargetLocalRotation,
|
||||
|
||||
// Laser pointing at.
|
||||
isBodyHovered = false,
|
||||
|
||||
// EventBridge.
|
||||
READY_MESSAGE = "ready", // Engine <== Dialog
|
||||
HOVER_MESSAGE = "hover", // Engine <== Dialog
|
||||
UNHOVER_MESSAGE = "unhover", // Engine <== Dialog
|
||||
MUTE_MESSAGE = "mute", // Engine <=> Dialog
|
||||
GOTO_MESSAGE = "goto", // Engine <=> Dialog
|
||||
EXPAND_MESSAGE = "expand", // Engine <== Dialog
|
||||
|
@ -196,8 +201,19 @@
|
|||
setGotoIcon();
|
||||
break;
|
||||
case HOVER_MESSAGE:
|
||||
// Audio feedback.
|
||||
playSound(hoverSound, HOVER_VOLUME);
|
||||
if (message.target === "body") {
|
||||
// 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;
|
||||
case MUTE_MESSAGE:
|
||||
// Toggle mute.
|
||||
|
@ -253,6 +269,10 @@
|
|||
};
|
||||
}
|
||||
|
||||
function isLaserPointingAt() {
|
||||
return isBodyHovered;
|
||||
}
|
||||
|
||||
|
||||
function show(hand) {
|
||||
var initialScale = 0.01; // Start very small.
|
||||
|
@ -420,6 +440,7 @@
|
|||
getUIPositionAndRotation: getUIPositionAndRotation,
|
||||
getMiniTabletID: getMiniTabletID,
|
||||
getMiniTabletProperties: getMiniTabletProperties,
|
||||
isLaserPointingAt: isLaserPointingAt,
|
||||
updateMutedStatus: updateMutedStatus,
|
||||
show: show,
|
||||
size: size,
|
||||
|
@ -509,32 +530,49 @@
|
|||
|
||||
function shouldShowMini(hand) {
|
||||
// Should show mini tablet if it would be oriented toward the camera.
|
||||
var pose,
|
||||
var show,
|
||||
pose,
|
||||
jointIndex,
|
||||
handPosition,
|
||||
handOrientation,
|
||||
uiPositionAndOrientation,
|
||||
miniPosition,
|
||||
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);
|
||||
if (!pose.valid) {
|
||||
return false;
|
||||
show = pose.valid;
|
||||
|
||||
// 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 {
|
||||
show: Vec3.dot(miniToCameraDirection, Quat.getForward(miniOrientation)) > MIN_HAND_CAMERA_ANGLE_COS,
|
||||
cameraToHand: -Vec3.dot(miniToCameraDirection, Quat.getForward(Camera.orientation))
|
||||
show: show,
|
||||
cameraToHand: cameraToHand
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue