mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
- grab script: possible fix for line disappearing
- grab script: go from 3 pickrays back to 1 - grab script: put "sphere" test back in, but with fixed distance test
This commit is contained in:
parent
d0118e80a7
commit
f16b62df83
1 changed files with 61 additions and 41 deletions
|
@ -19,7 +19,7 @@ Script.include("../libraries/utils.js");
|
||||||
//
|
//
|
||||||
// add lines where the hand ray picking is happening
|
// add lines where the hand ray picking is happening
|
||||||
//
|
//
|
||||||
var DEBUG_HAND_RAY_PICKING = false;
|
var WANT_DEBUG = false;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
@ -193,22 +193,23 @@ function MyController(hand, triggerAction) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setState = function(newState) {
|
this.setState = function(newState) {
|
||||||
// print("STATE: " + this.state + " --> " + newState);
|
if (WANT_DEBUG) {
|
||||||
|
print("STATE: " + this.state + " --> " + newState);
|
||||||
|
}
|
||||||
this.state = newState;
|
this.state = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.debugLine = function(closePoint, farPoint, color){
|
this.debugLine = function(closePoint, farPoint, color){
|
||||||
Entities.addEntity({
|
Entities.addEntity({
|
||||||
type: "Line",
|
type: "Line",
|
||||||
name: "Debug Line",
|
name: "Debug Line",
|
||||||
dimensions: LINE_ENTITY_DIMENSIONS,
|
dimensions: LINE_ENTITY_DIMENSIONS,
|
||||||
visible: true,
|
visible: true,
|
||||||
position: closePoint,
|
position: closePoint,
|
||||||
linePoints: [ZERO_VEC, farPoint],
|
linePoints: [ZERO_VEC, farPoint],
|
||||||
color: color,
|
color: color,
|
||||||
lifetime: 0.1
|
lifetime: 0.1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lineOn = function(closePoint, farPoint, color) {
|
this.lineOn = function(closePoint, farPoint, color) {
|
||||||
|
@ -226,14 +227,13 @@ function MyController(hand, triggerAction) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var age = Entities.getEntityProperties(this.pointer, "age").age;
|
var age = Entities.getEntityProperties(this.pointer, "age").age;
|
||||||
Entities.editEntity(this.pointer, {
|
this.pointer = Entities.editEntity(this.pointer, {
|
||||||
position: closePoint,
|
position: closePoint,
|
||||||
linePoints: [ZERO_VEC, farPoint],
|
linePoints: [ZERO_VEC, farPoint],
|
||||||
color: color,
|
color: color,
|
||||||
lifetime: age + LIFETIME
|
lifetime: age + LIFETIME
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.lineOff = function() {
|
this.lineOff = function() {
|
||||||
|
@ -282,7 +282,6 @@ function MyController(hand, triggerAction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// the trigger is being pressed, do a ray test
|
// the trigger is being pressed, do a ray test
|
||||||
var handPosition = this.getHandPosition();
|
var handPosition = this.getHandPosition();
|
||||||
var distantPickRay = {
|
var distantPickRay = {
|
||||||
|
@ -290,29 +289,17 @@ function MyController(hand, triggerAction) {
|
||||||
direction: Quat.getUp(this.getHandRotation()),
|
direction: Quat.getUp(this.getHandRotation()),
|
||||||
length: PICK_MAX_DISTANCE
|
length: PICK_MAX_DISTANCE
|
||||||
};
|
};
|
||||||
var palmPickRay = {
|
|
||||||
origin: handPosition,
|
|
||||||
direction: Quat.getFront(this.getHandRotation()),
|
|
||||||
length: NEAR_PICK_MAX_DISTANCE
|
|
||||||
};
|
|
||||||
|
|
||||||
var otherPickRay = {
|
|
||||||
origin: handPosition,
|
|
||||||
direction: Quat.getRight(this.getHandRotation()),
|
|
||||||
length: NEAR_PICK_MAX_DISTANCE
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
this.lineOn(distantPickRay.origin, Vec3.multiply(distantPickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
|
this.lineOn(distantPickRay.origin, Vec3.multiply(distantPickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
|
||||||
|
|
||||||
// don't pick 60x per second. do this check after updating the line so it's not jumpy.
|
// don't pick 60x per second.
|
||||||
|
var pickRays = [];
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
if (now - this.lastPickTime < MSECS_PER_SEC / PICKS_PER_SECOND_PER_HAND) {
|
if (now - this.lastPickTime > MSECS_PER_SEC / PICKS_PER_SECOND_PER_HAND) {
|
||||||
return;
|
pickRays = [distantPickRay];
|
||||||
|
this.lastPickTime = now;
|
||||||
}
|
}
|
||||||
this.lastPickTime = now;
|
|
||||||
|
|
||||||
var pickRays = [distantPickRay, palmPickRay, otherPickRay];
|
|
||||||
for (var index=0; index < pickRays.length; ++index) {
|
for (var index=0; index < pickRays.length; ++index) {
|
||||||
var pickRay = pickRays[index];
|
var pickRay = pickRays[index];
|
||||||
var directionNormalized = Vec3.normalize(pickRay.direction);
|
var directionNormalized = Vec3.normalize(pickRay.direction);
|
||||||
|
@ -322,12 +309,13 @@ function MyController(hand, triggerAction) {
|
||||||
direction: pickRay.direction
|
direction: pickRay.direction
|
||||||
};
|
};
|
||||||
|
|
||||||
if (DEBUG_HAND_RAY_PICKING)
|
if (WANT_DEBUG) {
|
||||||
this.debugLine(pickRayBacked.origin, Vec3.multiply(pickRayBacked.direction, NEAR_PICK_MAX_DISTANCE), {
|
this.debugLine(pickRayBacked.origin, Vec3.multiply(pickRayBacked.direction, NEAR_PICK_MAX_DISTANCE), {
|
||||||
red: 0,
|
red: 0,
|
||||||
green: 255,
|
green: 255,
|
||||||
blue: 0
|
blue: 0
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var intersection = Entities.findRayIntersection(pickRayBacked, true);
|
var intersection = Entities.findRayIntersection(pickRayBacked, true);
|
||||||
|
|
||||||
|
@ -336,7 +324,6 @@ function MyController(hand, triggerAction) {
|
||||||
var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection);
|
var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection);
|
||||||
this.grabbedEntity = intersection.entityID;
|
this.grabbedEntity = intersection.entityID;
|
||||||
|
|
||||||
|
|
||||||
//this code will disabled the beam for the opposite hand of the one that grabbed it if the entity says so
|
//this code will disabled the beam for the opposite hand of the one that grabbed it if the entity says so
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA);
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA);
|
||||||
if (grabbableData["turnOffOppositeBeam"] === true) {
|
if (grabbableData["turnOffOppositeBeam"] === true) {
|
||||||
|
@ -345,7 +332,6 @@ function MyController(hand, triggerAction) {
|
||||||
} else {
|
} else {
|
||||||
disabledHand = RIGHT_HAND;
|
disabledHand = RIGHT_HAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
disabledHand = 'none';
|
disabledHand = 'none';
|
||||||
}
|
}
|
||||||
|
@ -380,6 +366,35 @@ function MyController(hand, triggerAction) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.grabbedEntity === null) {
|
||||||
|
// forward ray test failed, try sphere test.
|
||||||
|
var nearbyEntities = Entities.findEntities(handPosition, GRAB_RADIUS);
|
||||||
|
var minDistance = PICK_MAX_DISTANCE;
|
||||||
|
var i, props, distance;
|
||||||
|
for (i = 0; i < nearbyEntities.length; i++) {
|
||||||
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, nearbyEntities[i], DEFAULT_GRABBABLE_DATA);
|
||||||
|
if (grabbableData.grabbable === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var propsForCandidate =
|
||||||
|
Entities.getEntityProperties(nearbyEntities[i], ["position", "name", "collisionsWillMove", "locked"]);
|
||||||
|
distance = Vec3.distance(propsForCandidate.position, handPosition);
|
||||||
|
if (distance < minDistance && props.name !== "pointer") {
|
||||||
|
this.grabbedEntity = nearbyEntities[i];
|
||||||
|
minDistance = distance;
|
||||||
|
props = propsForCandidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.grabbedEntity === null) {
|
||||||
|
return;
|
||||||
|
} else if (props.locked === 0 && props.collisionsWillMove === 1) {
|
||||||
|
this.setState(STATE_NEAR_GRABBING);
|
||||||
|
} 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
|
||||||
|
this.setState(STATE_NEAR_GRABBING_NON_COLLIDING);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.distanceHolding = function() {
|
this.distanceHolding = function() {
|
||||||
|
@ -441,7 +456,8 @@ function MyController(hand, triggerAction) {
|
||||||
this.lineOn(handPosition, Vec3.subtract(grabbedProperties.position, handPosition), INTERSECT_COLOR);
|
this.lineOn(handPosition, Vec3.subtract(grabbedProperties.position, handPosition), INTERSECT_COLOR);
|
||||||
|
|
||||||
// the action was set up on a previous call. update the targets.
|
// the action was set up on a previous call. update the targets.
|
||||||
var radius = Math.max(Vec3.distance(this.currentObjectPosition, handControllerPosition) * DISTANCE_HOLDING_RADIUS_FACTOR, DISTANCE_HOLDING_RADIUS_FACTOR);
|
var radius = Math.max(Vec3.distance(this.currentObjectPosition, handControllerPosition) *
|
||||||
|
DISTANCE_HOLDING_RADIUS_FACTOR, DISTANCE_HOLDING_RADIUS_FACTOR);
|
||||||
// how far did avatar move this timestep?
|
// how far did avatar move this timestep?
|
||||||
var currentPosition = MyAvatar.position;
|
var currentPosition = MyAvatar.position;
|
||||||
var avatarDeltaPosition = Vec3.subtract(currentPosition, this.currentAvatarPosition);
|
var avatarDeltaPosition = Vec3.subtract(currentPosition, this.currentAvatarPosition);
|
||||||
|
@ -491,7 +507,10 @@ function MyController(hand, triggerAction) {
|
||||||
this.currentObjectTime = now;
|
this.currentObjectTime = now;
|
||||||
|
|
||||||
// this doubles hand rotation
|
// this doubles hand rotation
|
||||||
var handChange = Quat.multiply(Quat.slerp(this.handPreviousRotation, handRotation, DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR), Quat.inverse(this.handPreviousRotation));
|
var handChange = Quat.multiply(Quat.slerp(this.handPreviousRotation,
|
||||||
|
handRotation,
|
||||||
|
DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR),
|
||||||
|
Quat.inverse(this.handPreviousRotation));
|
||||||
this.handPreviousRotation = handRotation;
|
this.handPreviousRotation = handRotation;
|
||||||
this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation);
|
this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation);
|
||||||
|
|
||||||
|
@ -526,7 +545,8 @@ function MyController(hand, triggerAction) {
|
||||||
|
|
||||||
this.lineOff();
|
this.lineOff();
|
||||||
|
|
||||||
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation", "gravity", "ignoreForCollisions"]);
|
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity,
|
||||||
|
["position", "rotation", "gravity", "ignoreForCollisions"]);
|
||||||
this.activateEntity(this.grabbedEntity, grabbedProperties);
|
this.activateEntity(this.grabbedEntity, grabbedProperties);
|
||||||
|
|
||||||
var handRotation = this.getHandRotation();
|
var handRotation = this.getHandRotation();
|
||||||
|
@ -764,9 +784,9 @@ function MyController(hand, triggerAction) {
|
||||||
|
|
||||||
this.release = function() {
|
this.release = function() {
|
||||||
|
|
||||||
if(this.hand!==disabledHand){
|
if(this.hand !== disabledHand){
|
||||||
//release the disabled hand when we let go with the main one
|
//release the disabled hand when we let go with the main one
|
||||||
disabledHand='none';
|
disabledHand = 'none';
|
||||||
}
|
}
|
||||||
this.lineOff();
|
this.lineOff();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue