fix away HMD unmouted logic

This commit is contained in:
Brad Hefta-Gaub 2016-09-23 16:17:28 -07:00
parent 89288b3ed5
commit c4a80996d5

View file

@ -148,15 +148,7 @@ var eventMappingName = "io.highfidelity.away"; // goActive on hand controller bu
var eventMapping = Controller.newMapping(eventMappingName); var eventMapping = Controller.newMapping(eventMappingName);
var avatarPosition = MyAvatar.position; var avatarPosition = MyAvatar.position;
// backward compatible version of getting HMD.mounted, so it works in old clients var wasHmdMounted = HMD.mounted;
function safeGetHMDMounted() {
if (HMD.mounted === undefined) {
return true;
}
return HMD.mounted;
}
var wasHmdMounted = safeGetHMDMounted();
function goAway() { function goAway() {
if (isAway) { if (isAway) {
@ -188,7 +180,7 @@ 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); Script.update.connect(ifAvatarMovedGoActive);
@ -229,7 +221,7 @@ 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.update.disconnect(ifAvatarMovedGoActive);
} }
@ -249,6 +241,8 @@ 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) {
@ -267,11 +261,21 @@ function maybeGoAway() {
} }
// 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) { print("HMD mounted changed...");
wasHmdMounted = hmdMounted;
goAway(); // 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();
}
}
} }
wasHmdMounted = HMD.mounted;
} }
Script.update.connect(maybeMoveOverlay); Script.update.connect(maybeMoveOverlay);