mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 20:22:34 +02:00
put tracked hand walk into a controller-dispatcher module
This commit is contained in:
parent
4d3da24c33
commit
865584e7e3
4 changed files with 108 additions and 72 deletions
|
@ -34,7 +34,6 @@ var DEFAULT_SCRIPTS_COMBINED = [
|
|||
"system/emote.js",
|
||||
"system/miniTablet.js",
|
||||
"system/audioMuteOverlay.js",
|
||||
"system/inspect.js",
|
||||
"system/keyboardShortcuts/keyboardShortcuts.js",
|
||||
"system/hand-track-walk.js"
|
||||
];
|
||||
|
|
106
scripts/system/controllers/controllerModules/trackedHandWalk.js
Normal file
106
scripts/system/controllers/controllerModules/trackedHandWalk.js
Normal file
|
@ -0,0 +1,106 @@
|
|||
"use strict";
|
||||
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
/* global Script, RIGHT_HAND, LEFT_HAND, makeRunningValues, enableDispatcherModule, disableDispatcherModule,
|
||||
makeDispatcherModuleParameters, handsAreTracked, Controller, Vec3
|
||||
*/
|
||||
|
||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
Script.include("/~/system/libraries/controllers.js");
|
||||
|
||||
(function() {
|
||||
|
||||
function TrackedHandWalk(hand) {
|
||||
this.mappingName = 'hand-track-walk-' + Math.random();
|
||||
this.inputMapping = Controller.newMapping(this.mappingName);
|
||||
this.leftIndexPos = null;
|
||||
this.rightIndexPos = null;
|
||||
this.pinchOnBelowDistance = 0.016;
|
||||
this.pinchOffAboveDistance = 0.04;
|
||||
this.walking = false;
|
||||
|
||||
this.parameters = makeDispatcherModuleParameters(
|
||||
80,
|
||||
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
|
||||
[],
|
||||
100);
|
||||
|
||||
this.updateWalking = function () {
|
||||
if (this.leftIndexPos && this.rightIndexPos) {
|
||||
var tipDistance = Vec3.distance(this.leftIndexPos, this.rightIndexPos);
|
||||
if (tipDistance < this.pinchOnBelowDistance) {
|
||||
this.walking = true;
|
||||
} else if (this.walking && tipDistance > this.pinchOffAboveDistance) {
|
||||
this.walking = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.leftIndexChanged = function (pose) {
|
||||
if (pose.valid) {
|
||||
this.leftIndexPos = pose.translation;
|
||||
} else {
|
||||
this.leftIndexPos = null;
|
||||
}
|
||||
this.updateWalking();
|
||||
};
|
||||
|
||||
this.rightIndexChanged = function (pose) {
|
||||
if (pose.valid) {
|
||||
this.rightIndexPos = pose.translation;
|
||||
} else {
|
||||
this.rightIndexPos = null;
|
||||
}
|
||||
this.updateWalking();
|
||||
};
|
||||
|
||||
this.isReady = function (controllerData) {
|
||||
if (!handsAreTracked()) {
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
if (this.walking) {
|
||||
return makeRunningValues(true, [], []);
|
||||
}
|
||||
};
|
||||
|
||||
this.run = function (controllerData) {
|
||||
return this.isReady(controllerData);
|
||||
};
|
||||
|
||||
this.setup = function () {
|
||||
var _this = this;
|
||||
this.inputMapping.from(Controller.Standard.LeftHandIndex4).peek().to(function (pose) {
|
||||
_this.leftIndexChanged(pose);
|
||||
});
|
||||
this.inputMapping.from(Controller.Standard.RightHandIndex4).peek().to(function (pose) {
|
||||
_this.rightIndexChanged(pose);
|
||||
});
|
||||
|
||||
this.inputMapping.from(function() {
|
||||
if (_this.walking) {
|
||||
return -1;
|
||||
} else {
|
||||
return Controller.getActionValue(Controller.Standard.TranslateZ);
|
||||
}
|
||||
}).to(Controller.Actions.TranslateZ);
|
||||
|
||||
Controller.enableMapping(this.mappingName);
|
||||
};
|
||||
|
||||
this.cleanUp = function () {
|
||||
this.inputMapping.disable();
|
||||
};
|
||||
}
|
||||
|
||||
var trackedHandWalk = new TrackedHandWalk(LEFT_HAND);
|
||||
trackedHandWalk.setup();
|
||||
enableDispatcherModule("TrackedHandWalk", trackedHandWalk);
|
||||
|
||||
function cleanup() {
|
||||
trackedHandWalk.cleanUp();
|
||||
disableDispatcherModule("TrackedHandWalk");
|
||||
}
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
}());
|
|
@ -18,7 +18,6 @@ var CONTOLLER_SCRIPTS = [
|
|||
//"toggleAdvancedMovementForHandControllers.js",
|
||||
"handTouch.js",
|
||||
"controllerDispatcher.js",
|
||||
// "controllerModules/nearParentGrabOverlay.js",
|
||||
"controllerModules/stylusInput.js",
|
||||
"controllerModules/equipEntity.js",
|
||||
"controllerModules/nearTrigger.js",
|
||||
|
@ -34,7 +33,8 @@ var CONTOLLER_SCRIPTS = [
|
|||
"controllerModules/nearTabletHighlight.js",
|
||||
"controllerModules/nearGrabEntity.js",
|
||||
"controllerModules/farGrabEntity.js",
|
||||
"controllerModules/pushToTalk.js"
|
||||
"controllerModules/pushToTalk.js",
|
||||
"controllerModules/trackedHandWalk.js"
|
||||
];
|
||||
|
||||
var DEBUG_MENU_ITEM = "Debug defaultScripts.js";
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
|
||||
/* global Script, Controller, Vec3 */
|
||||
/* jshint loopfunc:true */
|
||||
|
||||
(function() {
|
||||
|
||||
var mappingName = 'hand-track-walk-' + Math.random();
|
||||
var inputMapping = Controller.newMapping(mappingName);
|
||||
|
||||
var leftIndexPos = null;
|
||||
var rightIndexPos = null;
|
||||
|
||||
var pinchOnBelowDistance = 0.016;
|
||||
var pinchOffAboveDistance = 0.04;
|
||||
|
||||
var walking = false;
|
||||
|
||||
function updateWalking() {
|
||||
if (leftIndexPos && rightIndexPos) {
|
||||
var tipDistance = Vec3.distance(leftIndexPos, rightIndexPos);
|
||||
if (tipDistance < pinchOnBelowDistance) {
|
||||
print("qqqq walking");
|
||||
walking = true;
|
||||
} else if (walking && tipDistance > pinchOffAboveDistance) {
|
||||
print("qqqq stopping");
|
||||
walking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function leftIndexChanged(pose) {
|
||||
if (pose.valid) {
|
||||
leftIndexPos = pose.translation;
|
||||
} else {
|
||||
leftIndexPos = null;
|
||||
}
|
||||
updateWalking();
|
||||
}
|
||||
|
||||
function rightIndexChanged(pose) {
|
||||
if (pose.valid) {
|
||||
rightIndexPos = pose.translation;
|
||||
} else {
|
||||
rightIndexPos = null;
|
||||
}
|
||||
updateWalking();
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
inputMapping.disable();
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
cleanUp();
|
||||
});
|
||||
|
||||
inputMapping.from(Controller.Standard.LeftHandIndex4).peek().to(leftIndexChanged);
|
||||
inputMapping.from(Controller.Standard.RightHandIndex4).peek().to(rightIndexChanged);
|
||||
|
||||
inputMapping.from(function() {
|
||||
if (walking) {
|
||||
return -1;
|
||||
} else {
|
||||
return Controller.getActionValue(Controller.Standard.TranslateZ);
|
||||
}
|
||||
}).to(Controller.Actions.TranslateZ);
|
||||
|
||||
Controller.enableMapping(mappingName);
|
||||
})();
|
Loading…
Reference in a new issue