fix some bugs and also change it to use arrival mode

This commit is contained in:
James B. Pollack 2016-07-08 14:50:21 -07:00
parent 1cda8afa40
commit 38e580b211

View file

@ -8,8 +8,7 @@
//FEATURES: //FEATURES:
// ENTRY MODES // ENTRY MODE
// Thumbpad only
// Thumpad + trigger // Thumpad + trigger
// JUMP MODES // JUMP MODES
@ -28,15 +27,13 @@ var currentFadeSphereOpacity = 1;
var fadeSphereInterval = null; var fadeSphereInterval = null;
var fadeSphereUpdateInterval = null; var fadeSphereUpdateInterval = null;
//milliseconds between fading one-tenth -- so this is a half second fade total //milliseconds between fading one-tenth -- so this is a half second fade total
var USE_FADE_MODE = true; var USE_FADE_MODE = false;
var USE_FADE_IN = false;
var USE_FADE_OUT = true; var USE_FADE_OUT = true;
var FADE_IN_INTERVAL = 25;
var FADE_OUT_INTERVAL = 25; 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;
// // slow // // slow
// var SMOOTH_ARRIVAL_SPACING = 150; // var SMOOTH_ARRIVAL_SPACING = 150;
@ -46,17 +43,15 @@ var SMOOTH_ARRIVAL_SPACING = 0;
// var SMOOTH_ARRIVAL_SPACING = 100; // var SMOOTH_ARRIVAL_SPACING = 100;
// var NUMBER_OF_STEPS = 4; // var NUMBER_OF_STEPS = 4;
//medium-fast // medium-fast
// var SMOOTH_ARRIVAL_SPACING = 33; var SMOOTH_ARRIVAL_SPACING = 33;
// var NUMBER_OF_STEPS = 6; var NUMBER_OF_STEPS = 6;
//fast //fast
// var SMOOTH_ARRIVAL_SPACING = 10; // var SMOOTH_ARRIVAL_SPACING = 10;
// var NUMBER_OF_STEPS = 20; // var NUMBER_OF_STEPS = 20;
var USE_THUMB_AND_TRIGGER_MODE = true;
var TARGET_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/teleporter/target.fbx'; var TARGET_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/teleporter/target.fbx';
var TARGET_MODEL_DIMENSIONS = { var TARGET_MODEL_DIMENSIONS = {
x: 1.15, x: 1.15,
@ -67,15 +62,13 @@ var TARGET_MODEL_DIMENSIONS = {
function ThumbPad(hand) { function ThumbPad(hand) {
this.hand = hand; this.hand = hand;
var _this = this; var _thisPad = this;
this.buttonPress = function(value) { this.buttonPress = function(value) {
_this.buttonValue = value; _thisPad.buttonValue = value;
}; };
this.down = function() {
return _this.buttonValue === 1 ? 1.0 : 0.0;
};
} }
function Trigger(hand) { function Trigger(hand) {
@ -88,14 +81,14 @@ function Trigger(hand) {
}; };
this.down = function() { this.down = function() {
return _this.buttonValue === 1 ? 1.0 : 0.0; var down = _this.buttonValue === 1 ? 1.0 : 0.0;
return down
}; };
} }
function Teleporter() { function Teleporter() {
var _this = this; var _this = this;
this.intersection = null; this.intersection = null;
this.targetProps = null;
this.rightOverlayLine = null; this.rightOverlayLine = null;
this.leftOverlayLine = null; this.leftOverlayLine = null;
this.targetOverlay = null; this.targetOverlay = null;
@ -133,32 +126,22 @@ function Teleporter() {
}; };
this.enterTeleportMode = function(hand) { this.enterTeleportMode = function(hand) {
print('entered teleport from ' + hand)
if (inTeleportMode === true) { if (inTeleportMode === true) {
print('already in teleport mode so dont enter again')
return; return;
} }
inTeleportMode = true;
if (this.smoothArrivalInterval !== null) { if (this.smoothArrivalInterval !== null) {
Script.clearInterval(this.smoothArrivalInterval); Script.clearInterval(this.smoothArrivalInterval);
} }
inTeleportMode = true; if (fadeSphereInterval !== null) {
Script.clearInterval(fadeSphereInterval);
}
this.teleportHand = hand; this.teleportHand = hand;
this.initialize(); this.initialize();
this.updateConnected = true;
Script.update.connect(this.update); Script.update.connect(this.update);
this.updateConnected = true;
}; };
this.findMidpoint = function(start, end) {
var xy = Vec3.sum(start, end);
var midpoint = Vec3.multiply(0.5, xy);
return midpoint
};
this.createFadeSphere = function(avatarHead) { this.createFadeSphere = function(avatarHead) {
var sphereProps = { var sphereProps = {
position: avatarHead, position: avatarHead,
@ -183,9 +166,7 @@ function Teleporter() {
if (USE_FADE_OUT === true) { if (USE_FADE_OUT === true) {
this.fadeSphereOut(); this.fadeSphereOut();
} }
if (USE_FADE_IN === true) {
this.fadeSphereIn();
}
}; };
@ -209,23 +190,6 @@ function Teleporter() {
}, FADE_OUT_INTERVAL); }, FADE_OUT_INTERVAL);
}; };
this.fadeSphereIn = function() {
fadeSphereInterval = Script.setInterval(function() {
if (currentFadeSphereOpacity >= 1) {
Script.clearInterval(fadeSphereInterval);
_this.deleteFadeSphere();
fadeSphereInterval = null;
return;
}
if (currentFadeSphereOpacity < 1) {
currentFadeSphereOpacity = currentFadeSphereOpacity - 1;
}
Overlays.editOverlay(_this.fadeSphere, {
alpha: currentFadeSphereOpacity / 10
})
}, FADE_IN_INTERVAL);
};
this.updateFadeSphere = function() { this.updateFadeSphere = function() {
var headPosition = MyAvatar.getHeadPosition(); var headPosition = MyAvatar.getHeadPosition();
@ -255,16 +219,16 @@ function Teleporter() {
} }
this.exitTeleportMode = function(value) { this.exitTeleportMode = function(value) {
print('exiting teleport mode') if (this.updateConnected === true) {
Script.update.disconnect(this.update);
Script.update.disconnect(this.update); }
this.teleportHand = null;
this.updateConnected = null;
this.disableMappings(); this.disableMappings();
this.turnOffOverlayBeams(); this.turnOffOverlayBeams();
this.enableGrab(); this.enableGrab();
this.updateConnected = null;
Script.setTimeout(function() { Script.setTimeout(function() {
print('fully exited teleport mode')
inTeleportMode = false; inTeleportMode = false;
}, 100); }, 100);
}; };
@ -277,7 +241,6 @@ function Teleporter() {
teleporter.leftRay(); teleporter.leftRay();
if ((leftPad.buttonValue === 0 || leftTrigger.buttonValue === 0) && inTeleportMode === true) { if ((leftPad.buttonValue === 0 || leftTrigger.buttonValue === 0) && inTeleportMode === true) {
print('TELEPORTING LEFT')
_this.teleport(); _this.teleport();
return; return;
} }
@ -286,8 +249,6 @@ function Teleporter() {
teleporter.rightRay(); teleporter.rightRay();
if ((rightPad.buttonValue === 0 || rightTrigger.buttonValue === 0) && inTeleportMode === true) { if ((rightPad.buttonValue === 0 || rightTrigger.buttonValue === 0) && inTeleportMode === true) {
print('TELEPORTING RIGHT')
_this.teleport(); _this.teleport();
return; return;
} }
@ -337,12 +298,12 @@ function Teleporter() {
} else { } else {
this.deleteTargetOverlay();
this.rightLineOn(rightPickRay.origin, location, { this.rightLineOn(rightPickRay.origin, location, {
red: 7, red: 7,
green: 36, green: 36,
blue: 44 blue: 44
}); });
this.deleteTargetOverlay();
} }
} }
@ -388,12 +349,13 @@ function Teleporter() {
} else { } else {
this.deleteTargetOverlay();
this.leftLineOn(leftPickRay.origin, location, { this.leftLineOn(leftPickRay.origin, location, {
red: 7, red: 7,
green: 36, green: 36,
blue: 44 blue: 44
}); });
this.deleteTargetOverlay();
} }
}; };
@ -501,7 +463,9 @@ function Teleporter() {
}; };
this.teleport = function(value) { this.teleport = function(value) {
print('teleporting : ' + value) if (value === undefined) {
this.exitTeleportMode();
}
if (this.intersection !== null) { if (this.intersection !== null) {
if (USE_FADE_MODE === true) { if (USE_FADE_MODE === true) {
this.createFadeSphere(); this.createFadeSphere();
@ -516,6 +480,15 @@ function Teleporter() {
}; };
this.findMidpoint = function(start, end) {
var xy = Vec3.sum(start, end);
var midpoint = Vec3.multiply(0.5, xy);
return midpoint
};
this.getArrivalPoints = function(startPoint, endPoint) { this.getArrivalPoints = function(startPoint, endPoint) {
var arrivalPoints = []; var arrivalPoints = [];
@ -540,23 +513,17 @@ function Teleporter() {
this.smoothArrival = function() { this.smoothArrival = function() {
_this.arrivalPoints = _this.getArrivalPoints(MyAvatar.position, _this.intersection.intersection); _this.arrivalPoints = _this.getArrivalPoints(MyAvatar.position, _this.intersection.intersection);
print('ARRIVAL POINTS: ' + JSON.stringify(_this.arrivalPoints));
print('end point: ' + JSON.stringify(_this.intersection.intersection))
_this.smoothArrivalInterval = Script.setInterval(function() { _this.smoothArrivalInterval = Script.setInterval(function() {
print(_this.arrivalPoints.length + " arrival points remaining")
if (_this.arrivalPoints.length === 0) { if (_this.arrivalPoints.length === 0) {
Script.clearInterval(_this.smoothArrivalInterval); Script.clearInterval(_this.smoothArrivalInterval);
return; return;
} }
var landingPoint = _this.arrivalPoints.shift(); var landingPoint = _this.arrivalPoints.shift();
print('landing at: ' + JSON.stringify(landingPoint))
MyAvatar.position = landingPoint; MyAvatar.position = landingPoint;
if (_this.arrivalPoints.length === 1 || _this.arrivalPoints.length === 0) { if (_this.arrivalPoints.length === 1 || _this.arrivalPoints.length === 0) {
print('clear target overlay')
_this.deleteTargetOverlay(); _this.deleteTargetOverlay();
_this.triggerHaptics();
} }
@ -633,29 +600,28 @@ function registerMappings() {
teleportMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(rightPad.buttonPress); teleportMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(rightPad.buttonPress);
teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftPad.buttonPress); teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftPad.buttonPress);
teleportMapping.from(leftPad.down).when(leftTrigger.down).to(function(value) { teleportMapping.from(Controller.Standard.LeftPrimaryThumb).when(leftTrigger.down).to(function(value) {
print('tel 1') print('tel 1')
teleporter.enterTeleportMode('left') teleporter.enterTeleportMode('left')
return; return;
}); });
teleportMapping.from(rightPad.down).when(rightTrigger.down).to(function(value) { teleportMapping.from(Controller.Standard.RightPrimaryThumb).when(rightTrigger.down).to(function(value) {
print('tel 2') print('tel 2')
teleporter.enterTeleportMode('right') teleporter.enterTeleportMode('right')
return; return;
}); });
teleportMapping.from(leftTrigger.down).when(leftPad.down).to(function(value) { teleportMapping.from(Controller.Standard.RT).when(Controller.Standard.RightPrimaryThumb).to(function(value) {
print('tel 3') print('tel 3')
teleporter.enterTeleportMode('right')
return;
});
teleportMapping.from(Controller.Standard.LT).when(Controller.Standard.LeftPrimaryThumb).to(function(value) {
print('tel 4')
teleporter.enterTeleportMode('left') teleporter.enterTeleportMode('left')
return; return;
}); });
teleportMapping.from(rightTrigger.down).when(rightPad.down).to(function(value) {
print('tel 4')
teleporter.enterTeleportMode('right')
return;
});
} }
@ -674,12 +640,6 @@ function cleanup() {
teleporter.turnOffOverlayBeams(); teleporter.turnOffOverlayBeams();
teleporter.deleteFadeSphere(); teleporter.deleteFadeSphere();
if (teleporter.updateConnected !== null) { if (teleporter.updateConnected !== null) {
Script.update.disconnect(teleporter.update);
if (USE_THUMB_AND_TRIGGER_MODE === true) {
Script.update.disconnect(teleporter.updateForThumbAndTrigger);
} else {
Script.update.disconnect(teleporter.update);
}
} }
} }