From b634292261a49d26d17bee5360a2e5b03c955be5 Mon Sep 17 00:00:00 2001 From: druiz17 Date: Tue, 12 Sep 2017 10:53:04 -0700 Subject: [PATCH] fixing some small issues --- .../controllerModules/farActionGrabEntity.js | 2 +- .../controllerModules/nearActionGrabEntity.js | 12 ++++++++++-- .../controllerModules/nearParentGrabEntity.js | 13 +++++++++++-- .../controllerModules/overlayLaserInput.js | 2 +- .../controllers/controllerModules/scaleAvatar.js | 4 ++-- .../system/libraries/controllerDispatcherUtils.js | 5 +++++ 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farActionGrabEntity.js b/scripts/system/controllers/controllerModules/farActionGrabEntity.js index 9a6f39c490..80718bc68d 100644 --- a/scripts/system/controllers/controllerModules/farActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farActionGrabEntity.js @@ -137,7 +137,7 @@ Script.include("/~/system/libraries/controllers.js"); var dim = {x: radius, y: radius, z: radius}; var mode = "hold"; if (!this.distanceHolding && !this.distanceRotating) { - if (controllerData.triggerValues[this.hand] === 1) { + if (controllerData.triggerClicks[this.hand]) { mode = "full"; } else { mode = "half"; diff --git a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js index 98a3b9395d..ee44fb4907 100644 --- a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js @@ -9,7 +9,8 @@ getControllerJointIndex, getGrabbableData, NULL_UUID, enableDispatcherModule, disableDispatcherModule, propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, entityIsGrabbable, Quat, Vec3, MSECS_PER_SEC, getControllerWorldLocation, makeDispatcherModuleParameters, makeRunningValues, - TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS, findGroupParent, entityIsCloneable, propsAreCloneDynamic, cloneEntity + TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS, findGroupParent, entityIsCloneable, propsAreCloneDynamic, cloneEntity, + HAPTIC_PULSE_STRENGTH, HAPTIC_STYLUS_DURATION */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); @@ -22,6 +23,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.hand = hand; this.targetEntityID = null; this.actionID = null; // action this script created... + this.hapticTargetID = null; this.parameters = makeDispatcherModuleParameters( 500, @@ -152,6 +154,10 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); break; } if (entityIsGrabbable(props) || entityIsCloneable(props)) { + if (props.id !== this.hapticTargetID) { + Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); + this.hapticTargetID = props.id; + } // if we've attempted to grab a child, roll up to the root of the tree var groupRootProps = findGroupParent(controllerData, props); if (entityIsGrabbable(groupRootProps)) { @@ -166,11 +172,11 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.isReady = function (controllerData) { this.targetEntityID = null; + var targetProps = this.getTargetProps(controllerData); if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE && controllerData.secondaryValues[this.hand] < TRIGGER_OFF_VALUE) { return makeRunningValues(false, [], []); } - var targetProps = this.getTargetProps(controllerData); if (targetProps) { if (!propsArePhysical(targetProps) && !propsAreCloneDynamic(targetProps)) { return makeRunningValues(false, [], []); // let nearParentGrabEntity handle it @@ -179,6 +185,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); return makeRunningValues(true, [this.targetEntityID], []); } } else { + this.hapticTargetID = null; return makeRunningValues(false, [], []); } }; @@ -187,6 +194,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); if (this.actionID) { if (controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0) { this.endNearGrabAction(); + this.hapticTargetID = null; return makeRunningValues(false, [], []); } diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index 47f80932bb..30cce1b315 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -10,7 +10,7 @@ getControllerJointIndex, NULL_UUID, enableDispatcherModule, disableDispatcherModule, propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS, - findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic + findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic, HAPTIC_PULSE_STRENGTH, HAPTIC_STYLUS_DURATION */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); @@ -28,6 +28,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.previousParentID = {}; this.previousParentJointIndex = {}; this.previouslyUnhooked = {}; + this.hapticTargetID = null; this.parameters = makeDispatcherModuleParameters( 500, @@ -154,6 +155,11 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); continue; } if (entityIsGrabbable(props)) { + // give haptic feedback + if (props.id !== this.hapticTargetID) { + Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); + this.hapticTargetID = props.id; + } // if we've attempted to grab a child, roll up to the root of the tree var groupRootProps = findGroupParent(controllerData, props); if (entityIsGrabbable(groupRootProps)) { @@ -169,11 +175,11 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.targetEntityID = null; this.grabbing = false; + var targetProps = this.getTargetProps(controllerData); if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE && controllerData.secondaryValues[this.hand] < TRIGGER_OFF_VALUE) { return makeRunningValues(false, [], []); } - var targetProps = this.getTargetProps(controllerData); if (targetProps) { if (propsArePhysical(targetProps) || propsAreCloneDynamic(targetProps)) { return makeRunningValues(false, [], []); // let nearActionGrabEntity handle it @@ -182,6 +188,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); return makeRunningValues(true, [this.targetEntityID], []); } } else { + this.hapticTargetID = null; return makeRunningValues(false, [], []); } }; @@ -190,6 +197,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); if (this.grabbing) { if (controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0) { this.endNearParentingGrabEntity(); + this.hapticTargetID = null; return makeRunningValues(false, [], []); } @@ -197,6 +205,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); if (!this.thisHandIsParent(props)) { this.grabbing = false; this.targetEntityID = null; + this.hapticTargetID = null; return makeRunningValues(false, [], []); } diff --git a/scripts/system/controllers/controllerModules/overlayLaserInput.js b/scripts/system/controllers/controllerModules/overlayLaserInput.js index b1ffc77afe..2c950fd4df 100644 --- a/scripts/system/controllers/controllerModules/overlayLaserInput.js +++ b/scripts/system/controllers/controllerModules/overlayLaserInput.js @@ -433,7 +433,7 @@ Script.include("/~/system/libraries/controllers.js"); var nearGrabModule = getEnabledModuleByName(nearGrabName); var status = nearGrabModule ? nearGrabModule.isReady(controllerData) : makeRunningValues(false, [], []); var offOverlay = (intersection.type !== RayPick.INTERSECTED_OVERLAY); - var triggerOff = (controllerData.triggerValues[this.hand] === 0); + var triggerOff = (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE); return offOverlay || status.active || triggerOff; }; diff --git a/scripts/system/controllers/controllerModules/scaleAvatar.js b/scripts/system/controllers/controllerModules/scaleAvatar.js index 2c85b75ea9..04c400f2bc 100644 --- a/scripts/system/controllers/controllerModules/scaleAvatar.js +++ b/scripts/system/controllers/controllerModules/scaleAvatar.js @@ -15,7 +15,7 @@ //Script.include("/~/system/libraries/controllerDispatcherUtils.js"); (function () { var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js"); - + var BUMPER_ON_VALUE = 0.5; function ScaleAvatar(hand) { this.hand = hand; this.scalingStartAvatarScale = 0; @@ -38,7 +38,7 @@ }; this.triggersPressed = function(controllerData) { - if (controllerData.triggerValues[this.hand] === 1 && controllerData.secondaryValues[this.hand] === 1) { + if (controllerData.triggerClicks[this.hand] && controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE) { return true; } return false; diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index bc2aa1a9c8..dcdbed6fb2 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -19,6 +19,8 @@ COLORS_GRAB_DISTANCE_HOLD:true, NEAR_GRAB_RADIUS:true, DISPATCHER_PROPERTIES:true, + HAPTIC_PULSE_STRENGTH:true, + HAPTIC_PULSE_DURATION:true, Entities, makeDispatcherModuleParameters:true, makeRunningValues:true, @@ -42,6 +44,9 @@ MSECS_PER_SEC = 1000.0; INCHES_TO_METERS = 1.0 / 39.3701; +HAPTIC_PULSE_STRENGTH = 1.0; +HAPTIC_PULSE_DURATION = 13.0; + ZERO_VEC = { x: 0, y: 0, z: 0 }; ONE_VEC = { x: 1, y: 1, z: 1 };