mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-18 09:26:13 +02:00
double OK to open/close tablet. touch thumb-tips to walk backwards
This commit is contained in:
parent
865584e7e3
commit
600c2c3947
3 changed files with 218 additions and 17 deletions
|
@ -0,0 +1,142 @@
|
|||
"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, makeRunningValues, enableDispatcherModule, disableDispatcherModule,
|
||||
makeDispatcherModuleParameters, handsAreTracked, Controller, Vec3, Tablet, HMD, MyAvatar
|
||||
*/
|
||||
|
||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
Script.include("/~/system/libraries/controllers.js");
|
||||
|
||||
(function() {
|
||||
|
||||
function TrackedHandTablet() {
|
||||
this.mappingName = 'hand-track-tablet-' + Math.random();
|
||||
this.inputMapping = Controller.newMapping(this.mappingName);
|
||||
this.leftIndexPos = null;
|
||||
this.leftThumbPos = null;
|
||||
this.rightIndexPos = null;
|
||||
this.rightThumbPos = null;
|
||||
this.touchOnBelowDistance = 0.016;
|
||||
this.touchOffAboveDistance = 0.045;
|
||||
|
||||
this.gestureCompleted = false;
|
||||
this.previousGestureCompleted = false;
|
||||
|
||||
this.parameters = makeDispatcherModuleParameters(
|
||||
70,
|
||||
["rightHand", "leftHand"],
|
||||
[],
|
||||
100);
|
||||
|
||||
this.checkForGesture = function () {
|
||||
if (this.leftThumbPos && this.leftIndexPos && this.rightThumbPos && this.rightIndexPos) {
|
||||
var leftTipDistance = Vec3.distance(this.leftThumbPos, this.leftIndexPos);
|
||||
var rightTipDistance = Vec3.distance(this.rightThumbPos, this.rightIndexPos);
|
||||
if (leftTipDistance < this.touchOnBelowDistance && rightTipDistance < this.touchOnBelowDistance) {
|
||||
this.gestureCompleted = true;
|
||||
} else if (leftTipDistance > this.touchOffAboveDistance || rightTipDistance > this.touchOffAboveDistance) {
|
||||
this.gestureCompleted = false;
|
||||
}
|
||||
} else {
|
||||
this.gestureCompleted = false;
|
||||
}
|
||||
|
||||
if (this.gestureCompleted && !this.previousGestureCompleted) {
|
||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
if (HMD.showTablet) {
|
||||
HMD.closeTablet(false);
|
||||
} else if (!HMD.showTablet && !tablet.toolbarMode && !MyAvatar.isAway) {
|
||||
tablet.gotoHomeScreen();
|
||||
HMD.openTablet(false);
|
||||
}
|
||||
}
|
||||
|
||||
this.previousGestureCompleted = this.gestureCompleted;
|
||||
};
|
||||
|
||||
this.leftIndexChanged = function (pose) {
|
||||
if (pose.valid) {
|
||||
this.leftIndexPos = pose.translation;
|
||||
} else {
|
||||
this.leftIndexPos = null;
|
||||
}
|
||||
this.checkForGesture();
|
||||
};
|
||||
|
||||
this.leftThumbChanged = function (pose) {
|
||||
if (pose.valid) {
|
||||
this.leftThumbPos = pose.translation;
|
||||
} else {
|
||||
this.leftThumbPos = null;
|
||||
}
|
||||
this.checkForGesture();
|
||||
};
|
||||
|
||||
this.rightIndexChanged = function (pose) {
|
||||
if (pose.valid) {
|
||||
this.rightIndexPos = pose.translation;
|
||||
} else {
|
||||
this.rightIndexPos = null;
|
||||
}
|
||||
this.checkForGesture();
|
||||
};
|
||||
|
||||
this.rightThumbChanged = function (pose) {
|
||||
if (pose.valid) {
|
||||
this.rightThumbPos = pose.translation;
|
||||
} else {
|
||||
this.rightThumbPos = null;
|
||||
}
|
||||
this.checkForGesture();
|
||||
};
|
||||
|
||||
this.isReady = function (controllerData) {
|
||||
if (!handsAreTracked()) {
|
||||
return makeRunningValues(false, [], []);
|
||||
} else if (this.gestureCompleted) {
|
||||
return makeRunningValues(true, [], []);
|
||||
} else {
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
};
|
||||
|
||||
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.LeftHandThumb4).peek().to(function (pose) {
|
||||
_this.leftThumbChanged(pose);
|
||||
});
|
||||
this.inputMapping.from(Controller.Standard.RightHandIndex4).peek().to(function (pose) {
|
||||
_this.rightIndexChanged(pose);
|
||||
});
|
||||
this.inputMapping.from(Controller.Standard.RightHandThumb4).peek().to(function (pose) {
|
||||
_this.rightThumbChanged(pose);
|
||||
});
|
||||
|
||||
Controller.enableMapping(this.mappingName);
|
||||
};
|
||||
|
||||
this.cleanUp = function () {
|
||||
this.inputMapping.disable();
|
||||
};
|
||||
}
|
||||
|
||||
var trackedHandWalk = new TrackedHandTablet();
|
||||
trackedHandWalk.setup();
|
||||
enableDispatcherModule("TrackedHandTablet", trackedHandWalk);
|
||||
|
||||
function cleanup() {
|
||||
trackedHandWalk.cleanUp();
|
||||
disableDispatcherModule("TrackedHandTablet");
|
||||
}
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
}());
|
|
@ -3,7 +3,7 @@
|
|||
// 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,
|
||||
/* global Script, makeRunningValues, enableDispatcherModule, disableDispatcherModule,
|
||||
makeDispatcherModuleParameters, handsAreTracked, Controller, Vec3
|
||||
*/
|
||||
|
||||
|
@ -12,28 +12,46 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
|
||||
(function() {
|
||||
|
||||
function TrackedHandWalk(hand) {
|
||||
function TrackedHandWalk() {
|
||||
this.mappingName = 'hand-track-walk-' + Math.random();
|
||||
this.inputMapping = Controller.newMapping(this.mappingName);
|
||||
this.leftIndexPos = null;
|
||||
this.leftThumbPos = null;
|
||||
this.rightIndexPos = null;
|
||||
this.pinchOnBelowDistance = 0.016;
|
||||
this.pinchOffAboveDistance = 0.04;
|
||||
this.walking = false;
|
||||
this.rightThumbPos = null;
|
||||
this.touchOnBelowDistance = 0.016;
|
||||
this.touchOffAboveDistance = 0.045;
|
||||
this.walkingForward = false;
|
||||
this.walkingBackward = false;
|
||||
|
||||
this.parameters = makeDispatcherModuleParameters(
|
||||
80,
|
||||
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
|
||||
["rightHand", "leftHand"],
|
||||
[],
|
||||
100);
|
||||
|
||||
this.getControlPoint = function () {
|
||||
return Vec3.multiply(Vec3.sum(this.leftIndexPos, this.rightIndexPos), 0.5);
|
||||
};
|
||||
|
||||
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;
|
||||
var indexTipDistance = Vec3.distance(this.leftIndexPos, this.rightIndexPos);
|
||||
if (indexTipDistance < this.touchOnBelowDistance) {
|
||||
this.walkingForward = true;
|
||||
this.controlPoint = this.getControlPoint();
|
||||
} else if (this.walkingForward && indexTipDistance > this.touchOffAboveDistance) {
|
||||
this.walkingForward = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.leftThumbPos && this.rightThumbPos) {
|
||||
var thumbTipDistance = Vec3.distance(this.leftThumbPos, this.rightThumbPos);
|
||||
if (thumbTipDistance < this.touchOnBelowDistance) {
|
||||
this.walkingBackward = true;
|
||||
this.controlPoint = this.getControlPoint();
|
||||
} else if (this.walkingBackward && thumbTipDistance > this.touchOffAboveDistance) {
|
||||
this.walkingBackward = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -47,6 +65,15 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
this.updateWalking();
|
||||
};
|
||||
|
||||
this.leftThumbChanged = function (pose) {
|
||||
if (pose.valid) {
|
||||
this.leftThumbPos = pose.translation;
|
||||
} else {
|
||||
this.leftThumbPos = null;
|
||||
}
|
||||
this.updateWalking();
|
||||
};
|
||||
|
||||
this.rightIndexChanged = function (pose) {
|
||||
if (pose.valid) {
|
||||
this.rightIndexPos = pose.translation;
|
||||
|
@ -56,12 +83,22 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
this.updateWalking();
|
||||
};
|
||||
|
||||
this.rightThumbChanged = function (pose) {
|
||||
if (pose.valid) {
|
||||
this.rightThumbPos = pose.translation;
|
||||
} else {
|
||||
this.rightThumbPos = null;
|
||||
}
|
||||
this.updateWalking();
|
||||
};
|
||||
|
||||
this.isReady = function (controllerData) {
|
||||
if (!handsAreTracked()) {
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
if (this.walking) {
|
||||
} else if (this.walkingForward || this.walkingBackward) {
|
||||
return makeRunningValues(true, [], []);
|
||||
} else {
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -74,18 +111,39 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
this.inputMapping.from(Controller.Standard.LeftHandIndex4).peek().to(function (pose) {
|
||||
_this.leftIndexChanged(pose);
|
||||
});
|
||||
this.inputMapping.from(Controller.Standard.LeftHandThumb4).peek().to(function (pose) {
|
||||
_this.leftThumbChanged(pose);
|
||||
});
|
||||
this.inputMapping.from(Controller.Standard.RightHandIndex4).peek().to(function (pose) {
|
||||
_this.rightIndexChanged(pose);
|
||||
});
|
||||
this.inputMapping.from(Controller.Standard.RightHandThumb4).peek().to(function (pose) {
|
||||
_this.rightThumbChanged(pose);
|
||||
});
|
||||
|
||||
this.inputMapping.from(function() {
|
||||
if (_this.walking) {
|
||||
return -1;
|
||||
if (_this.walkingForward) {
|
||||
// var currentPoint = _this.getControlPoint();
|
||||
// return currentPoint.z - _this.controlPoint.z;
|
||||
return -0.5;
|
||||
} else if (_this.walkingBackward) {
|
||||
// var currentPoint = _this.getControlPoint();
|
||||
// return currentPoint.z - _this.controlPoint.z;
|
||||
return 0.5;
|
||||
} else {
|
||||
return Controller.getActionValue(Controller.Standard.TranslateZ);
|
||||
}
|
||||
}).to(Controller.Actions.TranslateZ);
|
||||
|
||||
// this.inputMapping.from(function() {
|
||||
// if (_this.walkingForward) {
|
||||
// var currentPoint = _this.getControlPoint();
|
||||
// return currentPoint.x - _this.controlPoint.x;
|
||||
// } else {
|
||||
// return Controller.getActionValue(Controller.Standard.Yaw);
|
||||
// }
|
||||
// }).to(Controller.Actions.Yaw);
|
||||
|
||||
Controller.enableMapping(this.mappingName);
|
||||
};
|
||||
|
||||
|
@ -94,7 +152,7 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
};
|
||||
}
|
||||
|
||||
var trackedHandWalk = new TrackedHandWalk(LEFT_HAND);
|
||||
var trackedHandWalk = new TrackedHandWalk();
|
||||
trackedHandWalk.setup();
|
||||
enableDispatcherModule("TrackedHandWalk", trackedHandWalk);
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ var CONTOLLER_SCRIPTS = [
|
|||
"controllerModules/nearGrabEntity.js",
|
||||
"controllerModules/farGrabEntity.js",
|
||||
"controllerModules/pushToTalk.js",
|
||||
"controllerModules/trackedHandWalk.js"
|
||||
"controllerModules/trackedHandWalk.js",
|
||||
"controllerModules/trackedHandTablet.js"
|
||||
];
|
||||
|
||||
var DEBUG_MENU_ITEM = "Debug defaultScripts.js";
|
||||
|
|
Loading…
Reference in a new issue