From 8350dc47f4ece46d475321955349747d8d55cdfa Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 2 Nov 2016 15:40:58 -0700 Subject: [PATCH 1/4] Fix Controller.Actions not returning correct values --- libraries/controllers/src/controllers/ScriptingInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index d32acb3d82..a690561813 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -68,7 +68,7 @@ controller::ScriptingInterface::ScriptingInterface() { // Expose the IDs to JS QString cleanActionName = QString(actionName).remove(SANITIZE_NAME_EXPRESSION); - _actions.insert(cleanActionName, actionInput.getID()); + _actions.insert(cleanActionName, actionInput.getChannel()); } updateMaps(); From 68735763df351f14ffe96bcb8d8d24bf628e8f97 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 2 Nov 2016 15:41:35 -0700 Subject: [PATCH 2/4] 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() { From f6c0a451deccc18da8058c921d5565d37f54b596 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 2 Nov 2016 15:53:29 -0700 Subject: [PATCH 3/4] Revert "Fix Controller.Actions not returning correct values" This reverts commit 8350dc47f4ece46d475321955349747d8d55cdfa. --- libraries/controllers/src/controllers/ScriptingInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index a690561813..d32acb3d82 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -68,7 +68,7 @@ controller::ScriptingInterface::ScriptingInterface() { // Expose the IDs to JS QString cleanActionName = QString(actionName).remove(SANITIZE_NAME_EXPRESSION); - _actions.insert(cleanActionName, actionInput.getChannel()); + _actions.insert(cleanActionName, actionInput.getID()); } updateMaps(); From cf975f966735437ac7547bfcaa9cff5280cea084 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 2 Nov 2016 15:56:19 -0700 Subject: [PATCH 4/4] Update step/smooth yaw action values to be hardcoded --- tutorial/tutorial.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tutorial/tutorial.js b/tutorial/tutorial.js index 95a2fcd771..4de418eb19 100644 --- a/tutorial/tutorial.js +++ b/tutorial/tutorial.js @@ -753,19 +753,8 @@ stepTurnAround.prototype = { }.bind(this), 100); }, onAction: function(action, value) { - // 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; - } + var STEP_YAW_ACTION = 6; + var SMOOTH_YAW_ACTION = 4; if (action == STEP_YAW_ACTION && value != 0) { debug("TurnAround | Got step yaw action");