mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:18:24 +02:00
Merge pull request #8654 from ZappoMan/betterAway
fix away HMD unmouted logic
This commit is contained in:
commit
8ac31a041d
2 changed files with 73 additions and 35 deletions
|
@ -635,7 +635,11 @@ void OpenVrDisplayPlugin::postPreview() {
|
||||||
_nextSimPoseData = nextSim;
|
_nextSimPoseData = nextSim;
|
||||||
});
|
});
|
||||||
_nextRenderPoseData = nextRender;
|
_nextRenderPoseData = nextRender;
|
||||||
|
|
||||||
|
// FIXME - this looks wrong!
|
||||||
_hmdActivityLevel = vr::k_EDeviceActivityLevel_UserInteraction; // _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd);
|
_hmdActivityLevel = vr::k_EDeviceActivityLevel_UserInteraction; // _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd);
|
||||||
|
#else
|
||||||
|
_hmdActivityLevel = _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
(function() { // BEGIN LOCAL_SCOPE
|
(function() { // BEGIN LOCAL_SCOPE
|
||||||
|
|
||||||
|
var BASIC_TIMER_INTERVAL = 50; // 50ms = 20hz
|
||||||
var OVERLAY_WIDTH = 1920;
|
var OVERLAY_WIDTH = 1920;
|
||||||
var OVERLAY_HEIGHT = 1080;
|
var OVERLAY_HEIGHT = 1080;
|
||||||
var OVERLAY_DATA = {
|
var OVERLAY_DATA = {
|
||||||
|
@ -49,6 +50,21 @@ var AWAY_INTRO = {
|
||||||
endFrame: 83.0
|
endFrame: 83.0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// MAIN CONTROL
|
||||||
|
var isEnabled = true;
|
||||||
|
var wasMuted; // unknonwn?
|
||||||
|
var isAway = false; // we start in the un-away state
|
||||||
|
var wasOverlaysVisible = Menu.isOptionChecked("Overlays");
|
||||||
|
var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too.
|
||||||
|
var eventMapping = Controller.newMapping(eventMappingName);
|
||||||
|
var avatarPosition = MyAvatar.position;
|
||||||
|
var wasHmdMounted = HMD.mounted;
|
||||||
|
|
||||||
|
|
||||||
|
// some intervals we may create/delete
|
||||||
|
var avatarMovedInterval;
|
||||||
|
|
||||||
|
|
||||||
// prefetch the kneel animation and hold a ref so it's always resident in memory when we need it.
|
// prefetch the kneel animation and hold a ref so it's always resident in memory when we need it.
|
||||||
var _animation = AnimationCache.prefetch(AWAY_INTRO.url);
|
var _animation = AnimationCache.prefetch(AWAY_INTRO.url);
|
||||||
|
|
||||||
|
@ -125,41 +141,28 @@ function maybeMoveOverlay() {
|
||||||
var halfWayBetweenOldAndLookAt = Vec3.multiply(lookAtChange, EASE_BY_RATIO);
|
var halfWayBetweenOldAndLookAt = Vec3.multiply(lookAtChange, EASE_BY_RATIO);
|
||||||
var newOverlayPosition = Vec3.sum(lastOverlayPosition, halfWayBetweenOldAndLookAt);
|
var newOverlayPosition = Vec3.sum(lastOverlayPosition, halfWayBetweenOldAndLookAt);
|
||||||
lastOverlayPosition = newOverlayPosition;
|
lastOverlayPosition = newOverlayPosition;
|
||||||
|
|
||||||
var actualOverlayPositon = moveCloserToCamera(lastOverlayPosition);
|
var actualOverlayPositon = moveCloserToCamera(lastOverlayPosition);
|
||||||
Overlays.editOverlay(overlayHMD, { visible: true, position: actualOverlayPositon });
|
Overlays.editOverlay(overlayHMD, { visible: true, position: actualOverlayPositon });
|
||||||
|
|
||||||
// make sure desktop version is hidden
|
// make sure desktop version is hidden
|
||||||
Overlays.editOverlay(overlay, { visible: false });
|
Overlays.editOverlay(overlay, { visible: false });
|
||||||
|
|
||||||
|
// also remember avatar position
|
||||||
|
avatarPosition = MyAvatar.position;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ifAvatarMovedGoActive() {
|
function ifAvatarMovedGoActive() {
|
||||||
if (Vec3.distance(MyAvatar.position, avatarPosition) > AVATAR_MOVE_FOR_ACTIVE_DISTANCE) {
|
var newAvatarPosition = MyAvatar.position;
|
||||||
|
if (Vec3.distance(newAvatarPosition, avatarPosition) > AVATAR_MOVE_FOR_ACTIVE_DISTANCE) {
|
||||||
goActive();
|
goActive();
|
||||||
}
|
}
|
||||||
|
avatarPosition = newAvatarPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MAIN CONTROL
|
function goAway(fromStartup) {
|
||||||
var isEnabled = true;
|
|
||||||
var wasMuted, isAway;
|
|
||||||
var wasOverlaysVisible = Menu.isOptionChecked("Overlays");
|
|
||||||
var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too.
|
|
||||||
var eventMapping = Controller.newMapping(eventMappingName);
|
|
||||||
var avatarPosition = MyAvatar.position;
|
|
||||||
|
|
||||||
// backward compatible version of getting HMD.mounted, so it works in old clients
|
|
||||||
function safeGetHMDMounted() {
|
|
||||||
if (HMD.mounted === undefined) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return HMD.mounted;
|
|
||||||
}
|
|
||||||
|
|
||||||
var wasHmdMounted = safeGetHMDMounted();
|
|
||||||
|
|
||||||
function goAway() {
|
|
||||||
if (!isEnabled || isAway) {
|
if (!isEnabled || isAway) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +170,6 @@ function goAway() {
|
||||||
UserActivityLogger.toggledAway(true);
|
UserActivityLogger.toggledAway(true);
|
||||||
|
|
||||||
isAway = true;
|
isAway = true;
|
||||||
print('going "away"');
|
|
||||||
wasMuted = AudioDevice.getMuted();
|
wasMuted = AudioDevice.getMuted();
|
||||||
if (!wasMuted) {
|
if (!wasMuted) {
|
||||||
AudioDevice.toggleMute();
|
AudioDevice.toggleMute();
|
||||||
|
@ -189,10 +191,21 @@ function goAway() {
|
||||||
// For HMD, the hmd preview will show the system mouse because of allowMouseCapture,
|
// For HMD, the hmd preview will show the system mouse because of allowMouseCapture,
|
||||||
// but we want to turn off our Reticle so that we don't get two in preview and a stuck one in headset.
|
// but we want to turn off our Reticle so that we don't get two in preview and a stuck one in headset.
|
||||||
Reticle.visible = !HMD.active;
|
Reticle.visible = !HMD.active;
|
||||||
wasHmdMounted = safeGetHMDMounted(); // always remember the correct state
|
wasHmdMounted = HMD.mounted; // always remember the correct state
|
||||||
|
|
||||||
avatarPosition = MyAvatar.position;
|
avatarPosition = MyAvatar.position;
|
||||||
Script.update.connect(ifAvatarMovedGoActive);
|
|
||||||
|
// If we're entering away mode from some other state than startup, then we create our move timer immediately.
|
||||||
|
// However if we're just stating up, we need to delay this process so that we don't think the initial teleport
|
||||||
|
// is actually a move.
|
||||||
|
if (fromStartup === undefined || fromStartup === false) {
|
||||||
|
avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL);
|
||||||
|
} else {
|
||||||
|
var WAIT_FOR_MOVE_ON_STARTUP = 3000; // 3 seconds
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL);
|
||||||
|
}, WAIT_FOR_MOVE_ON_STARTUP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function goActive() {
|
function goActive() {
|
||||||
|
@ -203,7 +216,6 @@ function goActive() {
|
||||||
UserActivityLogger.toggledAway(false);
|
UserActivityLogger.toggledAway(false);
|
||||||
|
|
||||||
isAway = false;
|
isAway = false;
|
||||||
print('going "active"');
|
|
||||||
if (!wasMuted) {
|
if (!wasMuted) {
|
||||||
AudioDevice.toggleMute();
|
AudioDevice.toggleMute();
|
||||||
}
|
}
|
||||||
|
@ -230,9 +242,9 @@ function goActive() {
|
||||||
if (HMD.active) {
|
if (HMD.active) {
|
||||||
Reticle.position = HMD.getHUDLookAtPosition2D();
|
Reticle.position = HMD.getHUDLookAtPosition2D();
|
||||||
}
|
}
|
||||||
wasHmdMounted = safeGetHMDMounted(); // always remember the correct state
|
wasHmdMounted = HMD.mounted; // always remember the correct state
|
||||||
|
|
||||||
Script.update.disconnect(ifAvatarMovedGoActive);
|
Script.clearInterval(avatarMovedInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeGoActive(event) {
|
function maybeGoActive(event) {
|
||||||
|
@ -250,10 +262,12 @@ var wasHmdActive = HMD.active;
|
||||||
var wasMouseCaptured = Reticle.mouseCaptured;
|
var wasMouseCaptured = Reticle.mouseCaptured;
|
||||||
|
|
||||||
function maybeGoAway() {
|
function maybeGoAway() {
|
||||||
|
// If our active state change (went to or from HMD mode), and we are now in the HMD, go into away
|
||||||
if (HMD.active !== wasHmdActive) {
|
if (HMD.active !== wasHmdActive) {
|
||||||
wasHmdActive = !wasHmdActive;
|
wasHmdActive = !wasHmdActive;
|
||||||
if (wasHmdActive) {
|
if (wasHmdActive) {
|
||||||
goAway();
|
goAway();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,19 +278,30 @@ function maybeGoAway() {
|
||||||
wasMouseCaptured = !wasMouseCaptured;
|
wasMouseCaptured = !wasMouseCaptured;
|
||||||
if (!wasMouseCaptured) {
|
if (!wasMouseCaptured) {
|
||||||
goAway();
|
goAway();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If you've removed your HMD from your head, and we can detect it, we will also go away...
|
// If you've removed your HMD from your head, and we can detect it, we will also go away...
|
||||||
var hmdMounted = safeGetHMDMounted();
|
if (HMD.mounted != wasHmdMounted) {
|
||||||
if (HMD.active && !hmdMounted && wasHmdMounted) {
|
wasHmdMounted = HMD.mounted;
|
||||||
wasHmdMounted = hmdMounted;
|
print("HMD mounted changed...");
|
||||||
|
|
||||||
|
// We're putting the HMD on... switch to those devices
|
||||||
|
if (HMD.mounted) {
|
||||||
|
print("NOW mounted...");
|
||||||
|
} else {
|
||||||
|
print("HMD NOW un-mounted...");
|
||||||
|
|
||||||
|
if (HMD.active) {
|
||||||
goAway();
|
goAway();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setEnabled(value) {
|
function setEnabled(value) {
|
||||||
print("setting away enabled: ", value);
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
goActive();
|
goActive();
|
||||||
}
|
}
|
||||||
|
@ -293,9 +318,12 @@ var handleMessage = function(channel, message, sender) {
|
||||||
Messages.subscribe(CHANNEL_AWAY_ENABLE);
|
Messages.subscribe(CHANNEL_AWAY_ENABLE);
|
||||||
Messages.messageReceived.connect(handleMessage);
|
Messages.messageReceived.connect(handleMessage);
|
||||||
|
|
||||||
Script.update.connect(maybeMoveOverlay);
|
var maybeIntervalTimer = Script.setInterval(function(){
|
||||||
|
maybeMoveOverlay();
|
||||||
|
maybeGoAway();
|
||||||
|
}, BASIC_TIMER_INTERVAL);
|
||||||
|
|
||||||
|
|
||||||
Script.update.connect(maybeGoAway);
|
|
||||||
Controller.mousePressEvent.connect(goActive);
|
Controller.mousePressEvent.connect(goActive);
|
||||||
Controller.keyPressEvent.connect(maybeGoActive);
|
Controller.keyPressEvent.connect(maybeGoActive);
|
||||||
// Note peek() so as to not interfere with other mappings.
|
// Note peek() so as to not interfere with other mappings.
|
||||||
|
@ -316,11 +344,17 @@ eventMapping.from(Controller.Standard.Start).peek().to(goActive);
|
||||||
Controller.enableMapping(eventMappingName);
|
Controller.enableMapping(eventMappingName);
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
Script.update.disconnect(maybeGoAway);
|
Script.clearInterval(maybeIntervalTimer);
|
||||||
goActive();
|
goActive();
|
||||||
Controller.disableMapping(eventMappingName);
|
Controller.disableMapping(eventMappingName);
|
||||||
Controller.mousePressEvent.disconnect(goActive);
|
Controller.mousePressEvent.disconnect(goActive);
|
||||||
Controller.keyPressEvent.disconnect(maybeGoActive);
|
Controller.keyPressEvent.disconnect(maybeGoActive);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (HMD.active && !HMD.mounted) {
|
||||||
|
print("Starting script, while HMD is active and not mounted...");
|
||||||
|
goAway(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}()); // END LOCAL_SCOPE
|
}()); // END LOCAL_SCOPE
|
||||||
|
|
Loading…
Reference in a new issue