better handling of the teleport target overlays to prevent flashing and thrashing

This commit is contained in:
Brad Hefta-Gaub 2016-10-13 18:24:38 -07:00
parent 90b283f83b
commit ef3c9ba78a

View file

@ -91,7 +91,6 @@ function Teleporter() {
this.tooClose = false; this.tooClose = false;
this.inCoolIn = false; this.inCoolIn = false;
this.initialize = function() { this.initialize = function() {
this.createMappings(); this.createMappings();
}; };
@ -142,7 +141,10 @@ function Teleporter() {
}; };
this.createTargetOverlay = function() { this.createTargetOverlay = function(visible) {
if (visible == undefined) {
visible = true;
}
if (_this.targetOverlay !== null) { if (_this.targetOverlay !== null) {
return; return;
@ -150,20 +152,17 @@ function Teleporter() {
var targetOverlayProps = { var targetOverlayProps = {
url: TARGET_MODEL_URL, url: TARGET_MODEL_URL,
dimensions: TARGET_MODEL_DIMENSIONS, dimensions: TARGET_MODEL_DIMENSIONS,
visible: true visible: visible
};
var cancelOverlayProps = {
url: TOO_CLOSE_MODEL_URL,
dimensions: TARGET_MODEL_DIMENSIONS,
visible: true
}; };
_this.targetOverlay = Overlays.addOverlay("model", targetOverlayProps); _this.targetOverlay = Overlays.addOverlay("model", targetOverlayProps);
}; };
this.createCancelOverlay = function() { this.createCancelOverlay = function(visible) {
if (visible == undefined) {
visible = true;
}
if (_this.cancelOverlay !== null) { if (_this.cancelOverlay !== null) {
return; return;
@ -172,7 +171,7 @@ function Teleporter() {
var cancelOverlayProps = { var cancelOverlayProps = {
url: TOO_CLOSE_MODEL_URL, url: TOO_CLOSE_MODEL_URL,
dimensions: TARGET_MODEL_DIMENSIONS, dimensions: TARGET_MODEL_DIMENSIONS,
visible: true visible: visible
}; };
_this.cancelOverlay = Overlays.addOverlay("model", cancelOverlayProps); _this.cancelOverlay = Overlays.addOverlay("model", cancelOverlayProps);
@ -187,6 +186,23 @@ function Teleporter() {
this.cancelOverlay = null; this.cancelOverlay = null;
} }
this.hideCancelOverlay = function() {
if (this.cancelOverlay === null) {
return;
}
this.intersection = null;
Overlays.editOverlay(this.cancelOverlay, { visible: false });
}
this.showCancelOverlay = function() {
if (this.cancelOverlay === null) {
return this.createCancelOverlay();
}
Overlays.editOverlay(this.cancelOverlay, { visible: true });
}
this.deleteTargetOverlay = function() { this.deleteTargetOverlay = function() {
if (this.targetOverlay === null) { if (this.targetOverlay === null) {
return; return;
@ -197,6 +213,22 @@ function Teleporter() {
this.targetOverlay = null; this.targetOverlay = null;
} }
this.hideTargetOverlay = function() {
if (this.targetOverlay === null) {
return;
}
this.intersection = null;
Overlays.editOverlay(this.targetOverlay, { visible: false });
}
this.showTargetOverlay = function() {
if (this.targetOverlay === null) {
return this.createTargetOverlay();
}
Overlays.editOverlay(this.targetOverlay, { visible: true });
}
this.turnOffOverlayBeams = function() { this.turnOffOverlayBeams = function() {
this.rightOverlayOff(); this.rightOverlayOff();
this.leftOverlayOff(); this.leftOverlayOff();
@ -232,8 +264,8 @@ function Teleporter() {
if ((leftPad.buttonValue === 0) && inTeleportMode === true) { if ((leftPad.buttonValue === 0) && inTeleportMode === true) {
if (_this.inCoolIn === true) { if (_this.inCoolIn === true) {
_this.exitTeleportMode(); _this.exitTeleportMode();
_this.deleteTargetOverlay(); _this.hideTargetOverlay();
_this.deleteCancelOverlay(); _this.hideCancelOverlay();
} else { } else {
_this.teleport(); _this.teleport();
} }
@ -248,8 +280,8 @@ function Teleporter() {
if ((rightPad.buttonValue === 0) && inTeleportMode === true) { if ((rightPad.buttonValue === 0) && inTeleportMode === true) {
if (_this.inCoolIn === true) { if (_this.inCoolIn === true) {
_this.exitTeleportMode(); _this.exitTeleportMode();
_this.deleteTargetOverlay(); _this.hideTargetOverlay();
_this.deleteCancelOverlay(); _this.hideCancelOverlay();
} else { } else {
_this.teleport(); _this.teleport();
} }
@ -283,7 +315,7 @@ function Teleporter() {
if (rightIntersection.intersects) { if (rightIntersection.intersects) {
if (this.tooClose === true) { if (this.tooClose === true) {
this.deleteTargetOverlay(); this.hideTargetOverlay();
this.rightLineOn(rightPickRay.origin, rightIntersection.intersection, COLORS_TELEPORT_TOO_CLOSE); this.rightLineOn(rightPickRay.origin, rightIntersection.intersection, COLORS_TELEPORT_TOO_CLOSE);
if (this.cancelOverlay !== null) { if (this.cancelOverlay !== null) {
@ -293,7 +325,7 @@ function Teleporter() {
} }
} else { } else {
if (this.inCoolIn === true) { if (this.inCoolIn === true) {
this.deleteTargetOverlay(); this.hideTargetOverlay();
this.rightLineOn(rightPickRay.origin, rightIntersection.intersection, COLORS_TELEPORT_TOO_CLOSE); this.rightLineOn(rightPickRay.origin, rightIntersection.intersection, COLORS_TELEPORT_TOO_CLOSE);
if (this.cancelOverlay !== null) { if (this.cancelOverlay !== null) {
this.updateCancelOverlay(rightIntersection); this.updateCancelOverlay(rightIntersection);
@ -301,7 +333,7 @@ function Teleporter() {
this.createCancelOverlay(); this.createCancelOverlay();
} }
} else { } else {
this.deleteCancelOverlay(); this.hideCancelOverlay();
this.rightLineOn(rightPickRay.origin, rightIntersection.intersection, COLORS_TELEPORT_CAN_TELEPORT); this.rightLineOn(rightPickRay.origin, rightIntersection.intersection, COLORS_TELEPORT_CAN_TELEPORT);
if (this.targetOverlay !== null) { if (this.targetOverlay !== null) {
@ -316,7 +348,7 @@ function Teleporter() {
} else { } else {
this.deleteTargetOverlay(); this.hideTargetOverlay();
this.rightLineOn(rightPickRay.origin, location, COLORS_TELEPORT_CANNOT_TELEPORT); this.rightLineOn(rightPickRay.origin, location, COLORS_TELEPORT_CANNOT_TELEPORT);
} }
} }
@ -347,7 +379,7 @@ function Teleporter() {
if (leftIntersection.intersects) { if (leftIntersection.intersects) {
if (this.tooClose === true) { if (this.tooClose === true) {
this.deleteTargetOverlay(); this.hideTargetOverlay();
this.leftLineOn(leftPickRay.origin, leftIntersection.intersection, COLORS_TELEPORT_TOO_CLOSE); this.leftLineOn(leftPickRay.origin, leftIntersection.intersection, COLORS_TELEPORT_TOO_CLOSE);
if (this.cancelOverlay !== null) { if (this.cancelOverlay !== null) {
this.updateCancelOverlay(leftIntersection); this.updateCancelOverlay(leftIntersection);
@ -356,7 +388,7 @@ function Teleporter() {
} }
} else { } else {
if (this.inCoolIn === true) { if (this.inCoolIn === true) {
this.deleteTargetOverlay(); this.hideTargetOverlay();
this.leftLineOn(leftPickRay.origin, leftIntersection.intersection, COLORS_TELEPORT_TOO_CLOSE); this.leftLineOn(leftPickRay.origin, leftIntersection.intersection, COLORS_TELEPORT_TOO_CLOSE);
if (this.cancelOverlay !== null) { if (this.cancelOverlay !== null) {
this.updateCancelOverlay(leftIntersection); this.updateCancelOverlay(leftIntersection);
@ -364,7 +396,7 @@ function Teleporter() {
this.createCancelOverlay(); this.createCancelOverlay();
} }
} else { } else {
this.deleteCancelOverlay(); this.hideCancelOverlay();
this.leftLineOn(leftPickRay.origin, leftIntersection.intersection, COLORS_TELEPORT_CAN_TELEPORT); this.leftLineOn(leftPickRay.origin, leftIntersection.intersection, COLORS_TELEPORT_CAN_TELEPORT);
if (this.targetOverlay !== null) { if (this.targetOverlay !== null) {
@ -380,7 +412,7 @@ function Teleporter() {
} else { } else {
this.deleteTargetOverlay(); this.hideTargetOverlay();
this.leftLineOn(leftPickRay.origin, location, COLORS_TELEPORT_CANNOT_TELEPORT); this.leftLineOn(leftPickRay.origin, location, COLORS_TELEPORT_CANNOT_TELEPORT);
} }
}; };
@ -463,6 +495,7 @@ function Teleporter() {
var towardUs = Quat.fromPitchYawRollDegrees(0, euler.y, 0); var towardUs = Quat.fromPitchYawRollDegrees(0, euler.y, 0);
Overlays.editOverlay(this.targetOverlay, { Overlays.editOverlay(this.targetOverlay, {
visible: true,
position: position, position: position,
rotation: towardUs rotation: towardUs
}); });
@ -484,6 +517,7 @@ function Teleporter() {
var towardUs = Quat.fromPitchYawRollDegrees(0, euler.y, 0); var towardUs = Quat.fromPitchYawRollDegrees(0, euler.y, 0);
Overlays.editOverlay(this.cancelOverlay, { Overlays.editOverlay(this.cancelOverlay, {
visible: true,
position: position, position: position,
rotation: towardUs rotation: towardUs
}); });
@ -503,7 +537,7 @@ function Teleporter() {
if (this.intersection !== null) { if (this.intersection !== null) {
if (this.tooClose === true) { if (this.tooClose === true) {
this.exitTeleportMode(); this.exitTeleportMode();
this.deleteCancelOverlay(); this.hideCancelOverlay();
return; return;
} }
var offset = getAvatarFootOffset(); var offset = getAvatarFootOffset();
@ -512,8 +546,8 @@ function Teleporter() {
// Disable smooth arrival, possibly temporarily // Disable smooth arrival, possibly temporarily
//this.smoothArrival(); //this.smoothArrival();
MyAvatar.position = _this.intersection.intersection; MyAvatar.position = _this.intersection.intersection;
_this.deleteTargetOverlay(); _this.hideTargetOverlay();
_this.deleteCancelOverlay(); _this.hideCancelOverlay();
HMD.centerUI(); HMD.centerUI();
} }
}; };
@ -556,14 +590,16 @@ function Teleporter() {
MyAvatar.position = landingPoint; MyAvatar.position = landingPoint;
if (_this.arrivalPoints.length === 1 || _this.arrivalPoints.length === 0) { if (_this.arrivalPoints.length === 1 || _this.arrivalPoints.length === 0) {
_this.deleteTargetOverlay(); _this.hideTargetOverlay();
_this.deleteCancelOverlay(); _this.hideCancelOverlay();
} }
}, SMOOTH_ARRIVAL_SPACING); }, SMOOTH_ARRIVAL_SPACING);
} }
this.createTargetOverlay(false);
this.createCancelOverlay(false);
} }
//related to repositioning the avatar after you teleport //related to repositioning the avatar after you teleport