From c6a3496b2573057381da004ea030114ffe92ecf9 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Sun, 24 Feb 2019 12:36:44 -0800 Subject: [PATCH] Add utility functions for adjusting target rotation and position. --- .../controllerModules/farGrabEntity.js | 64 ++++++++++++++++++- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 9c78c576d5..92fc4a45f1 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -146,7 +146,7 @@ Script.include("/~/system/libraries/controllers.js"); var newTargetPosLocal = MyAvatar.worldToJointPoint(targetProps.position); MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); - MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); + MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); // RKNOTE: This is where the rotation should be updated. var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; Entities.callEntityMethod(targetProps.id, "startDistanceGrab", args); @@ -235,7 +235,7 @@ Script.include("/~/system/libraries/controllers.js"); // var newTargetPosLocal = Mat4.transformPoint(MyAvatar.getSensorToWorldMatrix(), newTargetPosition); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); - MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); + MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); // RKNOTE: This is where the rotation should be updated. this.previousRoomControllerPosition = roomControllerPosition; }; @@ -259,7 +259,7 @@ Script.include("/~/system/libraries/controllers.js"); this.grabbing = false; this.targetEntityID = null; this.potentialEntityWithContextOverlay = false; - MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); + MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); // RKNOTE: Here, we should edit the entity's position and rotation data with the current joint rotation data. }; this.updateRecommendedArea = function () { @@ -395,6 +395,64 @@ Script.include("/~/system/libraries/controllers.js"); return (_this.getOffHandTrigger() <= TRIGGER_OFF_VALUE) ? true : false; }; + this.getTargetPosition = function () { + if (this.targetIsNull()) { + return null; + } else { + var props = Entities.getEntityProperties(this.targetEntityID, ["position"]); + return props.position; + } + }; + + this.getTargetRotation = function () { + if (this.targetIsNull()) { + return null; + } else { + var props = Entities.getEntityProperties(this.targetEntityID, ["rotation"]); + return props.rotation; + } + }; + + this.getTargetLocalPosition = function () { + if (this.targetIsNull()) { + return null; + } else { + var props = Entities.getEntityProperties(this.targetEntityID, ["localPosition"]); + return props.localPosition; + } + }; + + this.getTargetLocalRotation = function () { + if (this.targetIsNull()) { + return null; + } else { + var props = Entities.getEntityProperties(this.targetEntityID, ["localRotation"]); + return props.localRotation; + } + }; + + this.setTargetPosition = function (newPos) { + if (this.targetIsNull()) { + print("Fargrab Error: No target to edit position."); + return; + } else { + var props; + props.position = newPos; + Entities.editEntity(this.targetEntityID, props); + } + }; + + this.setTargetRotation = function (newRot) { + if (this.targetIsNull()) { + print("Fargrab Error: No target to edit rotation."); + return; + } else { + var props; + props.rotation = newRot; + Entitis.editEntity(this.targetEntityID, props); + } + } + this.isReady = function (controllerData) { if (HMD.active && this.hand === this.getOffHand()) { if (this.notPointingAtEntity(controllerData)) {