Remove input restrictions on grabbable web entities.

You no longer have to be grabbing a grabbable web entity to interact with it.
This commit is contained in:
Anthony J. Thibault 2016-08-05 15:25:54 -07:00
parent 1dd276c1a5
commit 0ba34c5635

View file

@ -170,6 +170,7 @@ var STATE_NEAR_GRABBING = 3;
var STATE_NEAR_TRIGGER = 4;
var STATE_FAR_TRIGGER = 5;
var STATE_HOLD = 6;
var STATE_ENTITY_TOUCHING = 7;
// "collidesWith" is specified by comma-separated list of group names
// the possible group names are: static, dynamic, kinematic, myAvatar, otherAvatar
@ -185,6 +186,8 @@ var delayedDeactivateEntityID;
var CONTROLLER_STATE_MACHINE = {};
var mostRecentSearchingHand = RIGHT_HAND;
CONTROLLER_STATE_MACHINE[STATE_OFF] = {
name: "off",
enterMethod: "offEnter",
@ -220,6 +223,40 @@ CONTROLLER_STATE_MACHINE[STATE_FAR_TRIGGER] = {
enterMethod: "farTriggerEnter",
updateMethod: "farTrigger"
};
CONTROLLER_STATE_MACHINE[STATE_ENTITY_TOUCHING] = {
name: "entityTouching",
enterMethod: "entityTouchingEnter",
exitMethod: "entityTouchingExit",
updateMethod: "entityTouching"
};
function handLaserIntersectWebEntity(entityID, hand) {
var standardControllerValue = (hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
var pose = Controller.getPoseValue(standardControllerValue);
var worldHandPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, pose.translation), MyAvatar.position);
var worldHandRotation = Quat.multiply(MyAvatar.orientation, pose.rotation);
var props = entityPropertiesCache.getProps(entityID);
var planePosition = props.position;
var planeNormal = Vec3.multiplyQbyV(props.rotation, {x: 0, y: 0, z: 1.0});
var rayStart = worldHandPosition;
var rayDirection = Quat.getUp(worldHandRotation);
var intersectionInfo = rayIntersectPlane(planePosition, planeNormal, rayStart, rayDirection);
var intersectionPoint = planePosition;
if (intersectionInfo.hit && intersectionInfo.distance > 0) {
intersectionPoint = Vec3.sum(rayStart, Vec3.multiply(intersectionInfo.distance, rayDirection));
} else {
intersectionPoint = planePosition;
}
intersectionInfo.point = intersectionPoint;
intersectionInfo.searchRay = {
origin: rayStart,
direction: rayDirection,
length: PICK_MAX_DISTANCE
};
return intersectionInfo;
}
function rayIntersectPlane(planePosition, planeNormal, rayStart, rayDirection) {
var rayDirectionDotPlaneNormal = Vec3.dot(rayDirection, planeNormal);
@ -743,8 +780,6 @@ function MyController(hand) {
}
};
this.searchSphereOn = function(location, size, color) {
var rotation = Quat.lookAt(location, Camera.getPosition(), Vec3.UP);
@ -1257,7 +1292,7 @@ function MyController(hand) {
};
this.searchEnter = function() {
this.capturedWebEntity = null;
mostRecentSearchingHand = this.hand;
};
this.search = function(deltaTime, timestamp) {
@ -1283,59 +1318,6 @@ function MyController(hand) {
entityPropertiesCache.addEntity(rayPickInfo.entityID);
}
// route simulated touch events to a webEntity.
if (this.capturedWebEntity ||
(rayPickInfo.entityID && entityPropertiesCache.getProps(rayPickInfo.entityID).type === "Web" &&
(!this.entityIsGrabbable(rayPickInfo.entityID) || this.getOtherHandController().grabbedEntity == rayPickInfo.entityID))) {
var standardControllerValue = (hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
var pose = Controller.getPoseValue(standardControllerValue);
var worldHandPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, pose.translation), MyAvatar.position);
var worldHandRotation = Quat.multiply(MyAvatar.orientation, pose.rotation);
var focusedEntity = this.capturedWebEntity || rayPickInfo.entityID;
entityPropertiesCache.addEntity(focusedEntity);
var props = entityPropertiesCache.getProps(focusedEntity);
var planePosition = props.position
var planeNormal = Vec3.multiplyQbyV(props.rotation, {x: 0, y: 0, z: 1.0});
var rayStart = worldHandPosition;
var rayDirection = Quat.getUp(worldHandRotation);
var intersectionInfo = rayIntersectPlane(planePosition, planeNormal, rayStart, rayDirection);
var intersectionPoint = planePosition;
if (intersectionInfo.hit && intersectionInfo.distance > 0) {
intersectionPoint = Vec3.sum(rayStart, Vec3.multiply(intersectionInfo.distance, rayDirection));
} else {
intersectionPoint = planePosition;
}
if (Reticle.keyboardFocusEntity != focusedEntity) {
Reticle.keyboardFocusEntity = focusedEntity;
}
if (!this.triggerSmoothedGrab()) {
// send mouse events for button highlights and tooltips
Reticle.sendEntityMouseMoveEvent(focusedEntity, intersectionPoint);
} else {
// but send touch updates when grab is pressed.
Reticle.sendEntityTouchUpdateEvent(focusedEntity, this.hand, intersectionPoint);
}
if (this.triggerSmoothedGrab() && !this.lastTriggerSmoothedGrab) {
Reticle.sendEntityTouchBeginEvent(focusedEntity, this.hand, intersectionPoint);
this.capturedWebEntity = focusedEntity;
}
if (!this.triggerSmoothedGrab() && this.lastTriggerSmoothedGrab) {
Reticle.sendEntityTouchEndEvent(focusedEntity, this.hand, intersectionPoint);
this.capturedWebEntity = null;
}
this.lastTriggerSmoothedGrab = this.triggerSmoothedGrab();
equipHotspotBuddy.updateHotspots([], timestamp);
this.intersectionDistance = intersectionInfo.distance;
} else {
var candidateEntities = Entities.findEntities(handPosition, NEAR_GRAB_RADIUS);
entityPropertiesCache.addEntities(candidateEntities);
@ -1403,6 +1385,29 @@ function MyController(hand) {
}
}
if (rayPickInfo.entityID && entityPropertiesCache.getProps(rayPickInfo.entityID).type === "Web") {
entity = rayPickInfo.entityID;
name = entityPropertiesCache.getProps(entity).name;
if (Reticle.keyboardFocusEntity != entity) {
Reticle.keyboardFocusEntity = entity;
}
// send mouse events for button highlights and tooltips.
if (this.hand == mostRecentSearchingHand || (this.hand !== mostRecentSearchingHand &&
this.getOtherHandController().state !== STATE_SEARCHING &&
this.getOtherHandController().state !== STATE_ENTITY_TOUCHING)) {
// most recently searching hand has priority over other hand, for the purposes of button highlighting.
Reticle.sendEntityMouseMoveEvent(entity, rayPickInfo.intersection);
}
if (this.triggerSmoothedGrab() && !isEditing()) {
this.grabbedEntity = entity;
this.setState(STATE_ENTITY_TOUCHING, "begin touching entity '" + name + "'");
return;
}
}
if (rayPickInfo.entityID) {
entity = rayPickInfo.entityID;
name = entityPropertiesCache.getProps(entity).name;
@ -1432,7 +1437,6 @@ function MyController(hand) {
if (potentialEquipHotspot) {
equipHotspotBuddy.highlightHotspot(potentialEquipHotspot);
}
}
this.searchIndicatorOn(rayPickInfo.searchRay);
Reticle.setVisible(false);
@ -2044,6 +2048,40 @@ function MyController(hand) {
this.release();
};
this.entityTouchingEnter = function() {
// test for intersection between controller laser and web entity plane.
var intersectInfo = handLaserIntersectWebEntity(this.grabbedEntity, this.hand);
Reticle.sendEntityTouchBeginEvent(this.grabbedEntity, this.hand, intersectInfo.point);
};
this.entityTouchingExit = function() {
// test for intersection between controller laser and web entity plane.
var intersectInfo = handLaserIntersectWebEntity(this.grabbedEntity, this.hand);
Reticle.sendEntityTouchEndEvent(this.grabbedEntity, this.hand, intersectInfo.point);
};
this.entityTouching = function() {
entityPropertiesCache.addEntity(this.grabbedEntity);
if (!this.triggerSmoothedGrab()) {
this.setState(STATE_OFF, "released trigger");
return;
}
// test for intersection between controller laser and web entity plane.
var intersectInfo = handLaserIntersectWebEntity(this.grabbedEntity, this.hand);
if (Reticle.keyboardFocusEntity != this.grabbedEntity) {
Reticle.keyboardFocusEntity = this.grabbedEntity;
}
Reticle.sendEntityTouchUpdateEvent(this.grabbedEntity, this.hand, intersectInfo.point);
this.intersectionDistance = intersectInfo.distance;
this.searchIndicatorOn(intersectInfo.searchRay);
Reticle.setVisible(false);
};
this.release = function() {
Messages.sendLocalMessage('Hifi-Teleport-Disabler','none');
this.turnOffVisualizations();