Show laser dot on UI even if trigger isn't squeezed

This commit is contained in:
David Rowe 2017-07-26 17:26:43 +12:00
parent 194a82974b
commit 8dceb3cc6c
3 changed files with 86 additions and 18 deletions

View file

@ -12,7 +12,8 @@
Laser = function (side) {
// Draws hand lasers.
// May intersect with entities or bounding box of other hand's selection.
// May intersect with overlays or entities, or bounding box of other hand's selection.
// Laser dot is always drawn on UI entities.
"use strict";
@ -47,6 +48,8 @@ Laser = function (side) {
LEFT_HAND = 0,
AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}",
uiEntityIDs = [],
intersection;
function colorPow(color, power) { // Per handControllerGrab.js.
@ -109,7 +112,7 @@ Laser = function (side) {
});
}
function display(origin, direction, distance, isClicked) {
function display(origin, direction, distance, isPressed, isClicked) {
var searchTarget,
sphereSize,
color,
@ -121,7 +124,11 @@ Laser = function (side) {
color = isClicked ? COLORS_GRAB_SEARCHING_FULL_SQUEEZE : COLORS_GRAB_SEARCHING_HALF_SQUEEZE;
brightColor = isClicked ? COLORS_GRAB_SEARCHING_FULL_SQUEEZE_BRIGHT : COLORS_GRAB_SEARCHING_HALF_SQUEEZE_BRIGHT;
updateLine(origin, searchTarget, color);
if (isPressed) {
updateLine(origin, searchTarget, color);
} else {
Overlays.editOverlay(laserLine, { visible: false });
}
updateSphere(searchTarget, sphereSize, color, brightColor);
}
@ -130,6 +137,10 @@ Laser = function (side) {
Overlays.editOverlay(laserSphere, { visible: false });
}
function setUIEntities(entityIDs) {
uiEntityIDs = entityIDs;
}
function update(hand) {
var handPosition,
handOrientation,
@ -140,7 +151,7 @@ Laser = function (side) {
return;
}
if (!hand.intersection().intersects && hand.triggerPressed()) {
if (!hand.intersection().intersects) {
handPosition = hand.position();
handOrientation = hand.orientation();
deltaOrigin = Vec3.multiplyQbyV(handOrientation, GRAB_POINT_SPHERE_OFFSET);
@ -150,20 +161,47 @@ Laser = function (side) {
length: PICK_MAX_DISTANCE
};
intersection = Overlays.findRayIntersection(pickRay, PRECISION_PICKING, NO_INCLUDE_IDS, NO_EXCLUDE_IDS,
VISIBLE_ONLY);
if (!intersection.intersects) {
intersection = Entities.findRayIntersection(pickRay, PRECISION_PICKING, NO_INCLUDE_IDS, NO_EXCLUDE_IDS,
VISIBLE_ONLY);
intersection.editableEntity = intersection.intersects && Entities.hasEditableRoot(intersection.entityID);
}
intersection.laserIntersected = true;
laserLength = (specifiedLaserLength !== null)
? specifiedLaserLength
: (intersection.intersects ? intersection.distance : PICK_MAX_DISTANCE);
if (hand.triggerPressed()) {
isLaserOn = true;
display(pickRay.origin, pickRay.direction, laserLength, hand.triggerClicked());
// Normal laser operation with trigger.
intersection = Overlays.findRayIntersection(pickRay, PRECISION_PICKING, NO_INCLUDE_IDS, NO_EXCLUDE_IDS,
VISIBLE_ONLY);
if (!intersection.intersects) {
intersection = Entities.findRayIntersection(pickRay, PRECISION_PICKING, NO_INCLUDE_IDS, NO_EXCLUDE_IDS,
VISIBLE_ONLY);
intersection.editableEntity = intersection.intersects && Entities.hasEditableRoot(intersection.entityID);
}
intersection.laserIntersected = true;
laserLength = (specifiedLaserLength !== null)
? specifiedLaserLength
: (intersection.intersects ? intersection.distance : PICK_MAX_DISTANCE);
isLaserOn = true;
display(pickRay.origin, pickRay.direction, laserLength, true, hand.triggerClicked());
} else {
// Special hovering of UI.
intersection = Overlays.findRayIntersection(pickRay, PRECISION_PICKING, NO_INCLUDE_IDS, NO_EXCLUDE_IDS,
VISIBLE_ONLY); // Check for overlay intersections in case they occlude the UI entities.
if (!intersection.intersects) {
intersection = Entities.findRayIntersection(pickRay, PRECISION_PICKING, uiEntityIDs, NO_EXCLUDE_IDS,
VISIBLE_ONLY);
}
if (intersection.intersects && intersection.entityID) {
intersection.laserIntersected = true;
laserLength = (specifiedLaserLength !== null)
? specifiedLaserLength
: (intersection.intersects ? intersection.distance : PICK_MAX_DISTANCE);
isLaserOn = true;
display(pickRay.origin, pickRay.direction, laserLength, false, false);
} else {
if (isLaserOn) {
isLaserOn = false;
hide();
}
}
}
} else {
intersection = {
intersects: false
@ -223,6 +261,7 @@ Laser = function (side) {
}
return {
setUIEntities: setUIEntities,
update: update,
intersection: getIntersection,
setLength: setLength,

View file

@ -66,6 +66,10 @@ ToolMenu = function (side, scaleModeChangedCallback) {
}
}
function getEntityIDs() {
return [panelEntity, buttonEntity];
}
function update() {
// TODO
}
@ -126,6 +130,7 @@ ToolMenu = function (side, scaleModeChangedCallback) {
return {
setHand: setHand,
getEntityIDs: getEntityIDs,
update: update,
display: display,
clear: clear,

View file

@ -92,6 +92,10 @@
hand = new Hand(side);
laser = new Laser(side);
function setUIEntities(entityIDs) {
laser.setUIEntities(entityIDs);
}
function getHand() {
return hand;
}
@ -140,6 +144,7 @@
}
return {
setUIEntities: setUIEntities,
hand: getHand,
laser: getLaser,
getIntersection: getIntersection,
@ -154,17 +159,32 @@
// Tool menu and Create palette.
var // Primary objects.
toolMenu;
toolMenu,
// References.
leftInputs,
rightInputs;
toolMenu = new ToolMenu(side);
function setReferences(left, right) {
leftInputs = left;
rightInputs = right;
}
function setHand(side) {
toolMenu.setHand(side);
}
function display() {
var uiEntityIDs;
toolMenu.display();
uiEntityIDs = toolMenu.getEntityIDs();
leftInputs.setUIEntities(uiEntityIDs);
rightInputs.setUIEntities(uiEntityIDs);
}
function update() {
@ -172,6 +192,8 @@
}
function clear() {
leftInputs.setUIEntities([]);
rightInputs.setUIEntities([]);
toolMenu.clear();
}
@ -187,6 +209,7 @@
}
return {
setReferences: setReferences,
setHand: setHand,
display: display,
update: update,
@ -987,6 +1010,7 @@
// UI object.
ui = new UI(otherHand(dominantHand));
ui.setReferences(inputs[LEFT_HAND], inputs[RIGHT_HAND]);
// Editor objects.
editors[LEFT_HAND] = new Editor(LEFT_HAND);