From 68735763df351f14ffe96bcb8d8d24bf628e8f97 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 2 Nov 2016 15:41:35 -0700 Subject: [PATCH] Add support for smooth turning in tutorial --- tutorial/tutorial.js | 45 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/tutorial/tutorial.js b/tutorial/tutorial.js index 4908465779..95a2fcd771 100644 --- a/tutorial/tutorial.js +++ b/tutorial/tutorial.js @@ -715,7 +715,8 @@ var stepTurnAround = function(name) { this.tempTag = name + "-temporary"; this.onActionBound = this.onAction.bind(this); - this.numTimesTurnPressed = 0; + this.numTimesSnapTurnPressed = 0; + this.numTimesSmoothTurnPressed = 0; } stepTurnAround.prototype = { start: function(onFinish) { @@ -724,19 +725,26 @@ stepTurnAround.prototype = { showEntitiesWithTag(this.tag); - this.numTimesTurnPressed = 0; + this.numTimesSnapTurnPressed = 0; + this.numTimesSmoothTurnPressed = 0; + this.smoothTurnDown = false; Controller.actionEvent.connect(this.onActionBound); this.interval = Script.setInterval(function() { - debug("TurnAround | Checking if finished", this.numTimesTurnPressed); + debug("TurnAround | Checking if finished", + this.numTimesSnapTurnPressed, this.numTimesSmoothTurnPressed); var FORWARD_THRESHOLD = 90; - var REQ_NUM_TIMES_PRESSED = 3; + var REQ_NUM_TIMES_SNAP_TURN_PRESSED = 3; + var REQ_NUM_TIMES_SMOOTH_TURN_PRESSED = 2; var dir = Quat.getFront(MyAvatar.orientation); var angle = Math.atan2(dir.z, dir.x); var angleDegrees = ((angle / Math.PI) * 180); - if (this.numTimesTurnPressed >= REQ_NUM_TIMES_PRESSED && Math.abs(angleDegrees) < FORWARD_THRESHOLD) { + var hasTurnedEnough = this.numTimesSnapTurnPressed >= REQ_NUM_TIMES_SNAP_TURN_PRESSED + || this.numTimesSmoothTurnPressed >= REQ_NUM_TIMES_SMOOTH_TURN_PRESSED; + var facingForward = Math.abs(angleDegrees) < FORWARD_THRESHOLD + if (hasTurnedEnough && facingForward) { Script.clearInterval(this.interval); this.interval = null; playSuccessSound(); @@ -745,10 +753,31 @@ stepTurnAround.prototype = { }.bind(this), 100); }, onAction: function(action, value) { - var STEP_YAW_ACTION = 6; + // NOTE(Huffman, 11/2/16): The checks below are for backward compatibility + // Old versions of High Fidelity returned invalid action ids from + // Controller.Actions.Yaw/StepYaw which were above 10000. If they are + // above 10000 then we can assume we are on an old version and hard-code + // the values. Eventually we should remove these checks. + var STEP_YAW_ACTION = Controller.Actions.StepYaw; + if (STEP_YAW_ACTION > 10000) { + STEP_YAW_ACTION = 6; + } + var SMOOTH_YAW_ACTION = Controller.Actions.Yaw; + if (SMOOTH_YAW_ACTION > 10000) { + SMOOTH_YAW_ACTION = 4; + } + if (action == STEP_YAW_ACTION && value != 0) { - debug("TurnAround | Got yaw action"); - this.numTimesTurnPressed += 1; + debug("TurnAround | Got step yaw action"); + ++this.numTimesSnapTurnPressed; + } else if (action == SMOOTH_YAW_ACTION) { + debug("TurnAround | Got smooth yaw action"); + if (this.smoothTurnDown && value === 0) { + this.smoothTurnDown = false; + ++this.numTimesSmoothTurnPressed; + } else if (!this.smoothTurnDown && value !== 0) { + this.smoothTurnDown = true; + } } }, cleanup: function() {