fix what happens when a distance grab is blocked because someone else already has it

This commit is contained in:
Seth Alves 2015-10-02 12:25:34 -07:00
parent 880d92ee64
commit c0e8b02a2f

View file

@ -167,6 +167,12 @@ function MyController(hand, triggerAction) {
} }
}; };
this.setState = function(newState) {
// print("STATE: " + this.state + " --> " + newState);
this.state = newState;
}
this.lineOn = function(closePoint, farPoint, color) { this.lineOn = function(closePoint, farPoint, color) {
// draw a line // draw a line
if (this.pointer === null) { if (this.pointer === null) {
@ -220,14 +226,14 @@ function MyController(hand, triggerAction) {
this.off = function() { this.off = function() {
if (this.triggerSmoothedSqueezed()) { if (this.triggerSmoothedSqueezed()) {
this.state = STATE_SEARCHING; this.setState(STATE_SEARCHING);
return; return;
} }
} }
this.search = function() { this.search = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.state = STATE_RELEASE; this.setState(STATE_RELEASE);
return; return;
} }
@ -238,6 +244,8 @@ function MyController(hand, triggerAction) {
direction: Quat.getUp(this.getHandRotation()) direction: Quat.getUp(this.getHandRotation())
}; };
this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
var defaultGrabbableData = { var defaultGrabbableData = {
grabbable: true grabbable: true
}; };
@ -253,21 +261,20 @@ function MyController(hand, triggerAction) {
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, defaultGrabbableData); var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, defaultGrabbableData);
if (grabbableData.grabbable === false) { if (grabbableData.grabbable === false) {
this.grabbedEntity = null;
return; return;
} }
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.
this.state = STATE_NEAR_GRABBING; this.setState(STATE_NEAR_GRABBING);
} else { } else {
// don't allow two people to distance grab the same object
if (entityIsGrabbedByOther(intersection.entityID)) { if (entityIsGrabbedByOther(intersection.entityID)) {
// don't allow two people to distance grab the same object this.grabbedEntity = null;
this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); } else {
return; // the hand is far from the intersected object. go into distance-holding mode
this.setState(STATE_DISTANCE_HOLDING);
} }
// the hand is far from the intersected object. go into distance-holding mode
this.state = STATE_DISTANCE_HOLDING;
this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
} }
} else { } else {
// forward ray test failed, try sphere test. // forward ray test failed, try sphere test.
@ -291,15 +298,14 @@ function MyController(hand, triggerAction) {
} }
} }
if (this.grabbedEntity === null) { if (this.grabbedEntity === null) {
this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); // this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
} else if (props.locked === 0 && props.collisionsWillMove === 1) { } else if (props.locked === 0 && props.collisionsWillMove === 1) {
this.state = STATE_NEAR_GRABBING; this.setState(STATE_NEAR_GRABBING);
} else if (props.collisionsWillMove === 0) { } else if (props.collisionsWillMove === 0) {
// We have grabbed a non-physical object, so we want to trigger a non-colliding event as opposed to a grab event // We have grabbed a non-physical object, so we want to trigger a non-colliding event as opposed to a grab event
this.state = STATE_NEAR_GRABBING_NON_COLLIDING; this.setState(STATE_NEAR_GRABBING_NON_COLLIDING);
} }
} }
}; };
this.distanceHolding = function() { this.distanceHolding = function() {
@ -329,7 +335,7 @@ function MyController(hand, triggerAction) {
} }
if (this.actionID !== null) { if (this.actionID !== null) {
this.state = STATE_CONTINUE_DISTANCE_HOLDING; this.setState(STATE_CONTINUE_DISTANCE_HOLDING);
this.activateEntity(this.grabbedEntity); this.activateEntity(this.grabbedEntity);
if (this.hand === RIGHT_HAND) { if (this.hand === RIGHT_HAND) {
Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); Entities.callEntityMethod(this.grabbedEntity, "setRightHand");
@ -346,7 +352,7 @@ function MyController(hand, triggerAction) {
this.continueDistanceHolding = function() { this.continueDistanceHolding = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.state = STATE_RELEASE; this.setState(STATE_RELEASE);
return; return;
} }
@ -404,7 +410,7 @@ function MyController(hand, triggerAction) {
var now = Date.now(); var now = Date.now();
var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds
this.computeReleaseVelocity(deltaPosition, deltaTime, false); this.computeReleaseVelocity(deltaPosition, deltaTime, false);
this.currentObjectPosition = newObjectPosition; this.currentObjectPosition = newObjectPosition;
this.currentObjectTime = now; this.currentObjectTime = now;
@ -427,7 +433,7 @@ function MyController(hand, triggerAction) {
this.nearGrabbing = function() { this.nearGrabbing = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.state = STATE_RELEASE; this.setState(STATE_RELEASE);
return; return;
} }
@ -458,7 +464,7 @@ function MyController(hand, triggerAction) {
if (this.actionID === NULL_ACTION_ID) { if (this.actionID === NULL_ACTION_ID) {
this.actionID = null; this.actionID = null;
} else { } else {
this.state = STATE_CONTINUE_NEAR_GRABBING; this.setState(STATE_CONTINUE_NEAR_GRABBING);
if (this.hand === RIGHT_HAND) { if (this.hand === RIGHT_HAND) {
Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); Entities.callEntityMethod(this.grabbedEntity, "setRightHand");
} else { } else {
@ -475,7 +481,7 @@ function MyController(hand, triggerAction) {
this.continueNearGrabbing = function() { this.continueNearGrabbing = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.state = STATE_RELEASE; this.setState(STATE_RELEASE);
return; return;
} }
@ -502,7 +508,7 @@ function MyController(hand, triggerAction) {
this.nearGrabbingNonColliding = function() { this.nearGrabbingNonColliding = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.state = STATE_RELEASE; this.setState(STATE_RELEASE);
return; return;
} }
if (this.hand === RIGHT_HAND) { if (this.hand === RIGHT_HAND) {
@ -511,12 +517,12 @@ function MyController(hand, triggerAction) {
Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); Entities.callEntityMethod(this.grabbedEntity, "setLeftHand");
} }
Entities.callEntityMethod(this.grabbedEntity, "startNearGrabNonColliding"); Entities.callEntityMethod(this.grabbedEntity, "startNearGrabNonColliding");
this.state = STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING; this.setState(STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING);
}; };
this.continueNearGrabbingNonColliding = function() { this.continueNearGrabbingNonColliding = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.state = STATE_RELEASE; this.setState(STATE_RELEASE);
return; return;
} }
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrabbingNonColliding"); Entities.callEntityMethod(this.grabbedEntity, "continueNearGrabbingNonColliding");
@ -627,7 +633,7 @@ function MyController(hand, triggerAction) {
this.grabbedVelocity = ZERO_VEC; this.grabbedVelocity = ZERO_VEC;
this.grabbedEntity = null; this.grabbedEntity = null;
this.actionID = null; this.actionID = null;
this.state = STATE_OFF; this.setState(STATE_OFF);
}; };
this.cleanup = function() { this.cleanup = function() {