From 7bc3435cfa5d17ae37531e2265860bdbde7ee328 Mon Sep 17 00:00:00 2001 From: volansystech Date: Thu, 13 Apr 2017 02:51:30 +0530 Subject: [PATCH 1/4] Initial Commit.. If distanceToObject from avatar is more than 15, we are accelarting entity travel by 2x. This will help user to grab the entity in lesser time. --- .../system/controllers/handControllerGrab.js | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 9a6760a37b..307c7fba16 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -75,7 +75,8 @@ var WEB_TOUCH_Y_OFFSET = 0.05; // how far forward (or back with a negative numbe // // distant manipulation // - +var shouldTravelAtRapidPace = false; +var accelarationStartingPoint = 0; var DISTANCE_HOLDING_RADIUS_FACTOR = 3.5; // multiplied by distance between hand and object var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position var DISTANCE_HOLDING_UNITY_MASS = 1200; // The mass at which the distance holding action timeframe is unmodified @@ -2524,7 +2525,19 @@ function MyController(hand) { // compute the mass for the purpose of energy and how quickly to move object this.mass = this.getMass(grabbedProperties.dimensions, grabbedProperties.density); + this.shouldTravelAtRapidPace = false; var distanceToObject = Vec3.length(Vec3.subtract(MyAvatar.position, grabbedProperties.position)); + + if(distanceToObject >= 15){ // Apply Rapid Pace only if distanceToObject is far than 15. + this.shouldTravelAtRapidPace = true; + var MyAvatarHipsPosition = MyAvatar.getJointPosition("Hips"); + var distanceToHandFromAvatarHips = worldControllerPosition.x - MyAvatarHipsPosition.x; + var ACCELERATION_START_THRESHOLD = 0.90; + this.accelarationStartingPoint = (distanceToHandFromAvatarHips * ACCELERATION_START_THRESHOLD); + }else{ + this.shouldTravelAtRapidPace = false; + } + var timeScale = this.distanceGrabTimescale(this.mass, distanceToObject); this.actionID = NULL_UUID; @@ -2619,16 +2632,22 @@ function MyController(hand) { this.grabRadius * RADIAL_GRAB_AMPLIFIER); } + if(this.shouldTravelAtRapidPace = true){ + var MyAvatarHipsPosition = MyAvatar.getJointPosition("Hips"); + var distanceToHandFromAvatarHips_x = worldControllerPosition.x - MyAvatarHipsPosition.x; + if(distanceToHandFromAvatarHips_x <= this.accelarationStartingPoint){ + var RAPID_PACE_RATE = 2; + this.grabRadius = (this.grabRadius / RAPID_PACE_RATE); + } + } // don't let grabRadius go all the way to zero, because it can't come back from that var MINIMUM_GRAB_RADIUS = 0.1; if (this.grabRadius < MINIMUM_GRAB_RADIUS) { this.grabRadius = MINIMUM_GRAB_RADIUS; } - var newTargetPosition = Vec3.multiply(this.grabRadius, Quat.getUp(worldControllerRotation)); newTargetPosition = Vec3.sum(newTargetPosition, worldControllerPosition); newTargetPosition = Vec3.sum(newTargetPosition, this.offsetPosition); - var objectToAvatar = Vec3.subtract(this.currentObjectPosition, MyAvatar.position); var handControllerData = getEntityCustomData('handControllerKey', this.grabbedThingID, defaultMoveWithHeadData); if (handControllerData.disableMoveWithHead !== true) { From 7e0efed062ad1e95ddc784496161cab37f632de9 Mon Sep 17 00:00:00 2001 From: volansystech Date: Tue, 18 Apr 2017 00:54:01 +0530 Subject: [PATCH 2/4] Improve speed of grabbing. --- .../system/controllers/handControllerGrab.js | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 307c7fba16..d49579ce3f 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -75,7 +75,6 @@ var WEB_TOUCH_Y_OFFSET = 0.05; // how far forward (or back with a negative numbe // // distant manipulation // -var shouldTravelAtRapidPace = false; var accelarationStartingPoint = 0; var DISTANCE_HOLDING_RADIUS_FACTOR = 3.5; // multiplied by distance between hand and object var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position @@ -2525,19 +2524,13 @@ function MyController(hand) { // compute the mass for the purpose of energy and how quickly to move object this.mass = this.getMass(grabbedProperties.dimensions, grabbedProperties.density); - this.shouldTravelAtRapidPace = false; var distanceToObject = Vec3.length(Vec3.subtract(MyAvatar.position, grabbedProperties.position)); - if(distanceToObject >= 15){ // Apply Rapid Pace only if distanceToObject is far than 15. - this.shouldTravelAtRapidPace = true; - var MyAvatarHipsPosition = MyAvatar.getJointPosition("Hips"); - var distanceToHandFromAvatarHips = worldControllerPosition.x - MyAvatarHipsPosition.x; - var ACCELERATION_START_THRESHOLD = 0.90; - this.accelarationStartingPoint = (distanceToHandFromAvatarHips * ACCELERATION_START_THRESHOLD); - }else{ - this.shouldTravelAtRapidPace = false; - } - + + var MyAvatarHipsPosition = MyAvatar.getJointPosition("Hips"); + var distanceToHandFromAvatarHips = Vec3.length(Vec3.subtract(worldControllerPosition, MyAvatarHipsPosition)); + var ACCELERATION_START_THRESHOLD = 0.95; + this.accelarationStartingPoint = (distanceToHandFromAvatarHips * ACCELERATION_START_THRESHOLD); var timeScale = this.distanceGrabTimescale(this.mass, distanceToObject); this.actionID = NULL_UUID; @@ -2589,7 +2582,6 @@ function MyController(hand) { var roomControllerPosition = Mat4.transformPoint(worldToSensorMat, worldControllerPosition); var grabbedProperties = Entities.getEntityProperties(this.grabbedThingID, GRABBABLE_PROPERTIES); - var now = Date.now(); var deltaObjectTime = (now - this.currentObjectTime) / MSECS_PER_SEC; // convert to seconds this.currentObjectTime = now; @@ -2632,16 +2624,14 @@ function MyController(hand) { this.grabRadius * RADIAL_GRAB_AMPLIFIER); } - if(this.shouldTravelAtRapidPace = true){ - var MyAvatarHipsPosition = MyAvatar.getJointPosition("Hips"); - var distanceToHandFromAvatarHips_x = worldControllerPosition.x - MyAvatarHipsPosition.x; - if(distanceToHandFromAvatarHips_x <= this.accelarationStartingPoint){ - var RAPID_PACE_RATE = 2; - this.grabRadius = (this.grabRadius / RAPID_PACE_RATE); - } - } // don't let grabRadius go all the way to zero, because it can't come back from that - var MINIMUM_GRAB_RADIUS = 0.1; + var MINIMUM_GRAB_RADIUS = 0.3; + var MyAvatarHipsPosition = MyAvatar.getJointPosition("Hips"); + var distanceToHandFromAvatarHips = Vec3.length(Vec3.subtract(worldControllerPosition, MyAvatarHipsPosition)); + if(distanceToHandFromAvatarHips <= this.accelarationStartingPoint && this.grabRadius >= MINIMUM_GRAB_RADIUS){ + var RAPID_PACE_RATE = 2; + this.grabRadius = (this.grabRadius / RAPID_PACE_RATE); + } if (this.grabRadius < MINIMUM_GRAB_RADIUS) { this.grabRadius = MINIMUM_GRAB_RADIUS; } From e5c7587ad8b36f16f108098a5cadd2ae5eec04d4 Mon Sep 17 00:00:00 2001 From: volansystech Date: Tue, 18 Apr 2017 20:01:02 +0530 Subject: [PATCH 3/4] Improve far grabbing based on timescale. --- .../system/controllers/handControllerGrab.js | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index d49579ce3f..aa61081da9 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -75,7 +75,7 @@ var WEB_TOUCH_Y_OFFSET = 0.05; // how far forward (or back with a negative numbe // // distant manipulation // -var accelarationStartingPoint = 0; +var linearTimeScale = 0; var DISTANCE_HOLDING_RADIUS_FACTOR = 3.5; // multiplied by distance between hand and object var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position var DISTANCE_HOLDING_UNITY_MASS = 1200; // The mass at which the distance holding action timeframe is unmodified @@ -2525,14 +2525,8 @@ function MyController(hand) { // compute the mass for the purpose of energy and how quickly to move object this.mass = this.getMass(grabbedProperties.dimensions, grabbedProperties.density); var distanceToObject = Vec3.length(Vec3.subtract(MyAvatar.position, grabbedProperties.position)); - - - var MyAvatarHipsPosition = MyAvatar.getJointPosition("Hips"); - var distanceToHandFromAvatarHips = Vec3.length(Vec3.subtract(worldControllerPosition, MyAvatarHipsPosition)); - var ACCELERATION_START_THRESHOLD = 0.95; - this.accelarationStartingPoint = (distanceToHandFromAvatarHips * ACCELERATION_START_THRESHOLD); var timeScale = this.distanceGrabTimescale(this.mass, distanceToObject); - + this.linearTimeScale = timeScale; this.actionID = NULL_UUID; this.actionID = Entities.addAction("spring", this.grabbedThingID, { targetPosition: this.currentObjectPosition, @@ -2625,13 +2619,7 @@ function MyController(hand) { } // don't let grabRadius go all the way to zero, because it can't come back from that - var MINIMUM_GRAB_RADIUS = 0.3; - var MyAvatarHipsPosition = MyAvatar.getJointPosition("Hips"); - var distanceToHandFromAvatarHips = Vec3.length(Vec3.subtract(worldControllerPosition, MyAvatarHipsPosition)); - if(distanceToHandFromAvatarHips <= this.accelarationStartingPoint && this.grabRadius >= MINIMUM_GRAB_RADIUS){ - var RAPID_PACE_RATE = 2; - this.grabRadius = (this.grabRadius / RAPID_PACE_RATE); - } + var MINIMUM_GRAB_RADIUS = 0.1; if (this.grabRadius < MINIMUM_GRAB_RADIUS) { this.grabRadius = MINIMUM_GRAB_RADIUS; } @@ -2670,9 +2658,13 @@ function MyController(hand) { this.grabbedThingID); var distanceToObject = Vec3.length(Vec3.subtract(MyAvatar.position, this.currentObjectPosition)); + this.linearTimeScale = (this.linearTimeScale / 2); + if(this.linearTimeScale <= DISTANCE_HOLDING_ACTION_TIMEFRAME){ + this.linearTimeScale = DISTANCE_HOLDING_ACTION_TIMEFRAME; + } var success = Entities.updateAction(this.grabbedThingID, this.actionID, { targetPosition: newTargetPosition, - linearTimeScale: this.distanceGrabTimescale(this.mass, distanceToObject), + linearTimeScale: this.linearTimeScale, targetRotation: this.currentObjectRotation, angularTimeScale: this.distanceGrabTimescale(this.mass, distanceToObject), ttl: ACTION_TTL From b194ddeb66d4552270e3894710cfc9166fbae2a4 Mon Sep 17 00:00:00 2001 From: volansystech Date: Wed, 19 Apr 2017 16:39:23 +0530 Subject: [PATCH 4/4] Resolve Comments of @sethalves --- scripts/system/controllers/handControllerGrab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index aa61081da9..5af1f5d5c3 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -2659,7 +2659,7 @@ function MyController(hand) { var distanceToObject = Vec3.length(Vec3.subtract(MyAvatar.position, this.currentObjectPosition)); this.linearTimeScale = (this.linearTimeScale / 2); - if(this.linearTimeScale <= DISTANCE_HOLDING_ACTION_TIMEFRAME){ + if (this.linearTimeScale <= DISTANCE_HOLDING_ACTION_TIMEFRAME) { this.linearTimeScale = DISTANCE_HOLDING_ACTION_TIMEFRAME; } var success = Entities.updateAction(this.grabbedThingID, this.actionID, {