cleanup dead code

This commit is contained in:
James B. Pollack 2016-08-02 21:26:04 -07:00
parent 9d56c697e7
commit fed39d9056

View file

@ -1,21 +1,13 @@
// Created by james b. pollack @imgntn on 7/2/2016 // Created by james b. pollack @imgntn on 7/2/2016
// Copyright 2016 High Fidelity, Inc. // Copyright 2016 High Fidelity, Inc.
// //
// Creates a beam and target and then teleports you there when you let go of either activation button. // Creates a beam and target and then teleports you there.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// 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
var inTeleportMode = false; var inTeleportMode = false;
var currentFadeSphereOpacity = 1;
var fadeSphereInterval = null;
var fadeSphereUpdateInterval = null;
//milliseconds between fading one-tenth -- so this is a half second fade total
var USE_FADE_MODE = false;
var USE_FADE_OUT = true;
var FADE_OUT_INTERVAL = 25;
// instant // instant
// var NUMBER_OF_STEPS = 0; // var NUMBER_OF_STEPS = 0;
// var SMOOTH_ARRIVAL_SPACING = 0; // var SMOOTH_ARRIVAL_SPACING = 0;
@ -36,16 +28,13 @@ var NUMBER_OF_STEPS = 6;
// var SMOOTH_ARRIVAL_SPACING = 10; // var SMOOTH_ARRIVAL_SPACING = 10;
// var NUMBER_OF_STEPS = 20; // var NUMBER_OF_STEPS = 20;
var TARGET_MODEL_URL = Script.resolvePath("../assets/models/teleport.fbx"); var TARGET_MODEL_URL = Script.resolvePath("../assets/models/teleport.fbx");
var TARGET_MODEL_DIMENSIONS = { var TARGET_MODEL_DIMENSIONS = {
x: 1.15, x: 1.15,
y: 0.5, y: 0.5,
z: 1.15 z: 1.15
}; };
var COLORS_TELEPORT_CAN_TELEPORT = { var COLORS_TELEPORT_CAN_TELEPORT = {
red: 97, red: 97,
green: 247, green: 247,
@ -58,7 +47,6 @@ var COLORS_TELEPORT_CANNOT_TELEPORT = {
blue: 141 blue: 141
}; };
var MAX_AVATAR_SPEED = 0.25; var MAX_AVATAR_SPEED = 0.25;
function ThumbPad(hand) { function ThumbPad(hand) {
@ -75,7 +63,6 @@ function ThumbPad(hand) {
} }
}; };
} }
function Trigger(hand) { function Trigger(hand) {
@ -101,7 +88,6 @@ function Teleporter() {
this.targetOverlay = null; this.targetOverlay = null;
this.updateConnected = null; this.updateConnected = null;
this.smoothArrivalInterval = null; this.smoothArrivalInterval = null;
this.fadeSphere = null;
this.teleportHand = null; this.teleportHand = null;
this.initialize = function() { this.initialize = function() {
@ -141,86 +127,22 @@ function Teleporter() {
if (isDisabled === 'both') { if (isDisabled === 'both') {
return; return;
} }
inTeleportMode = true; inTeleportMode = true;
if (this.smoothArrivalInterval !== null) { if (this.smoothArrivalInterval !== null) {
Script.clearInterval(this.smoothArrivalInterval); Script.clearInterval(this.smoothArrivalInterval);
} }
if (fadeSphereInterval !== null) {
Script.clearInterval(fadeSphereInterval);
}
if (activationTimeout !== null) { if (activationTimeout !== null) {
Script.clearInterval(activationTimeout); Script.clearInterval(activationTimeout);
} }
this.teleportHand = hand; this.teleportHand = hand;
this.initialize(); this.initialize();
Script.update.connect(this.update); Script.update.connect(this.update);
this.updateConnected = true; this.updateConnected = true;
}; };
this.createFadeSphere = function(avatarHead) {
var sphereProps = {
position: avatarHead,
size: -1,
color: {
red: 0,
green: 0,
blue: 0,
},
alpha: 1,
solid: true,
visible: true,
ignoreRayIntersection: true,
drawInFront: false
};
currentFadeSphereOpacity = 10;
_this.fadeSphere = Overlays.addOverlay("sphere", sphereProps);
Script.clearInterval(fadeSphereInterval)
Script.update.connect(_this.updateFadeSphere);
if (USE_FADE_OUT === true) {
this.fadeSphereOut();
}
};
this.fadeSphereOut = function() {
fadeSphereInterval = Script.setInterval(function() {
if (currentFadeSphereOpacity <= 0) {
Script.clearInterval(fadeSphereInterval);
_this.deleteFadeSphere();
fadeSphereInterval = null;
return;
}
if (currentFadeSphereOpacity > 0) {
currentFadeSphereOpacity = currentFadeSphereOpacity - 1;
}
Overlays.editOverlay(_this.fadeSphere, {
alpha: currentFadeSphereOpacity / 10
})
}, FADE_OUT_INTERVAL);
};
this.updateFadeSphere = function() {
var headPosition = MyAvatar.getHeadPosition();
Overlays.editOverlay(_this.fadeSphere, {
position: headPosition
})
};
this.deleteFadeSphere = function() {
if (_this.fadeSphere !== null) {
Script.update.disconnect(_this.updateFadeSphere);
Overlays.deleteOverlay(_this.fadeSphere);
_this.fadeSphere = null;
}
};
this.deleteTargetOverlay = function() { this.deleteTargetOverlay = function() {
if (this.targetOverlay === null) { if (this.targetOverlay === null) {
@ -288,14 +210,12 @@ function Teleporter() {
this.rightRay = function() { this.rightRay = function() {
var rightPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, Controller.getPoseValue(Controller.Standard.RightHand).translation), MyAvatar.position); var rightPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, Controller.getPoseValue(Controller.Standard.RightHand).translation), MyAvatar.position);
var rightControllerRotation = Controller.getPoseValue(Controller.Standard.RightHand).rotation; var rightControllerRotation = Controller.getPoseValue(Controller.Standard.RightHand).rotation;
var rightRotation = Quat.multiply(MyAvatar.orientation, rightControllerRotation) var rightRotation = Quat.multiply(MyAvatar.orientation, rightControllerRotation)
var rightFinal = Quat.multiply(rightRotation, Quat.angleAxis(90, { var rightFinal = Quat.multiply(rightRotation, Quat.angleAxis(90, {
x: 1, x: 1,
y: 0, y: 0,
@ -335,14 +255,12 @@ function Teleporter() {
var leftRotation = Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(Controller.Standard.LeftHand).rotation) var leftRotation = Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(Controller.Standard.LeftHand).rotation)
var leftFinal = Quat.multiply(leftRotation, Quat.angleAxis(90, { var leftFinal = Quat.multiply(leftRotation, Quat.angleAxis(90, {
x: 1, x: 1,
y: 0, y: 0,
z: 0 z: 0
})); }));
var leftPickRay = { var leftPickRay = {
origin: leftPosition, origin: leftPosition,
direction: Quat.getUp(leftRotation), direction: Quat.getUp(leftRotation),
@ -364,7 +282,6 @@ function Teleporter() {
this.createTargetOverlay(); this.createTargetOverlay();
} }
} else { } else {
this.deleteTargetOverlay(); this.deleteTargetOverlay();
@ -378,7 +295,7 @@ function Teleporter() {
start: closePoint, start: closePoint,
end: farPoint, end: farPoint,
color: color, color: color,
ignoreRayIntersection: true, // always ignore this ignoreRayIntersection: true,
visible: true, visible: true,
alpha: 1, alpha: 1,
solid: true, solid: true,
@ -390,14 +307,9 @@ function Teleporter() {
} else { } else {
var success = Overlays.editOverlay(this.rightOverlayLine, { var success = Overlays.editOverlay(this.rightOverlayLine, {
lineWidth: 50,
start: closePoint, start: closePoint,
end: farPoint, end: farPoint,
color: color, color: color
visible: true,
ignoreRayIntersection: true, // always ignore this
alpha: 1,
glow: 1.0
}); });
} }
}; };
@ -405,7 +317,7 @@ function Teleporter() {
this.leftLineOn = function(closePoint, farPoint, color) { this.leftLineOn = function(closePoint, farPoint, color) {
if (this.leftOverlayLine === null) { if (this.leftOverlayLine === null) {
var lineProperties = { var lineProperties = {
ignoreRayIntersection: true, // always ignore this ignoreRayIntersection: true,
start: closePoint, start: closePoint,
end: farPoint, end: farPoint,
color: color, color: color,
@ -422,11 +334,7 @@ function Teleporter() {
var success = Overlays.editOverlay(this.leftOverlayLine, { var success = Overlays.editOverlay(this.leftOverlayLine, {
start: closePoint, start: closePoint,
end: farPoint, end: farPoint,
color: color, color: color
visible: true,
alpha: 1,
solid: true,
glow: 1.0
}); });
} }
}; };
@ -479,16 +387,11 @@ function Teleporter() {
this.exitTeleportMode(); this.exitTeleportMode();
} }
if (this.intersection !== null) { if (this.intersection !== null) {
if (USE_FADE_MODE === true) {
this.createFadeSphere();
}
var offset = getAvatarFootOffset(); var offset = getAvatarFootOffset();
this.intersection.intersection.y += offset; this.intersection.intersection.y += offset;
this.exitTeleportMode(); this.exitTeleportMode();
this.smoothArrival(); this.smoothArrival();
} }
}; };
@ -498,12 +401,8 @@ function Teleporter() {
return midpoint return midpoint
}; };
this.getArrivalPoints = function(startPoint, endPoint) { this.getArrivalPoints = function(startPoint, endPoint) {
var arrivalPoints = []; var arrivalPoints = [];
var i; var i;
var lastPoint; var lastPoint;
@ -516,9 +415,9 @@ function Teleporter() {
arrivalPoints.push(newPoint); arrivalPoints.push(newPoint);
} }
arrivalPoints.push(endPoint) arrivalPoints.push(endPoint);
return arrivalPoints return arrivalPoints;
}; };
this.smoothArrival = function() { this.smoothArrival = function() {
@ -529,7 +428,6 @@ function Teleporter() {
Script.clearInterval(_this.smoothArrivalInterval); Script.clearInterval(_this.smoothArrivalInterval);
return; return;
} }
var landingPoint = _this.arrivalPoints.shift(); var landingPoint = _this.arrivalPoints.shift();
MyAvatar.position = landingPoint; MyAvatar.position = landingPoint;
@ -537,8 +435,7 @@ function Teleporter() {
_this.deleteTargetOverlay(); _this.deleteTargetOverlay();
} }
}, SMOOTH_ARRIVAL_SPACING);
}, SMOOTH_ARRIVAL_SPACING)
} }
} }
@ -563,14 +460,14 @@ function getAvatarFootOffset() {
toe = d.translation.y; toe = d.translation.y;
} }
if (jointName === "RightToe_End") { if (jointName === "RightToe_End") {
toeTop = d.translation.y toeTop = d.translation.y;
} }
}) })
var myPosition = MyAvatar.position; var myPosition = MyAvatar.position;
var offset = upperLeg + lowerLeg + foot + toe + toeTop; var offset = upperLeg + lowerLeg + foot + toe + toeTop;
offset = offset / 100; offset = offset / 100;
return offset return offset;
}; };
function getJointData() { function getJointData() {
@ -590,11 +487,6 @@ function getJointData() {
return allJointData; return allJointData;
}; };
function getAvatarSpeed() {
return Vec3.length(MyAvatar.velocity)
}
var leftPad = new ThumbPad('left'); var leftPad = new ThumbPad('left');
var rightPad = new ThumbPad('right'); var rightPad = new ThumbPad('right');
var leftTrigger = new Trigger('left'); var leftTrigger = new Trigger('left');
@ -606,13 +498,12 @@ var activationTimeout = null;
var TELEPORT_DELAY = 0; var TELEPORT_DELAY = 0;
function isMoving() { function isMoving() {
var LY = Controller.getValue(Controller.Standard.LY); var LY = Controller.getValue(Controller.Standard.LY);
var LX = Controller.getValue(Controller.Standard.LX); var LX = Controller.getValue(Controller.Standard.LX);
if (LY !== 0 || LX !== 0) { if (LY !== 0 || LX !== 0) {
return true return true;
} else { } else {
return false return false;
} }
} }
@ -639,9 +530,6 @@ function registerMappings() {
if (isMoving() === true) { if (isMoving() === true) {
return; return;
} }
// if (getAvatarSpeed() >= MAX_AVATAR_SPEED) {
// return;
// }
activationTimeout = Script.setTimeout(function() { activationTimeout = Script.setTimeout(function() {
Script.clearTimeout(activationTimeout); Script.clearTimeout(activationTimeout);
activationTimeout = null; activationTimeout = null;
@ -663,9 +551,7 @@ function registerMappings() {
if (isMoving() === true) { if (isMoving() === true) {
return; return;
} }
// if (getAvatarSpeed() >= MAX_AVATAR_SPEED) {
// return;
// }
activationTimeout = Script.setTimeout(function() { activationTimeout = Script.setTimeout(function() {
teleporter.enterTeleportMode('right') teleporter.enterTeleportMode('right')
Script.clearTimeout(activationTimeout); Script.clearTimeout(activationTimeout);
@ -673,7 +559,6 @@ function registerMappings() {
}, TELEPORT_DELAY) }, TELEPORT_DELAY)
return; return;
}); });
} }
registerMappings(); registerMappings();
@ -689,7 +574,6 @@ function cleanup() {
teleporter.disableMappings(); teleporter.disableMappings();
teleporter.deleteTargetOverlay(); teleporter.deleteTargetOverlay();
teleporter.turnOffOverlayBeams(); teleporter.turnOffOverlayBeams();
teleporter.deleteFadeSphere();
if (teleporter.updateConnected !== null) { if (teleporter.updateConnected !== null) {
Script.update.disconnect(teleporter.update); Script.update.disconnect(teleporter.update);
} }