From 3b05317db67af35cffc6e46ca205a8fddea92fa0 Mon Sep 17 00:00:00 2001 From: druiz17 Date: Thu, 28 Sep 2017 11:18:40 -0700 Subject: [PATCH] fixing grabbing and tablet bugs --- .../controllerModules/equipEntity.js | 16 +++++++++++++--- .../controllerModules/farActionGrabEntity.js | 4 ++-- .../controllerModules/tabletStylusInput.js | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/scripts/system/controllers/controllerModules/equipEntity.js b/scripts/system/controllers/controllerModules/equipEntity.js index 29db02c6de..4978f225ce 100644 --- a/scripts/system/controllers/controllerModules/equipEntity.js +++ b/scripts/system/controllers/controllerModules/equipEntity.js @@ -255,6 +255,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa this.messageGrabEntity = false; this.grabEntityProps = null; this.shouldSendStart = false; + this.equipedWithSecondary = false; this.parameters = makeDispatcherModuleParameters( 300, @@ -370,6 +371,10 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa return this.rawSecondaryValue < BUMPER_ON_VALUE; }; + this.secondarySmoothedSqueezed = function() { + return this.rawSecondaryValue > BUMPER_ON_VALUE; + }; + this.chooseNearEquipHotspots = function(candidateEntityProps, controllerData) { var _this = this; var collectedHotspots = flatten(candidateEntityProps.map(function(props) { @@ -592,11 +597,13 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa // if the potentialHotspot os not cloneable and locked return null if (potentialEquipHotspot && - ((this.triggerSmoothedSqueezed() && !this.waitForTriggerRelease) || this.messageGrabEntity)) { + (((this.triggerSmoothedSqueezed() || this.secondarySmoothedSqueezed()) && !this.waitForTriggerRelease) || + this.messageGrabEntity)) { this.grabbedHotspot = potentialEquipHotspot; this.targetEntityID = this.grabbedHotspot.entityID; this.startEquipEntity(controllerData); this.messageGrabEnity = false; + this.equipedWithSecondary = this.secondarySmoothedSqueezed(); return makeRunningValues(true, [potentialEquipHotspot.entityID], []); } else { return makeRunningValues(false, [], []); @@ -627,7 +634,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa return this.checkNearbyHotspots(controllerData, deltaTime, timestamp); } - if (controllerData.secondaryValues[this.hand]) { + if (controllerData.secondaryValues[this.hand] && !this.equipedWithSecondary) { // this.secondaryReleased() will always be true when not depressed // so we cannot simply rely on that for release - ensure that the // trigger was first "prepared" by being pushed in before the release @@ -644,7 +651,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa var dropDetected = this.dropGestureProcess(deltaTime); - if (this.triggerSmoothedReleased()) { + if (this.triggerSmoothedReleased() || this.secondaryReleased()) { if (this.shouldSendStart) { // we don't want to send startEquip message until the trigger is released. otherwise, // guns etc will fire right as they are equipped. @@ -653,6 +660,9 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa this.shouldSendStart = false; } this.waitForTriggerRelease = false; + if (this.secondaryReleased() && this.equipedWithSecondary) { + this.equipedWithSecondary = false; + } } if (dropDetected && this.prevDropDetected !== dropDetected) { diff --git a/scripts/system/controllers/controllerModules/farActionGrabEntity.js b/scripts/system/controllers/controllerModules/farActionGrabEntity.js index 5c31c859e9..c5b82f75f0 100644 --- a/scripts/system/controllers/controllerModules/farActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farActionGrabEntity.js @@ -132,7 +132,7 @@ Script.include("/~/system/libraries/controllers.js"); this.updateLaserPointer = function(controllerData) { var SEARCH_SPHERE_SIZE = 0.011; var MIN_SPHERE_SIZE = 0.0005; - var radius = Math.max(1.2 * SEARCH_SPHERE_SIZE * this.intersectionDistance, MIN_SPHERE_SIZE); + var radius = Math.max(1.2 * SEARCH_SPHERE_SIZE * this.intersectionDistance, MIN_SPHERE_SIZE) * MyAvatar.sensorToWorldScale; var dim = {x: radius, y: radius, z: radius}; var mode = "hold"; if (!this.distanceHolding && !this.distanceRotating) { @@ -424,7 +424,7 @@ Script.include("/~/system/libraries/controllers.js"); this.laserPointerOff(); return makeRunningValues(false, [], []); } - + this.intersectionDistance = controllerData.rayPicks[this.hand].distance; this.updateLaserPointer(controllerData); var otherModuleName =this.hand === RIGHT_HAND ? "LeftFarActionGrabEntity" : "RightFarActionGrabEntity"; diff --git a/scripts/system/controllers/controllerModules/tabletStylusInput.js b/scripts/system/controllers/controllerModules/tabletStylusInput.js index def958b223..0a3b2b8adc 100644 --- a/scripts/system/controllers/controllerModules/tabletStylusInput.js +++ b/scripts/system/controllers/controllerModules/tabletStylusInput.js @@ -152,6 +152,20 @@ Script.include("/~/system/libraries/controllers.js"); } }; + this.updateStylus = function() { + if (this.stylus) { + var X_ROT_NEG_90 = { x: -0.70710678, y: 0, z: 0, w: 0.70710678 }; + var modelOrientation = Quat.multiply(this.stylusTip.orientation, X_ROT_NEG_90); + var modelPositionOffset = Vec3.multiplyQbyV(modelOrientation, { x: 0, y: 0, z: MyAvatar.sensorToWorldScale * -WEB_STYLUS_LENGTH / 2 }); + + var stylusProps = { + position: Vec3.sum(this.stylusTip.position, modelPositionOffset), + rotation: modelOrientation + }; + Overlays.editOverlay(this.stylus, stylusProps); + } + }; + this.showStylus = function() { if (this.stylus) { return; @@ -320,6 +334,7 @@ Script.include("/~/system/libraries/controllers.js"); if (this.isNearStylusTarget) { if (!this.useFingerInsteadOfStylus) { this.showStylus(); + this.updateStylus(); } else { this.pointFinger(true); } @@ -335,7 +350,7 @@ Script.include("/~/system/libraries/controllers.js"); var SCALED_TABLET_MAX_HOVER_DISTANCE = TABLET_MAX_HOVER_DISTANCE * sensorScaleFactor; if (nearestStylusTarget && nearestStylusTarget.distance > SCALED_TABLET_MIN_TOUCH_DISTANCE && - nearestStylusTarget.distance < SCALED_TABLET_MAX_HOVER_DISTANCE) { + nearestStylusTarget.distance < SCALED_TABLET_MAX_HOVER_DISTANCE && !this.getOtherHandController().stylusTouchingTarget) { this.requestTouchFocus(nearestStylusTarget);