mirror of
https://github.com/overte-org/overte.git
synced 2025-07-24 01:23:55 +02:00
Merge pull request #6020 from ericrius1/grabFarNonColliding
Added grab far events for non physical objects
This commit is contained in:
commit
9f0721c08b
1 changed files with 80 additions and 25 deletions
|
@ -77,7 +77,9 @@ var STATE_NEAR_GRABBING = 4;
|
||||||
var STATE_CONTINUE_NEAR_GRABBING = 5;
|
var STATE_CONTINUE_NEAR_GRABBING = 5;
|
||||||
var STATE_NEAR_GRABBING_NON_COLLIDING = 6;
|
var STATE_NEAR_GRABBING_NON_COLLIDING = 6;
|
||||||
var STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING = 7;
|
var STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING = 7;
|
||||||
var STATE_RELEASE = 8;
|
var STATE_FAR_GRABBING_NON_COLLIDING = 8;
|
||||||
|
var STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING = 9;
|
||||||
|
var STATE_RELEASE = 10;
|
||||||
|
|
||||||
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js
|
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js
|
||||||
var GRAB_USER_DATA_KEY = "grabKey"; // shared with grab.js
|
var GRAB_USER_DATA_KEY = "grabKey"; // shared with grab.js
|
||||||
|
@ -161,6 +163,12 @@ function MyController(hand, triggerAction) {
|
||||||
case STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING:
|
case STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING:
|
||||||
this.continueNearGrabbingNonColliding();
|
this.continueNearGrabbingNonColliding();
|
||||||
break;
|
break;
|
||||||
|
case STATE_FAR_GRABBING_NON_COLLIDING:
|
||||||
|
this.farGrabbingNonColliding();
|
||||||
|
break;
|
||||||
|
case STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING:
|
||||||
|
this.continueFarGrabbingNonColliding();
|
||||||
|
break;
|
||||||
case STATE_RELEASE:
|
case STATE_RELEASE:
|
||||||
this.release();
|
this.release();
|
||||||
break;
|
break;
|
||||||
|
@ -251,9 +259,7 @@ function MyController(hand, triggerAction) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var intersection = Entities.findRayIntersection(pickRay, true);
|
var intersection = Entities.findRayIntersection(pickRay, true);
|
||||||
if (intersection.intersects &&
|
if (intersection.intersects && intersection.properties.locked === 0) {
|
||||||
intersection.properties.collisionsWillMove === 1 &&
|
|
||||||
intersection.properties.locked === 0) {
|
|
||||||
// the ray is intersecting something we can move.
|
// the ray is intersecting something we can move.
|
||||||
var handControllerPosition = Controller.getSpatialControlPosition(this.palm);
|
var handControllerPosition = Controller.getSpatialControlPosition(this.palm);
|
||||||
var intersectionDistance = Vec3.distance(handControllerPosition, intersection.intersection);
|
var intersectionDistance = Vec3.distance(handControllerPosition, intersection.intersection);
|
||||||
|
@ -266,14 +272,22 @@ function MyController(hand, triggerAction) {
|
||||||
}
|
}
|
||||||
if (intersectionDistance < NEAR_PICK_MAX_DISTANCE) {
|
if (intersectionDistance < NEAR_PICK_MAX_DISTANCE) {
|
||||||
// the hand is very close to the intersected object. go into close-grabbing mode.
|
// the hand is very close to the intersected object. go into close-grabbing mode.
|
||||||
|
if (intersection.properties.collisionsWillMove === 1) {
|
||||||
this.setState(STATE_NEAR_GRABBING);
|
this.setState(STATE_NEAR_GRABBING);
|
||||||
|
} else {
|
||||||
|
this.setState(STATE_NEAR_GRABBING_NON_COLLIDING);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// don't allow two people to distance grab the same object
|
// don't allow two people to distance grab the same object
|
||||||
if (entityIsGrabbedByOther(intersection.entityID)) {
|
if (entityIsGrabbedByOther(intersection.entityID)) {
|
||||||
this.grabbedEntity = null;
|
this.grabbedEntity = null;
|
||||||
} else {
|
} else {
|
||||||
// the hand is far from the intersected object. go into distance-holding mode
|
// the hand is far from the intersected object. go into distance-holding mode
|
||||||
|
if (intersection.properties.collisionsWillMove === 1) {
|
||||||
this.setState(STATE_DISTANCE_HOLDING);
|
this.setState(STATE_DISTANCE_HOLDING);
|
||||||
|
} else {
|
||||||
|
this.setState(STATE_FAR_GRABBING_NON_COLLIDING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -504,7 +518,9 @@ function MyController(hand, triggerAction) {
|
||||||
this.currentObjectTime = now;
|
this.currentObjectTime = now;
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab");
|
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab");
|
||||||
|
|
||||||
Entities.updateAction(this.grabbedEntity, this.actionID, {lifetime: ACTION_LIFETIME});
|
Entities.updateAction(this.grabbedEntity, this.actionID, {
|
||||||
|
lifetime: ACTION_LIFETIME
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.nearGrabbingNonColliding = function() {
|
this.nearGrabbingNonColliding = function() {
|
||||||
|
@ -521,14 +537,46 @@ function MyController(hand, triggerAction) {
|
||||||
this.setState(STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING);
|
this.setState(STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.farGrabbingNonColliding = function() {
|
||||||
|
if (this.triggerSmoothedReleased()) {
|
||||||
|
this.setState(STATE_RELEASE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hand === RIGHT_HAND) {
|
||||||
|
Entities.callEntityMethod(this.grabbedEntity, "setRightHand");
|
||||||
|
} else {
|
||||||
|
Entities.callEntityMethod(this.grabbedEntity, "setLeftHand");
|
||||||
|
}
|
||||||
|
Entities.callEntityMethod(this.grabbedEntity, "startFarGrabNonColliding");
|
||||||
|
this.setState(STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING);
|
||||||
|
};
|
||||||
|
|
||||||
this.continueNearGrabbingNonColliding = function() {
|
this.continueNearGrabbingNonColliding = function() {
|
||||||
if (this.triggerSmoothedReleased()) {
|
if (this.triggerSmoothedReleased()) {
|
||||||
this.setState(STATE_RELEASE);
|
this.setState(STATE_RELEASE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrabbingNonColliding");
|
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrabbingNonColliding");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.continueFarGrabbingNonColliding = function() {
|
||||||
|
if (this.triggerSmoothedReleased()) {
|
||||||
|
this.setState(STATE_RELEASE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var handPosition = this.getHandPosition();
|
||||||
|
var pickRay = {
|
||||||
|
origin: handPosition,
|
||||||
|
direction: Quat.getUp(this.getHandRotation())
|
||||||
|
};
|
||||||
|
|
||||||
|
this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
|
||||||
|
Entities.callEntityMethod(this.grabbedEntity, "continueFarGrabbingNonColliding");
|
||||||
|
};
|
||||||
|
|
||||||
_this.allTouchedIDs = {};
|
_this.allTouchedIDs = {};
|
||||||
this.touchTest = function() {
|
this.touchTest = function() {
|
||||||
var maxDistance = 0.05;
|
var maxDistance = 0.05;
|
||||||
|
@ -650,7 +698,14 @@ function MyController(hand, triggerAction) {
|
||||||
if (data["refCount"] == 1) {
|
if (data["refCount"] == 1) {
|
||||||
data["gravity"] = grabbedProperties.gravity;
|
data["gravity"] = grabbedProperties.gravity;
|
||||||
data["ignoreForCollisions"] = grabbedProperties.ignoreForCollisions;
|
data["ignoreForCollisions"] = grabbedProperties.ignoreForCollisions;
|
||||||
Entities.editEntity(entityID, {gravity: {x:0, y:0, z:0}, ignoreForCollisions: true});
|
Entities.editEntity(entityID, {
|
||||||
|
gravity: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
},
|
||||||
|
ignoreForCollisions: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
setEntityCustomData(GRAB_USER_DATA_KEY, entityID, data);
|
setEntityCustomData(GRAB_USER_DATA_KEY, entityID, data);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue