diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index fe7ab67ad9..e2d0dcff8d 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -14,8 +14,6 @@ //parabola: point count, point spacing, graphic thickness - - //Standard.LeftPrimaryThumb //Standard.LT @@ -24,40 +22,119 @@ var teleportMapping = Controller.newMapping('Hifi-Teleporter-Dev-' + Math.random()); Script.scriptEnding.connect(teleportMapping.disable); -// Gather the trigger data for smoothing. -clickMapping.from(Controller.Standard.RT).peek().to(rightTrigger.triggerPress); -clickMapping.from(Controller.Standard.LT).peek().to(leftTrigger.triggerPress); +// peek at the trigger and thumbs to store their values +teleportMapping.from(Controller.Standard.RT).peek().to(rightTrigger.buttonPress); +teleportMapping.from(Controller.Standard.LT).peek().to(leftTrigger.buttonPress); +teleportMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(rightPad.buttonPress); +teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftPad.buttonPress); - -function thumbPad() { +function ThumbPad() { } -thumbPad.prototype = { - down: function() { - return this.padValue === 0 ? true : false; - } -} - -function trigger() { - -} - -trigger.prototype = { - triggerPress: function(value) { - this.triggerValue = value; +ThumbPad.prototype = { + buttonPress: function(value) { + print('pad press: ' + value) + this.buttonValue = value; }, down: function() { - return this.triggerValue === 0 ? true : false; + return this.buttonValue === 0 ? true : false; } } - -teleportMapping.from(thumbPad.down).when(trigger.down).to(teleport); - -function teleport() { +function Trigger() { } -function() {} \ No newline at end of file +Trigger.prototype = { + buttonPress: function(value) { + print('trigger press: ' + value) + this.buttonValue = value; + }, + down: function() { + return this.buttonValue === 0 ? true : false; + } +} + +teleportMapping.from(leftPad.down).when(leftTrigger.down).to(teleporter.enterTeleportMode); +teleportMapping.from(rightPad.down).when(rightTrigger.down).to(teleporter.enterTeleportMode); + + +function Teleporter() { + +} + +Teleporter.prototype = { + enterTeleportMode: function(value) { + print('value on enter: ' + value); + }, + exitTeleportMode: function(value) { + print('value on exit: ' + value); + }, + teleport: function(value) { + //todo + //get the y position of the teleport landing spot + print('value on teleport: ' + value) + var properties = Entities.getEntityProperties(_this.entityID); + var offset = getAvatarFootOffset(); + properties.position.y += offset; + + print('OFFSET IS::: ' + JSON.stringify(offset)) + print('TELEPORT POSITION IS:: ' + JSON.stringify(properties.position)); + MyAvatar.position = properties.position; + } +} + +function getAvatarFootOffset() { + var data = getJointData(); + var upperLeg, lowerLeg, foot, toe, toeTop; + data.forEach(function(d) { + + var jointName = d.joint; + if (jointName === "RightUpLeg") { + upperLeg = d.translation.y; + } + if (jointName === "RightLeg") { + lowerLeg = d.translation.y; + } + if (jointName === "RightFoot") { + foot = d.translation.y; + } + if (jointName === "RightToeBase") { + toe = d.translation.y; + } + if (jointName === "RightToe_End") { + toeTop = d.translation.y + } + }) + + var myPosition = MyAvatar.position; + var offset = upperLeg + lowerLeg + foot + toe + toeTop; + offset = offset / 100; + return offset +}; + +function getJointData() { + var allJointData = []; + var jointNames = MyAvatar.jointNames; + jointNames.forEach(function(joint, index) { + var translation = MyAvatar.getJointTranslation(index); + var rotation = MyAvatar.getJointRotation(index) + allJointData.push({ + joint: joint, + index: index, + translation: translation, + rotation: rotation + }); + }); + + return allJointData; +} + + +var leftPad = new ThumbPad(); +var rightPad = new ThumbPad(); +var leftTrigger = new Trigger(); +var rightTrigger = new Trigger(); +var teleporter = new Teleporter(); \ No newline at end of file