somewhat better distance from bounding box

This commit is contained in:
Dante Ruiz 2018-07-27 17:49:49 -07:00
parent 30b4815bf9
commit 6320401308
2 changed files with 43 additions and 3 deletions

View file

@ -23,6 +23,20 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
// XXX this.ignoreIK = (grabbableData.ignoreIK !== undefined) ? grabbableData.ignoreIK : true; // XXX this.ignoreIK = (grabbableData.ignoreIK !== undefined) ? grabbableData.ignoreIK : true;
// XXX this.kinematicGrab = (grabbableData.kinematic !== undefined) ? grabbableData.kinematic : NEAR_GRABBING_KINEMATIC; // XXX this.kinematicGrab = (grabbableData.kinematic !== undefined) ? grabbableData.kinematic : NEAR_GRABBING_KINEMATIC;
var GRAB_POINT_SPHERE_OFFSET = { x: 0.01, y: -0.13, z: 0.039 };
function getGrabPointSphereOffset(handController) {
var offset = GRAB_POINT_SPHERE_OFFSET;
if (handController === Controller.Standard.LeftHand) {
offset = {
x: -GRAB_POINT_SPHERE_OFFSET.x,
y: GRAB_POINT_SPHERE_OFFSET.y,
z: GRAB_POINT_SPHERE_OFFSET.z
};
}
return Vec3.multiply(MyAvatar.sensorToWorldScale, offset);
}
function NearParentingGrabEntity(hand) { function NearParentingGrabEntity(hand) {
this.hand = hand; this.hand = hand;
this.targetEntityID = null; this.targetEntityID = null;
@ -174,7 +188,9 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
this.lastUnequipCheckTime = now; this.lastUnequipCheckTime = now;
if (props.parentID === MyAvatar.SELF_ID) { if (props.parentID === MyAvatar.SELF_ID) {
var tearAwayDistance = TEAR_AWAY_DISTANCE * MyAvatar.sensorToWorldScale; var tearAwayDistance = TEAR_AWAY_DISTANCE * MyAvatar.sensorToWorldScale;
var distance = distanceBetweenPointAndEntityBoundingBox(props); var controllerIndex = (this.hand === LEFT_HAND ? Controller.Standard.LeftHand : Controller.Standard.RightHand);
var controllerGrabOffset = getGrabPointSphereOffset(controllerIndex);
var distance = distanceBetweenEntityLocalPositionAndBoundingBox(props, controllerGrabOffset);
if (distance > tearAwayDistance) { if (distance > tearAwayDistance) {
this.autoUnequipCounter++; this.autoUnequipCounter++;
} else { } else {

View file

@ -58,7 +58,7 @@
entityIsFarGrabbedByOther:true, entityIsFarGrabbedByOther:true,
highlightTargetEntity:true, highlightTargetEntity:true,
clearHighlightedEntities:true, clearHighlightedEntities:true,
unhighlightTargetEntity:true unhighlightTargetEntity:true,
distanceBetweenEntityLocalPositionAndBoundingBox: true distanceBetweenEntityLocalPositionAndBoundingBox: true
*/ */
@ -95,7 +95,7 @@ COLORS_GRAB_DISTANCE_HOLD = { red: 238, green: 75, blue: 214 };
NEAR_GRAB_RADIUS = 1.0; NEAR_GRAB_RADIUS = 1.0;
TEAR_AWAY_DISTANCE = 0.1; // ungrab an entity if its bounding-box moves this far from the hand TEAR_AWAY_DISTANCE = 0.2; // ungrab an entity if its bounding-box moves this far from the hand
TEAR_AWAY_COUNT = 2; // multiply by TEAR_AWAY_CHECK_TIME to know how long the item must be away TEAR_AWAY_COUNT = 2; // multiply by TEAR_AWAY_CHECK_TIME to know how long the item must be away
TEAR_AWAY_CHECK_TIME = 0.15; // seconds, duration between checks TEAR_AWAY_CHECK_TIME = 0.15; // seconds, duration between checks
DISPATCHER_HOVERING_LIST = "dispactherHoveringList"; DISPATCHER_HOVERING_LIST = "dispactherHoveringList";
@ -416,6 +416,30 @@ findHandChildEntities = function(hand) {
}); });
}; };
distanceBetweenEntityLocalPositionAndBoundingBox = function(entityProps, jointGrabOffset) {
var DEFAULT_REGISTRATION_POINT = { x: 0.5, y: 0.5, z: 0.5 };
var rotInv = Quat.inverse(entityProps.localRotation);
var localPosition = Vec3.sum(entityProps.localPosition, jointGrabOffset);
var localPoint = Vec3.multiplyQbyV(rotInv, Vec3.multiply(localPosition, -1.0));
var halfDims = Vec3.multiply(entityProps.dimensions, 0.5);
var regRatio = Vec3.subtract(DEFAULT_REGISTRATION_POINT, entityProps.registrationPoint);
var entityCenter = Vec3.multiplyVbyV(regRatio, entityProps.dimensions);
var localMin = Vec3.subtract(entityCenter, halfDims);
var localMax = Vec3.sum(entityCenter, halfDims);
if ((localMin.x < localPoint.x) && (localMin.y < localPoint.y) && (localMin.z < localPoint.z)) {
if ((localMax.x > localPoint.x) && (localMax.y > localPoint.y) && (localMax.z > localPoint.z)) {
return 0;
}
}
var distanceToLocalMax = Vec3.distance(localMax, localPoint);
var distanceToLocalMin = Vec3.distance(localMin, localPoint);
return Math.min(distanceToLocalMax, distanceToLocalMin);
};
distanceBetweenPointAndEntityBoundingBox = function(point, entityProps) { distanceBetweenPointAndEntityBoundingBox = function(point, entityProps) {
var entityXform = new Xform(entityProps.rotation, entityProps.position); var entityXform = new Xform(entityProps.rotation, entityProps.position);
var localPoint = entityXform.inv().xformPoint(point); var localPoint = entityXform.inv().xformPoint(point);