From b779c33a1b98b0e440a5892348200fd3b94c82ca Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 13 Nov 2017 16:42:16 -0800 Subject: [PATCH] fixed lockEndUUID offset for scripts --- .../controllerModules/farActionGrabEntity.js | 29 ++++++++++++++----- .../libraries/controllerDispatcherUtils.js | 5 ++-- scripts/system/libraries/pointersUtils.js | 8 +++-- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farActionGrabEntity.js b/scripts/system/controllers/controllerModules/farActionGrabEntity.js index e4dccfe2e1..8d5c3a7446 100644 --- a/scripts/system/controllers/controllerModules/farActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farActionGrabEntity.js @@ -14,7 +14,7 @@ PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, ZERO_VEC, ensureDynamic, getControllerWorldLocation, projectOntoEntityXYPlane, ContextOverlay, HMD, Reticle, Overlays, isPointingAtUI - Picks, makeLaserLockInfo + Picks, makeLaserLockInfo Xform */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); @@ -495,10 +495,10 @@ Script.include("/~/system/libraries/Xform.js"); this.distanceRotate(otherFarGrabModule); } } - return this.exitIfDisabled(); + return this.exitIfDisabled(controllerData); }; - this.exitIfDisabled = function() { + this.exitIfDisabled = function(controllerData) { var moduleName = this.hand === RIGHT_HAND ? "RightDisableModules" : "LeftDisableModules"; var disableModule = getEnabledModuleByName(moduleName); if (disableModule) { @@ -507,13 +507,28 @@ Script.include("/~/system/libraries/Xform.js"); return makeRunningValues(false, [], []); } } - var grabbedThing = (this.distanceHolding || this.distanceRotating) ? this.grabbedThingID : null; - var grabbedIsOverlay = (this.distanceHolding || this.distanceRotating) ? this.grabbedIsOverlay : false; - var laserLockInfo = makeLaserLockInfo(grabbedThing, grabbedIsOverlay, this.hand); + var grabbedThing = (this.distanceHolding || this.distanceRotating) ? this.targetObject.entityID : null; + var offset = this.calculateOffset(controllerData); + var laserLockInfo = makeLaserLockInfo(grabbedThing, false, this.hand, offset); return makeRunningValues(true, [], [], laserLockInfo); }; - this.cleanup = function () { + this.calculateOffset = function(controllerData) { + if (this.distanceHolding || this.distanceRotating) { + var targetProps = Entities.getEntityProperties(this.targetObject.entityID, [ + "position", + "rotation" + ]); + var zeroVector = { x: 0, y: 0, z:0, w: 0 }; + var intersection = controllerData.rayPicks[this.hand].intersection; + var intersectionMat = new Xform(zeroVector, intersection); + var modelMat = new Xform(targetProps.rotation, targetProps.position); + var modelMatInv = modelMat.inv(); + var xformMat = Xform.mul(modelMatInv, intersectionMat); + var offsetMat = Mat4.createFromRotAndTrans(xformMat.rot, xformMat.pos); + return offsetMat; + } + return undefined; }; } diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index 16091314b6..fd0db91fec 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -125,11 +125,12 @@ makeDispatcherModuleParameters = function (priority, activitySlots, requiredData }; }; -makeLaserLockInfo = function(targetID, isOverlay, hand) { +makeLaserLockInfo = function(targetID, isOverlay, hand, offset) { return { targetID: targetID, isOverlay: isOverlay, - hand: hand + hand: hand, + offset: offset }; }; diff --git a/scripts/system/libraries/pointersUtils.js b/scripts/system/libraries/pointersUtils.js index 63bef21637..f48c332c35 100644 --- a/scripts/system/libraries/pointersUtils.js +++ b/scripts/system/libraries/pointersUtils.js @@ -130,10 +130,14 @@ Pointer = function(hudLayer, pickType, pointerData) { this.lockEnd = function(lockData) { if (lockData !== undefined) { - if (this.visible) { + if (this.visible && !this.locked && lockData.targetID !== null) { var targetID = lockData.targetID; var targetIsOverlay = lockData.isOverlay; - Pointers.setLockEndUUID(this.pointerID, targetID, targetIsOverlay); + if (lockData.offset === undefined) { + Pointers.setLockEndUUID(this.pointerID, targetID, targetIsOverlay); + } else { + Pointers.setLockEndUUID(this.pointerID, targetID, targetIsOverlay, lockData.offset); + } this.locked = targetID; } } else if (this.locked) {