mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:09:24 +02:00
Merge pull request #13700 from danteruiz/fix-grabbing-problem
Impove the way we checkForChildTooFarAway in nearParentGrabEntity.js
This commit is contained in:
commit
8e277758ad
2 changed files with 33 additions and 11 deletions
|
@ -12,17 +12,32 @@
|
||||||
findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic, HAPTIC_PULSE_STRENGTH,
|
findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic, HAPTIC_PULSE_STRENGTH,
|
||||||
HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE, findHandChildEntities, TEAR_AWAY_DISTANCE, MSECS_PER_SEC, TEAR_AWAY_CHECK_TIME,
|
HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE, findHandChildEntities, TEAR_AWAY_DISTANCE, MSECS_PER_SEC, TEAR_AWAY_CHECK_TIME,
|
||||||
TEAR_AWAY_COUNT, distanceBetweenPointAndEntityBoundingBox, print, Uuid, highlightTargetEntity, unhighlightTargetEntity,
|
TEAR_AWAY_COUNT, distanceBetweenPointAndEntityBoundingBox, print, Uuid, highlightTargetEntity, unhighlightTargetEntity,
|
||||||
distanceBetweenEntityLocalPositionAndBoundingBox
|
distanceBetweenEntityLocalPositionAndBoundingBox, GRAB_POINT_SPHERE_OFFSET
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||||
Script.include("/~/system/libraries/cloneEntityUtils.js");
|
Script.include("/~/system/libraries/cloneEntityUtils.js");
|
||||||
|
Script.include("/~/system/libraries/controllers.js");
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
|
function getGrabOffset(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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
offset.y = -GRAB_POINT_SPHERE_OFFSET.y;
|
||||||
|
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 +189,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 = distanceBetweenEntityLocalPositionAndBoundingBox(props);
|
var controllerIndex = (this.hand === LEFT_HAND ? Controller.Standard.LeftHand : Controller.Standard.RightHand);
|
||||||
|
var controllerGrabOffset = getGrabOffset(controllerIndex);
|
||||||
|
var distance = distanceBetweenEntityLocalPositionAndBoundingBox(props, controllerGrabOffset);
|
||||||
if (distance > tearAwayDistance) {
|
if (distance > tearAwayDistance) {
|
||||||
this.autoUnequipCounter++;
|
this.autoUnequipCounter++;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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.15; // 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,13 +416,18 @@ findHandChildEntities = function(hand) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
distanceBetweenEntityLocalPositionAndBoundingBox = function(entityProps) {
|
distanceBetweenEntityLocalPositionAndBoundingBox = function(entityProps, jointGrabOffset) {
|
||||||
var localPoint = entityProps.localPosition;
|
var DEFAULT_REGISTRATION_POINT = { x: 0.5, y: 0.5, z: 0.5 };
|
||||||
var entityXform = new Xform(entityProps.rotation, entityProps.position);
|
var rotInv = Quat.inverse(entityProps.localRotation);
|
||||||
var minOffset = Vec3.multiplyVbyV(entityProps.registrationPoint, entityProps.dimensions);
|
var localPosition = Vec3.sum(entityProps.localPosition, jointGrabOffset);
|
||||||
var maxOffset = Vec3.multiplyVbyV(Vec3.subtract(ONE_VEC, entityProps.registrationPoint), entityProps.dimensions);
|
var localPoint = Vec3.multiplyQbyV(rotInv, Vec3.multiply(localPosition, -1.0));
|
||||||
var localMin = Vec3.subtract(entityXform.trans, minOffset);
|
|
||||||
var localMax = Vec3.sum(entityXform.trans, maxOffset);
|
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);
|
||||||
|
|
||||||
|
|
||||||
var v = {x: localPoint.x, y: localPoint.y, z: localPoint.z};
|
var v = {x: localPoint.x, y: localPoint.y, z: localPoint.z};
|
||||||
v.x = Math.max(v.x, localMin.x);
|
v.x = Math.max(v.x, localMin.x);
|
||||||
|
|
Loading…
Reference in a new issue