From 53ef9fa5a86d80bf63a37c463051d67c7e6bc53f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 2 Aug 2016 16:05:46 -0700 Subject: [PATCH 1/4] test commit --- scripts/system/controllers/handControllerPointer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/system/controllers/handControllerPointer.js b/scripts/system/controllers/handControllerPointer.js index dab6438efa..0b1fde61af 100644 --- a/scripts/system/controllers/handControllerPointer.js +++ b/scripts/system/controllers/handControllerPointer.js @@ -69,6 +69,8 @@ function Trigger(label) { that.triggerSmoothedClick = function () { return that.triggerClicked; }; + + that.triggerSmoothedSqueezed = function () { return that.triggerValue > that.TRIGGER_ON_VALUE; }; From c1e044364f03a56e71233a26aec00dbf702f5d6f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 22 Nov 2016 10:24:02 -0800 Subject: [PATCH 2/4] Added distance attentuation of linear and angular rate --- scripts/system/controllers/grab.js | 35 +++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/grab.js b/scripts/system/controllers/grab.js index 05303aa0a7..25ce499aa7 100644 --- a/scripts/system/controllers/grab.js +++ b/scripts/system/controllers/grab.js @@ -8,6 +8,8 @@ // // Grab's physically moveable entities with the mouse, by applying a spring force. // +// Updated November 22, 2016 by Philip Rosedale: Add distance attenuation of grab effect +// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // @@ -48,6 +50,23 @@ var enabled = true; function getTag() { return "grab-" + MyAvatar.sessionUUID; } + +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 +var DISTANCE_HOLDING_UNITY_DISTANCE = 6; // The distance at which the distance holding action timeframe is unmodified + +function distanceGrabTimescale(mass, distance) { + var timeScale = DISTANCE_HOLDING_ACTION_TIMEFRAME * mass / + DISTANCE_HOLDING_UNITY_MASS * distance / + DISTANCE_HOLDING_UNITY_DISTANCE; + if (timeScale < DISTANCE_HOLDING_ACTION_TIMEFRAME) { + timeScale = DISTANCE_HOLDING_ACTION_TIMEFRAME; + } + return timeScale; +} +function getMass(dimensions, density) { + return (dimensions.x * dimensions.y * dimensions.z) * density; +} function entityIsGrabbedByOther(entityID) { // by convention, a distance grab sets the tag of its action to be grab-*owner-session-id*. @@ -445,6 +464,8 @@ Grabber.prototype.moveEvent = function(event) { this.originalGravity = entityProperties.gravity; } this.currentPosition = entityProperties.position; + this.mass = getMass(entityProperties.dimensions, entityProperties.density); + var cameraPosition = Camera.getPosition(); var actionArgs = { tag: getTag(), @@ -465,15 +486,19 @@ Grabber.prototype.moveEvent = function(event) { //var qZero = this.lastRotation; this.lastRotation = Quat.multiply(deltaQ, this.lastRotation); + var distanceToCamera = Vec3.length(Vec3.subtract(this.currentPosition, cameraPosition)); + var angularTimeScale = distanceGrabTimescale(this.mass, distanceToCamera); + actionArgs = { targetRotation: this.lastRotation, - angularTimeScale: 0.1, + angularTimeScale: angularTimeScale, tag: getTag(), ttl: ACTION_TTL }; } else { var newPointOnPlane; + if (this.mode === "verticalCylinder") { // for this mode we recompute the plane based on current Camera var planeNormal = Quat.getFront(Camera.getOrientation()); @@ -487,8 +512,9 @@ Grabber.prototype.moveEvent = function(event) { y: this.pointOnPlane.y, z: this.pointOnPlane.z }; + } else { - var cameraPosition = Camera.getPosition(); + newPointOnPlane = mouseIntersectionWithPlane( this.pointOnPlane, this.planeNormal, mouse.current, this.maxDistance); var relativePosition = Vec3.subtract(newPointOnPlane, cameraPosition); @@ -501,9 +527,12 @@ Grabber.prototype.moveEvent = function(event) { } this.targetPosition = Vec3.subtract(newPointOnPlane, this.offset); + var distanceToCamera = Vec3.length(Vec3.subtract(this.targetPosition, cameraPosition)); + var linearTimeScale = distanceGrabTimescale(this.mass, distanceToCamera); + actionArgs = { targetPosition: this.targetPosition, - linearTimeScale: 0.1, + linearTimeScale: linearTimeScale, tag: getTag(), ttl: ACTION_TTL }; From 664b54c004d4ca02d26346ba89573034c010e6bd Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 22 Nov 2016 10:27:27 -0800 Subject: [PATCH 3/4] remove whitespace --- scripts/system/controllers/handControllerPointer.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/system/controllers/handControllerPointer.js b/scripts/system/controllers/handControllerPointer.js index 06da2b1ac8..ce9b8e403f 100644 --- a/scripts/system/controllers/handControllerPointer.js +++ b/scripts/system/controllers/handControllerPointer.js @@ -70,8 +70,6 @@ function Trigger(label) { that.triggerSmoothedClick = function () { return that.triggerClicked; }; - - that.triggerSmoothedSqueezed = function () { return that.triggerValue > that.TRIGGER_ON_VALUE; }; From c60b0c7ef540d7b1320a38f3f7cd5fb65c5622b1 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 1 Dec 2016 12:54:38 -0800 Subject: [PATCH 4/4] Fix indents --- scripts/system/controllers/grab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/grab.js b/scripts/system/controllers/grab.js index 25ce499aa7..3ce44c2672 100644 --- a/scripts/system/controllers/grab.js +++ b/scripts/system/controllers/grab.js @@ -57,8 +57,8 @@ var DISTANCE_HOLDING_UNITY_DISTANCE = 6; // The distance at which the distance function distanceGrabTimescale(mass, distance) { var timeScale = DISTANCE_HOLDING_ACTION_TIMEFRAME * mass / - DISTANCE_HOLDING_UNITY_MASS * distance / - DISTANCE_HOLDING_UNITY_DISTANCE; + DISTANCE_HOLDING_UNITY_MASS * distance / + DISTANCE_HOLDING_UNITY_DISTANCE; if (timeScale < DISTANCE_HOLDING_ACTION_TIMEFRAME) { timeScale = DISTANCE_HOLDING_ACTION_TIMEFRAME; }