History

naming and some logging for teleport stuff

James B. Pollack committed 10 years ago

Commit b8213ae1 parent 37846d93 files · +50 −22Browse files

Showing the changes to scripts/system/controllers/toggleAdvancedMovementForHandControllers.js (1 of 3 files). Show all

Unified · Split

scripts/system/controllers/toggleAdvancedMovementForHandControllers.js+145−0
@@ -0,0 +1,145 @@
1// Created by james b. pollack @imgntn on 7/2/2016
2// Copyright 2016 High Fidelity, Inc.
3//advanced movements settings are in individual controller json files
4//what we do is check the status of the 'advance movement' checkbox when you enter HMD mode
5//if 'advanced movement' is checked...we give you the defaults that are in the json.
6//if 'advanced movement' is not checked... we override the advanced controls with basic ones.
7//
8// Distributed under the Apache License, Version 2.0.
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10
11var mappingName, basicMapping, isChecked;
12
13var previousSetting = Settings.getValue('advancedMovementForHandControllersIsChecked');
14if (previousSetting === '') {
15 previousSetting = false;
16 isChecked = false;
17}
18
19if (previousSetting === true) {
20 isChecked = true;
21}
22if (previousSetting === false) {
23 isChecked = false;
24}
25
26function addAdvancedMovementItemToSettingsMenu() {
27 Menu.addMenuItem({
28 menuName: "Settings",
29 menuItemName: "Advanced Movement For Hand Controllers",
30 isCheckable: true,
31 isChecked: previousSetting
32 });
33
34}
35
36function rotate180() {
37 MyAvatar.orientation = Quat.inverse(MyAvatar.orientation);
38}
39
40var inFlipTurn = false;
41
42function registerBasicMapping() {
43 mappingName = 'Hifi-AdvancedMovement-Dev-' + Math.random();
44 basicMapping = Controller.newMapping(mappingName);
45 basicMapping.from(Controller.Standard.LY).to(function(value) {
46 var stick = Controller.getValue(Controller.Standard.LS);
47 if (value === 1 && Controller.Hardware.OculusTouch !== undefined) {
48 rotate180();
49 }
50 if (Controller.Hardware.Vive !== undefined) {
51 if (value > 0.75 && inFlipTurn === false) {
52 print('vive should flip turn')
53 inFlipTurn = true;
54 rotate180();
55 Script.setTimeout(function() {
56 print('vive should be able to flip turn again')
57 inFlipTurn = false;
58 }, 250)
59 } else {
60 print('vive should not flip turn')
61
62 }
63 }
64 return;
65 });
66 basicMapping.from(Controller.Standard.LX).to(Controller.Standard.RX);
67 basicMapping.from(Controller.Standard.RY).to(function(value) {
68 var stick = Controller.getValue(Controller.Standard.RS);
69 if (value === 1 && Controller.Hardware.OculusTouch !== undefined) {
70 rotate180();
71 }
72 if (Controller.Hardware.Vive !== undefined) {
73 if (value > 0.75 && inFlipTurn === false) {
74 print('vive should flip turn')
75 inFlipTurn = true;
76 rotate180();
77 Script.setTimeout(function() {
78 print('vive should be able to flip turn again')
79 inFlipTurn = false;
80 }, 250)
81 } else {
82 print('vive should not flip turn')
83
84 }
85 }
86 print('should do RY stuff' + value + ":stick:" + stick);
87 return;
88 })
89}
90
91
92function enableMappings() {
93 Controller.enableMapping(mappingName);
94}
95
96function disableMappings() {
97 Controller.disableMapping(mappingName);
98}
99
100function scriptEnding() {
101 Menu.removeMenuItem("Settings", "Advanced Movement For Hand Controllers");
102 disableMappings();
103}
104
105
106function menuItemEvent(menuItem) {
107 if (menuItem == "Advanced Movement For Hand Controllers") {
108 isChecked = Menu.isOptionChecked("Advanced Movement For Hand Controllers");
109 if (isChecked === true) {
110 Settings.setValue('advancedMovementForHandControllersIsChecked', true);
111 disableMappings();
112 } else if (isChecked === false) {
113 Settings.setValue('advancedMovementForHandControllersIsChecked', false);
114 enableMappings();
115 }
116 }
117
118}
119
120addAdvancedMovementItemToSettingsMenu();
121
122Script.scriptEnding.connect(scriptEnding);
123
124Menu.menuItemEvent.connect(menuItemEvent);
125
126registerBasicMapping();
127if (previousSetting === true) {
128 disableMappings();
129} else if (previousSetting === false) {
130 enableMappings();
131}
132
133
134HMD.displayModeChanged.connect(function(isHMDMode) {
135 if (isHMDMode) {
136 if (Controller.Hardware.Vive !== undefined || Controller.Hardware.OculusTouch !== undefined) {
137 if (isChecked === true) {
138 disableMappings();
139 } else if (isChecked === false) {
140 enableMappings();
141 }
142
143 }
144 }
145});

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