equip/de-equip with thumb button rather than bumper. trigger and bumper do the same thing

This commit is contained in:
Seth Alves 2016-03-14 15:25:59 -07:00
parent a7a8bd2256
commit 7e5a1e73e5

View file

@ -20,7 +20,7 @@ Script.include("../libraries/utils.js");
// add lines where the hand ray picking is happening // add lines where the hand ray picking is happening
// //
var WANT_DEBUG = false; var WANT_DEBUG = false;
var WANT_DEBUG_STATE = false; var WANT_DEBUG_STATE = true;
var WANT_DEBUG_SEARCH_NAME = null; var WANT_DEBUG_SEARCH_NAME = null;
// //
@ -34,6 +34,8 @@ var TRIGGER_OFF_VALUE = 0.15;
var BUMPER_ON_VALUE = 0.5; var BUMPER_ON_VALUE = 0.5;
var THUMB_ON_VALUE = 0.5;
var HAND_HEAD_MIX_RATIO = 0.0; // 0 = only use hands for search/move. 1 = only use head for search/move. var HAND_HEAD_MIX_RATIO = 0.0; // 0 = only use hands for search/move. 1 = only use head for search/move.
var PICK_WITH_HAND_RAY = true; var PICK_WITH_HAND_RAY = true;
@ -161,11 +163,11 @@ var STATE_CONTINUE_NEAR_TRIGGER = 7;
var STATE_FAR_TRIGGER = 8; var STATE_FAR_TRIGGER = 8;
var STATE_CONTINUE_FAR_TRIGGER = 9; var STATE_CONTINUE_FAR_TRIGGER = 9;
var STATE_RELEASE = 10; var STATE_RELEASE = 10;
var STATE_EQUIP_SEARCHING = 11; // var STATE_EQUIP_SEARCHING = 11;
var STATE_EQUIP = 12 var STATE_EQUIP = 12
var STATE_CONTINUE_EQUIP_BD = 13; // equip while bumper is still held down // var STATE_CONTINUE_EQUIP_BD = 13; // equip while bumper is still held down
var STATE_CONTINUE_EQUIP = 14; var STATE_CONTINUE_EQUIP = 14;
var STATE_WAITING_FOR_BUMPER_RELEASE = 15; var STATE_WAITING_FOR_THUMB_RELEASE = 15;
// "collidesWith" is specified by comma-separated list of group names // "collidesWith" is specified by comma-separated list of group names
// the possible group names are: static, dynamic, kinematic, myAvatar, otherAvatar // the possible group names are: static, dynamic, kinematic, myAvatar, otherAvatar
@ -199,16 +201,16 @@ function stateToName(state) {
return "continue_far_trigger"; return "continue_far_trigger";
case STATE_RELEASE: case STATE_RELEASE:
return "release"; return "release";
case STATE_EQUIP_SEARCHING: // case STATE_EQUIP_SEARCHING:
return "equip_searching"; // return "equip_searching";
case STATE_EQUIP: case STATE_EQUIP:
return "equip"; return "equip";
case STATE_CONTINUE_EQUIP_BD: // case STATE_CONTINUE_EQUIP_BD:
return "continue_equip_bd"; // return "continue_equip_bd";
case STATE_CONTINUE_EQUIP: case STATE_CONTINUE_EQUIP:
return "continue_equip"; return "continue_equip";
case STATE_WAITING_FOR_BUMPER_RELEASE: case STATE_WAITING_FOR_THUMB_RELEASE:
return "waiting_for_bumper_release"; return "waiting_for_thumb_release";
} }
return "unknown"; return "unknown";
@ -262,6 +264,7 @@ function MyController(hand) {
this.triggerValue = 0; // rolling average of trigger value this.triggerValue = 0; // rolling average of trigger value
this.rawTriggerValue = 0; this.rawTriggerValue = 0;
this.rawBumperValue = 0; this.rawBumperValue = 0;
this.rawThumbValue = 0;
//for visualizations //for visualizations
this.overlayLine = null; this.overlayLine = null;
this.particleBeamObject = null; this.particleBeamObject = null;
@ -297,9 +300,9 @@ function MyController(hand) {
case STATE_SEARCHING: case STATE_SEARCHING:
this.search(); this.search();
break; break;
case STATE_EQUIP_SEARCHING: // case STATE_EQUIP_SEARCHING:
this.search(); // this.search();
break; // break;
case STATE_DISTANCE_HOLDING: case STATE_DISTANCE_HOLDING:
this.distanceHolding(); this.distanceHolding();
break; break;
@ -310,11 +313,11 @@ function MyController(hand) {
case STATE_EQUIP: case STATE_EQUIP:
this.nearGrabbing(); this.nearGrabbing();
break; break;
case STATE_WAITING_FOR_BUMPER_RELEASE: case STATE_WAITING_FOR_THUMB_RELEASE:
this.waitingForBumperRelease(); this.waitingForThumbRelease();
break; break;
case STATE_CONTINUE_NEAR_GRABBING: case STATE_CONTINUE_NEAR_GRABBING:
case STATE_CONTINUE_EQUIP_BD: // case STATE_CONTINUE_EQUIP_BD:
case STATE_CONTINUE_EQUIP: case STATE_CONTINUE_EQUIP:
this.continueNearGrabbing(); this.continueNearGrabbing();
break; break;
@ -784,16 +787,36 @@ function MyController(hand) {
return _this.rawBumperValue < BUMPER_ON_VALUE; return _this.rawBumperValue < BUMPER_ON_VALUE;
}; };
// this.triggerOrBumperSqueezed = function() {
// return triggerSmoothedSqueezed() || bumperSqueezed();
// }
// this.triggerAndBumperReleased = function() {
// return triggerSmoothedReleased() && bumperReleased();
// }
this.thumbPress = function(value) {
_this.rawThumbValue = value;
}
this.thumbPressed = function() {
return _this.rawThumbValue > THUMB_ON_VALUE;
};
this.thumbReleased = function() {
return _this.rawThumbValue < THUMB_ON_VALUE;
};
this.off = function() { this.off = function() {
if (this.triggerSmoothedSqueezed() || this.bumperSqueezed()) { if (this.triggerSmoothedSqueezed() || this.bumperSqueezed()) {
this.lastPickTime = 0; this.lastPickTime = 0;
var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand; var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
this.startingHandRotation = Controller.getPoseValue(controllerHandInput).rotation; this.startingHandRotation = Controller.getPoseValue(controllerHandInput).rotation;
if (this.triggerSmoothedSqueezed()) { if (this.triggerSmoothedSqueezed() || this.bumperSqueezed()) {
this.setState(STATE_SEARCHING); this.setState(STATE_SEARCHING);
} else { } // else {
this.setState(STATE_EQUIP_SEARCHING); // this.setState(STATE_EQUIP_SEARCHING);
} // }
} }
}; };
@ -804,7 +827,7 @@ function MyController(hand) {
this.checkForStrayChildren(); this.checkForStrayChildren();
if (this.state == STATE_SEARCHING ? this.triggerSmoothedReleased() : this.bumperReleased()) { if (this.state == STATE_SEARCHING && this.triggerSmoothedReleased() && this.bumperReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
return; return;
} }
@ -936,13 +959,13 @@ function MyController(hand) {
} }
continue; continue;
} }
if (propsForCandidate.parentID != NULL_UUID && this.state == STATE_EQUIP_SEARCHING) { // if (propsForCandidate.parentID != NULL_UUID && this.state == STATE_EQUIP_SEARCHING) {
// don't allow a double-equip // // don't allow a double-equip
if (WANT_DEBUG_SEARCH_NAME && propsForCandidate.name == WANT_DEBUG_SEARCH_NAME) { // if (WANT_DEBUG_SEARCH_NAME && propsForCandidate.name == WANT_DEBUG_SEARCH_NAME) {
print("grab is skipping '" + WANT_DEBUG_SEARCH_NAME + "': it's a child"); // print("grab is skipping '" + WANT_DEBUG_SEARCH_NAME + "': it's a child");
} // }
continue; // continue;
} // }
if (this.state == STATE_SEARCHING && if (this.state == STATE_SEARCHING &&
!isPhysical && distance > NEAR_PICK_MAX_DISTANCE && !near && !grabbableDataForCandidate.wantsTrigger) { !isPhysical && distance > NEAR_PICK_MAX_DISTANCE && !near && !grabbableDataForCandidate.wantsTrigger) {
@ -978,7 +1001,8 @@ function MyController(hand) {
return; return;
} }
// far grab or equip with action // far grab or equip with action
if ((isPhysical || this.state == STATE_EQUIP_SEARCHING) && !near) { // if ((isPhysical || this.state == STATE_EQUIP_SEARCHING) && !near) {
if (isPhysical && !near) {
if (entityIsGrabbedByOther(this.grabbedEntity)) { if (entityIsGrabbedByOther(this.grabbedEntity)) {
// don't distance grab something that is already grabbed. // don't distance grab something that is already grabbed.
if (WANT_DEBUG_SEARCH_NAME && props.name == WANT_DEBUG_SEARCH_NAME) { if (WANT_DEBUG_SEARCH_NAME && props.name == WANT_DEBUG_SEARCH_NAME) {
@ -999,7 +1023,8 @@ function MyController(hand) {
intersectionPointToCenterDistance * intersectionPointToCenterDistance *
FAR_TO_NEAR_GRAB_PADDING_FACTOR); FAR_TO_NEAR_GRAB_PADDING_FACTOR);
} }
this.setState(this.state == STATE_SEARCHING ? STATE_DISTANCE_HOLDING : STATE_EQUIP); // this.setState(this.state == STATE_SEARCHING ? STATE_DISTANCE_HOLDING : STATE_EQUIP);
this.setState(STATE_DISTANCE_HOLDING);
this.searchSphereOff(); this.searchSphereOff();
return; return;
} }
@ -1104,7 +1129,7 @@ function MyController(hand) {
}; };
this.continueDistanceHolding = function() { this.continueDistanceHolding = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased() && this.bumperReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("releaseGrab"); this.callEntityMethodOnGrabbed("releaseGrab");
return; return;
@ -1121,14 +1146,15 @@ function MyController(hand) {
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES);
if (this.state == STATE_CONTINUE_DISTANCE_HOLDING && this.bumperSqueezed() && // // switch from far grab to near equip
this.hasPresetOffsets()) { // if (this.state == STATE_CONTINUE_DISTANCE_HOLDING && this.bumperSqueezed() &&
var saveGrabbedID = this.grabbedEntity; // this.hasPresetOffsets()) {
this.release(); // var saveGrabbedID = this.grabbedEntity;
this.setState(STATE_EQUIP); // this.release();
this.grabbedEntity = saveGrabbedID; // this.setState(STATE_EQUIP);
return; // this.grabbedEntity = saveGrabbedID;
} // return;
// }
var now = Date.now(); var now = Date.now();
this.currentObjectTime = now; this.currentObjectTime = now;
@ -1307,7 +1333,7 @@ function MyController(hand) {
this.nearGrabbing = function() { this.nearGrabbing = function() {
var now = Date.now(); var now = Date.now();
if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased() && this.bumperReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("releaseGrab"); this.callEntityMethodOnGrabbed("releaseGrab");
return; return;
@ -1329,7 +1355,7 @@ function MyController(hand) {
var handPosition = this.getHandPosition(); var handPosition = this.getHandPosition();
var hasPresetPosition = false; var hasPresetPosition = false;
if (this.state != STATE_NEAR_GRABBING && this.hasPresetOffsets()) { if (this.state == STATE_EQUIP && this.hasPresetOffsets()) {
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
// if an object is "equipped" and has a predefined offset, use it. // if an object is "equipped" and has a predefined offset, use it.
this.ignoreIK = grabbableData.ignoreIK ? grabbableData.ignoreIK : false; this.ignoreIK = grabbableData.ignoreIK ? grabbableData.ignoreIK : false;
@ -1351,7 +1377,7 @@ function MyController(hand) {
} }
} }
var isPhysical = this.propsArePhysical(grabbedProperties) || entityHasActions(this.grabbedEntity); var isPhysical = this.propsArePhysical(grabbedProperties); // || entityHasActions(this.grabbedEntity);
if (isPhysical && this.state == STATE_NEAR_GRABBING) { if (isPhysical && this.state == STATE_NEAR_GRABBING) {
// grab entity via action // grab entity via action
if (!this.setupHoldAction()) { if (!this.setupHoldAction()) {
@ -1359,6 +1385,11 @@ function MyController(hand) {
} }
} else { } else {
// grab entity via parenting // grab entity via parenting
if (this.actionID) {
var saveGrabbedID = this.grabbedEntity;
this.release();
this.grabbedEntity = saveGrabbedID;
}
this.actionID = null; this.actionID = null;
var handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"); var handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "RightHand" : "LeftHand");
reparentProps = { reparentProps = {
@ -1378,13 +1409,15 @@ function MyController(hand) {
this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "startNearGrab" : "startEquip"); this.callEntityMethodOnGrabbed(this.state == STATE_NEAR_GRABBING ? "startNearGrab" : "startEquip");
if (this.state == STATE_NEAR_GRABBING) { // if (this.state == STATE_NEAR_GRABBING) {
// near grabbing // // near grabbing
this.setState(STATE_CONTINUE_NEAR_GRABBING); // this.setState(STATE_CONTINUE_NEAR_GRABBING);
} else { // } else {
// equipping // // equipping
this.setState(STATE_CONTINUE_EQUIP_BD); // this.setState(STATE_CONTINUE_EQUIP_BD);
} // }
this.setState(this.state == STATE_NEAR_GRABBING ? STATE_CONTINUE_NEAR_GRABBING : STATE_CONTINUE_EQUIP);
this.currentHandControllerTipPosition = this.currentHandControllerTipPosition =
(this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition; (this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition;
@ -1392,22 +1425,23 @@ function MyController(hand) {
}; };
this.continueNearGrabbing = function() { this.continueNearGrabbing = function() {
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased() && this.bumperReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("releaseGrab"); this.callEntityMethodOnGrabbed("releaseGrab");
return; return;
} }
if (this.state == STATE_CONTINUE_EQUIP_BD && this.bumperReleased()) { // if (this.state == STATE_CONTINUE_EQUIP_BD && this.thumbReleased()) {
this.setState(STATE_CONTINUE_EQUIP); // this.setState(STATE_EQUIP);
return; // return;
} // }
if (this.state == STATE_CONTINUE_EQUIP && this.bumperSqueezed()) { if (this.state == STATE_CONTINUE_EQUIP && this.thumbPressed()) {
this.setState(STATE_WAITING_FOR_BUMPER_RELEASE); // this.setState(STATE_WAITING_FOR_THUMB_RELEASE);
this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("releaseEquip"); this.callEntityMethodOnGrabbed("releaseEquip");
return; return;
} }
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.thumbPressed()) {
this.setState(STATE_CONTINUE_EQUIP_BD); this.setState(STATE_WAITING_FOR_THUMB_RELEASE);
this.callEntityMethodOnGrabbed("releaseGrab"); this.callEntityMethodOnGrabbed("releaseGrab");
this.callEntityMethodOnGrabbed("startEquip"); this.callEntityMethodOnGrabbed("startEquip");
return; return;
@ -1479,14 +1513,14 @@ function MyController(hand) {
} }
}; };
this.waitingForBumperRelease = function() { this.waitingForThumbRelease = function() {
if (this.bumperReleased()) { if (this.thumbReleased() && this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_EQUIP);
} }
}; };
this.nearTrigger = function() { this.nearTrigger = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased() && this.bumperReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopNearTrigger"); this.callEntityMethodOnGrabbed("stopNearTrigger");
return; return;
@ -1496,7 +1530,7 @@ function MyController(hand) {
}; };
this.farTrigger = function() { this.farTrigger = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased() && this.bumperReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopFarTrigger"); this.callEntityMethodOnGrabbed("stopFarTrigger");
return; return;
@ -1506,7 +1540,7 @@ function MyController(hand) {
}; };
this.continueNearTrigger = function() { this.continueNearTrigger = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased() && this.bumperReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopNearTrigger"); this.callEntityMethodOnGrabbed("stopNearTrigger");
return; return;
@ -1515,7 +1549,7 @@ function MyController(hand) {
}; };
this.continueFarTrigger = function() { this.continueFarTrigger = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased() && this.bumperReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
this.callEntityMethodOnGrabbed("stopFarTrigger"); this.callEntityMethodOnGrabbed("stopFarTrigger");
return; return;
@ -1794,8 +1828,9 @@ function MyController(hand) {
this.checkNewlyLoaded = function(loadedEntityID) { this.checkNewlyLoaded = function(loadedEntityID) {
if (this.state == STATE_OFF || if (this.state == STATE_OFF ||
this.state == STATE_SEARCHING || this.state == STATE_SEARCHING // ||
this.state == STATE_EQUIP_SEARCHING) { // this.state == STATE_EQUIP_SEARCHING
) {
var loadedProps = Entities.getEntityProperties(loadedEntityID); var loadedProps = Entities.getEntityProperties(loadedEntityID);
if (loadedProps.parentID != MyAvatar.sessionUUID) { if (loadedProps.parentID != MyAvatar.sessionUUID) {
return; return;
@ -1827,6 +1862,9 @@ mapping.from([Controller.Standard.LT]).peek().to(leftController.triggerPress);
mapping.from([Controller.Standard.RB]).peek().to(rightController.bumperPress); mapping.from([Controller.Standard.RB]).peek().to(rightController.bumperPress);
mapping.from([Controller.Standard.LB]).peek().to(leftController.bumperPress); mapping.from([Controller.Standard.LB]).peek().to(leftController.bumperPress);
mapping.from([Controller.Standard.LeftPrimaryThumb]).peek().to(leftController.thumbPress);
mapping.from([Controller.Standard.RightPrimaryThumb]).peek().to(rightController.thumbPress);
Controller.enableMapping(MAPPING_NAME); Controller.enableMapping(MAPPING_NAME);
//the section below allows the grab script to listen for messages that disable either one or both hands. useful for two handed items //the section below allows the grab script to listen for messages that disable either one or both hands. useful for two handed items