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) { Laser = function (side) {
// Draws hand lasers. // 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"; "use strict";
@ -47,6 +48,8 @@ Laser = function (side) {
LEFT_HAND = 0, LEFT_HAND = 0,
AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}", AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}",
uiEntityIDs = [],
intersection; intersection;
function colorPow(color, power) { // Per handControllerGrab.js. 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, var searchTarget,
sphereSize, sphereSize,
color, color,
@ -121,7 +124,11 @@ Laser = function (side) {
color = isClicked ? COLORS_GRAB_SEARCHING_FULL_SQUEEZE : COLORS_GRAB_SEARCHING_HALF_SQUEEZE; 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; brightColor = isClicked ? COLORS_GRAB_SEARCHING_FULL_SQUEEZE_BRIGHT : COLORS_GRAB_SEARCHING_HALF_SQUEEZE_BRIGHT;
if (isPressed) {
updateLine(origin, searchTarget, color); updateLine(origin, searchTarget, color);
} else {
Overlays.editOverlay(laserLine, { visible: false });
}
updateSphere(searchTarget, sphereSize, color, brightColor); updateSphere(searchTarget, sphereSize, color, brightColor);
} }
@ -130,6 +137,10 @@ Laser = function (side) {
Overlays.editOverlay(laserSphere, { visible: false }); Overlays.editOverlay(laserSphere, { visible: false });
} }
function setUIEntities(entityIDs) {
uiEntityIDs = entityIDs;
}
function update(hand) { function update(hand) {
var handPosition, var handPosition,
handOrientation, handOrientation,
@ -140,7 +151,7 @@ Laser = function (side) {
return; return;
} }
if (!hand.intersection().intersects && hand.triggerPressed()) { if (!hand.intersection().intersects) {
handPosition = hand.position(); handPosition = hand.position();
handOrientation = hand.orientation(); handOrientation = hand.orientation();
deltaOrigin = Vec3.multiplyQbyV(handOrientation, GRAB_POINT_SPHERE_OFFSET); deltaOrigin = Vec3.multiplyQbyV(handOrientation, GRAB_POINT_SPHERE_OFFSET);
@ -150,6 +161,9 @@ Laser = function (side) {
length: PICK_MAX_DISTANCE length: PICK_MAX_DISTANCE
}; };
if (hand.triggerPressed()) {
// Normal laser operation with trigger.
intersection = Overlays.findRayIntersection(pickRay, PRECISION_PICKING, NO_INCLUDE_IDS, NO_EXCLUDE_IDS, intersection = Overlays.findRayIntersection(pickRay, PRECISION_PICKING, NO_INCLUDE_IDS, NO_EXCLUDE_IDS,
VISIBLE_ONLY); VISIBLE_ONLY);
if (!intersection.intersects) { if (!intersection.intersects) {
@ -161,9 +175,33 @@ Laser = function (side) {
laserLength = (specifiedLaserLength !== null) laserLength = (specifiedLaserLength !== null)
? specifiedLaserLength ? specifiedLaserLength
: (intersection.intersects ? intersection.distance : PICK_MAX_DISTANCE); : (intersection.intersects ? intersection.distance : PICK_MAX_DISTANCE);
isLaserOn = true; isLaserOn = true;
display(pickRay.origin, pickRay.direction, laserLength, hand.triggerClicked()); 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 { } else {
intersection = { intersection = {
intersects: false intersects: false
@ -223,6 +261,7 @@ Laser = function (side) {
} }
return { return {
setUIEntities: setUIEntities,
update: update, update: update,
intersection: getIntersection, intersection: getIntersection,
setLength: setLength, setLength: setLength,

View file

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

View file

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