History

Add support for smooth turning in tutorial

Ryan Huffman committed 10 years ago

Commit 68735761 parent 8350dc41 file · +37 −8Browse files

Showing the changes to tutorial/tutorial.js (1 of 1 file). Show all

Unified · Split

tutorial/tutorial.js+37−8
@@ -715,7 +715,8 @@ var stepTurnAround = function(name) { · 714 unmodified lines
715 this.tempTag = name + "-temporary";715 this.tempTag = name + "-temporary";
716 716
717 this.onActionBound = this.onAction.bind(this);717 this.onActionBound = this.onAction.bind(this);
718 this.numTimesTurnPressed = 0;718 this.numTimesSnapTurnPressed = 0;
719 this.numTimesSmoothTurnPressed = 0;
719}720}
720stepTurnAround.prototype = {721stepTurnAround.prototype = {
721 start: function(onFinish) {722 start: function(onFinish) {
@@ -724,19 +725,26 @@ stepTurnAround.prototype = { · 2 unmodified lines
724 725
725 showEntitiesWithTag(this.tag);726 showEntitiesWithTag(this.tag);
726 727
727 this.numTimesTurnPressed = 0;728 this.numTimesSnapTurnPressed = 0;
729 this.numTimesSmoothTurnPressed = 0;
730 this.smoothTurnDown = false;
728 Controller.actionEvent.connect(this.onActionBound);731 Controller.actionEvent.connect(this.onActionBound);
729 732
730 this.interval = Script.setInterval(function() {733 this.interval = Script.setInterval(function() {
731 debug("TurnAround | Checking if finished", this.numTimesTurnPressed);734 debug("TurnAround | Checking if finished",
735 this.numTimesSnapTurnPressed, this.numTimesSmoothTurnPressed);
732 var FORWARD_THRESHOLD = 90;736 var FORWARD_THRESHOLD = 90;
733 var REQ_NUM_TIMES_PRESSED = 3;737 var REQ_NUM_TIMES_SNAP_TURN_PRESSED = 3;
738 var REQ_NUM_TIMES_SMOOTH_TURN_PRESSED = 2;
734 739
735 var dir = Quat.getFront(MyAvatar.orientation);740 var dir = Quat.getFront(MyAvatar.orientation);
736 var angle = Math.atan2(dir.z, dir.x);741 var angle = Math.atan2(dir.z, dir.x);
737 var angleDegrees = ((angle / Math.PI) * 180);742 var angleDegrees = ((angle / Math.PI) * 180);
738 743
739 if (this.numTimesTurnPressed >= REQ_NUM_TIMES_PRESSED && Math.abs(angleDegrees) < FORWARD_THRESHOLD) {744 var hasTurnedEnough = this.numTimesSnapTurnPressed >= REQ_NUM_TIMES_SNAP_TURN_PRESSED
745 || this.numTimesSmoothTurnPressed >= REQ_NUM_TIMES_SMOOTH_TURN_PRESSED;
746 var facingForward = Math.abs(angleDegrees) < FORWARD_THRESHOLD
747 if (hasTurnedEnough && facingForward) {
740 Script.clearInterval(this.interval);748 Script.clearInterval(this.interval);
741 this.interval = null;749 this.interval = null;
742 playSuccessSound();750 playSuccessSound();
@@ -745,10 +753,31 @@ stepTurnAround.prototype = { · 2 unmodified lines
745 }.bind(this), 100);753 }.bind(this), 100);
746 },754 },
747 onAction: function(action, value) {755 onAction: function(action, value) {
748 var STEP_YAW_ACTION = 6;756 // NOTE(Huffman, 11/2/16): The checks below are for backward compatibility
757 // Old versions of High Fidelity returned invalid action ids from
758 // Controller.Actions.Yaw/StepYaw which were above 10000. If they are
759 // above 10000 then we can assume we are on an old version and hard-code
760 // the values. Eventually we should remove these checks.
761 var STEP_YAW_ACTION = Controller.Actions.StepYaw;
762 if (STEP_YAW_ACTION > 10000) {
763 STEP_YAW_ACTION = 6;
764 }
765 var SMOOTH_YAW_ACTION = Controller.Actions.Yaw;
766 if (SMOOTH_YAW_ACTION > 10000) {
767 SMOOTH_YAW_ACTION = 4;
768 }
769
749 if (action == STEP_YAW_ACTION && value != 0) {770 if (action == STEP_YAW_ACTION && value != 0) {
750 debug("TurnAround | Got yaw action");771 debug("TurnAround | Got step yaw action");
751 this.numTimesTurnPressed += 1;772 ++this.numTimesSnapTurnPressed;
773 } else if (action == SMOOTH_YAW_ACTION) {
774 debug("TurnAround | Got smooth yaw action");
775 if (this.smoothTurnDown && value === 0) {
776 this.smoothTurnDown = false;
777 ++this.numTimesSmoothTurnPressed;
778 } else if (!this.smoothTurnDown && value !== 0) {
779 this.smoothTurnDown = true;
780 }
752 }781 }
753 },782 },
754 cleanup: function() {783 cleanup: function() {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t