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.
This commit is contained in:
Anthony J. Thibault 2016-08-29 11:55:04 -07:00
parent 9801ff075a
commit 0f42943bfb
2 changed files with 39 additions and 12 deletions

View file

@ -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");

View file

@ -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
});