From 0f42943bfbeb72088f6569e2e42e3315fe2fff7c Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 29 Aug 2016 11:55:04 -0700 Subject: [PATCH] Marketplace tablet is a bit larger and lower DPI. Bug fix for grabbing/equipping large objects, they no longer will drop immediately if your grab point is too far away from the grabbed entity position. --- .../system/controllers/handControllerGrab.js | 42 +++++++++++++++---- scripts/system/libraries/WebTablet.js | 9 ++-- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 32e0b047de..1f90918a69 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -21,7 +21,7 @@ Script.include("/~/system/libraries/Xform.js"); // add lines where the hand ray picking is happening // var WANT_DEBUG = false; -var WANT_DEBUG_STATE = false; +var WANT_DEBUG_STATE = true; var WANT_DEBUG_SEARCH_NAME = null; // @@ -125,6 +125,12 @@ var ZERO_VEC = { z: 0 }; +var ONE_VEC = { + x: 1, + y: 1, + z: 1 +}; + var NULL_UUID = "{00000000-0000-0000-0000-000000000000}"; // these control how long an abandoned pointer line or action will hang around @@ -232,6 +238,25 @@ CONTROLLER_STATE_MACHINE[STATE_ENTITY_TOUCHING] = { updateMethod: "entityTouching" }; +function distanceBetweenPointAndEntityBoundingBox(point, entityProps) { + var entityXform = new Xform(entityProps.rotation, entityProps.position); + var localPoint = entityXform.inv().xformPoint(point); + var minOffset = Vec3.multiplyVbyV(entityProps.registrationPoint, entityProps.dimensions); + var maxOffset = Vec3.multiplyVbyV(Vec3.subtract(ONE_VEC, entityProps.registrationPoint), entityProps.dimensions); + var localMin = Vec3.subtract(entityXform.trans, minOffset); + var localMax = Vec3.sum(entityXform.trans, maxOffset); + + var v = {x: localPoint.x, y: localPoint.y, z: localPoint.z}; + v.x = Math.max(v.x, localMin.x); + v.x = Math.min(v.x, localMax.x); + v.y = Math.max(v.y, localMin.y); + v.y = Math.min(v.y, localMax.y); + v.z = Math.max(v.z, localMin.z); + v.z = Math.min(v.z, localMax.z); + + return Vec3.distance(v, localPoint); +} + function angleBetween(a, b) { return Math.acos(Vec3.dot(Vec3.normalize(a), Vec3.normalize(b))); } @@ -1961,7 +1986,8 @@ function MyController(hand) { this.heartBeat(this.grabbedEntity); var props = Entities.getEntityProperties(this.grabbedEntity, ["localPosition", "parentID", - "position", "rotation", "dimensions"]); + "position", "rotation", "dimensions", + "registrationPoint"]); if (!props.position) { // server may have reset, taking our equipped entity with it. move back to "off" stte this.callEntityMethodOnGrabbed("releaseGrab"); @@ -1975,14 +2001,12 @@ function MyController(hand) { if (props.parentID == MyAvatar.sessionUUID) { var handPosition = this.getHandPosition(); - // the center of the equipped object being far from the hand isn't enough to auto-unequip -- we also - // need to fail the findEntities test. - var TEAR_AWAY_DISTANCE = 0.04; - var nearPickedCandidateEntities = Entities.findEntities(handPosition, NEAR_GRAB_RADIUS + TEAR_AWAY_DISTANCE); - if (nearPickedCandidateEntities.indexOf(this.grabbedEntity) == -1) { - // for whatever reason, the held/equipped entity has been pulled away. ungrab or unequip. + + var TEAR_AWAY_DISTANCE = 0.1; + var dist = distanceBetweenPointAndEntityBoundingBox(handPosition, props); + if (dist > TEAR_AWAY_DISTANCE) { print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." + - props.parentID + " " + vec3toStr(props.position)); + props.parentID + ", dist = " + dist); if (this.state == STATE_NEAR_GRABBING) { this.callEntityMethodOnGrabbed("releaseGrab"); diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 34368e475b..adbcd78381 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -11,6 +11,8 @@ var RAD_TO_DEG = 180 / Math.PI; var X_AXIS = {x: 1, y: 0, z: 0}; var Y_AXIS = {x: 0, y: 1, z: 0}; +var DEFAULT_DPI = 30; +var DEFAULT_WIDTH = 0.5; var TABLET_URL = "https://s3.amazonaws.com/hifi-public/tony/tablet.fbx"; @@ -37,12 +39,13 @@ function calcSpawnInfo() { } // ctor -WebTablet = function (url) { +WebTablet = function (url, width, dpi) { var ASPECT = 4.0 / 3.0; - var WIDTH = 0.4; + var WIDTH = width || DEFAULT_WIDTH; var HEIGHT = WIDTH * ASPECT; var DEPTH = 0.025; + var DPI = dpi || DEFAULT_DPI; var spawnInfo = calcSpawnInfo(); @@ -78,7 +81,7 @@ WebTablet = function (url) { position: webEntityPosition, rotation: webEntityRotation, shapeType: "box", - dpi: 45, + dpi: DPI, parentID: this.tabletEntityID, parentJointIndex: -1 });