552 lines
20 KiB
JavaScript
Raw Normal View History

2017-08-31 18:06:55 -07:00
"use strict";
2017-08-23 17:32:41 -07:00
// overlayLaserInput.js
2017-08-23 17:32:41 -07:00
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/* global Script, Entities, Controller, RIGHT_HAND, LEFT_HAND, NULL_UUID, enableDispatcherModule, disableDispatcherModule,
makeRunningValues, Messages, Quat, Vec3, makeDispatcherModuleParameters, Overlays, ZERO_VEC, AVATAR_SELF_ID, HMD,
INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, getGrabPointSphereOffset, COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE,
TRIGGER_OFF_VALUE, getEnabledModuleByName, PICK_MAX_DISTANCE, LaserPointers, RayPick, ContextOverlay
2017-08-23 17:32:41 -07:00
*/
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
2017-08-23 17:32:41 -07:00
Script.include("/~/system/libraries/controllers.js");
(function() {
2017-08-31 18:06:55 -07:00
var halfPath = {
2017-08-23 17:32:41 -07:00
type: "line3d",
color: COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
lineWidth: 5,
ignoreRayIntersection: true, // always ignore this
drawInFront: true, // Even when burried inside of something, show it.
parentID: AVATAR_SELF_ID
};
var halfEnd = {
type: "sphere",
solid: true,
color: COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
alpha: 0.9,
ignoreRayIntersection: true,
drawInFront: true, // Even when burried inside of something, show it.
visible: true
};
var fullPath = {
type: "line3d",
color: COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
lineWidth: 5,
ignoreRayIntersection: true, // always ignore this
drawInFront: true, // Even when burried inside of something, show it.
parentID: AVATAR_SELF_ID
};
var fullEnd = {
type: "sphere",
solid: true,
color: COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
alpha: 0.9,
ignoreRayIntersection: true,
drawInFront: true, // Even when burried inside of something, show it.
visible: true
};
var holdPath = {
type: "line3d",
color: COLORS_GRAB_DISTANCE_HOLD,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
lineWidth: 5,
ignoreRayIntersection: true, // always ignore this
drawInFront: true, // Even when burried inside of something, show it.
parentID: AVATAR_SELF_ID
};
2017-08-25 14:20:31 -07:00
2017-08-31 18:06:55 -07:00
var renderStates = [
{name: "half", path: halfPath, end: halfEnd},
{name: "full", path: fullPath, end: fullEnd},
{name: "hold", path: holdPath}
];
2017-08-23 17:32:41 -07:00
2017-08-31 18:06:55 -07:00
var defaultRenderStates = [
{name: "half", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: halfPath},
{name: "full", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: fullPath},
{name: "hold", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: holdPath}
];
2017-08-25 14:20:31 -07:00
2017-08-23 17:32:41 -07:00
// triggered when stylus presses a web overlay/entity
var HAPTIC_STYLUS_STRENGTH = 1.0;
var HAPTIC_STYLUS_DURATION = 20.0;
2017-08-25 14:20:31 -07:00
function laserTargetHasKeyboardFocus(laserTarget) {
2017-08-24 17:42:27 -07:00
if (laserTarget && laserTarget !== NULL_UUID) {
return Overlays.keyboardFocusOverlay === laserTarget;
2017-08-23 17:32:41 -07:00
}
}
2017-08-25 14:20:31 -07:00
function setKeyboardFocusOnLaserTarget(laserTarget) {
2017-08-24 17:42:27 -07:00
if (laserTarget && laserTarget !== NULL_UUID) {
Overlays.keyboardFocusOverlay = laserTarget;
2017-08-23 17:32:41 -07:00
Entities.keyboardFocusEntity = NULL_UUID;
}
}
2017-08-25 14:20:31 -07:00
function sendHoverEnterEventToLaserTarget(hand, laserTarget) {
2017-08-24 17:42:27 -07:00
if (!laserTarget) {
return;
}
2017-08-23 17:32:41 -07:00
var pointerEvent = {
type: "Move",
id: hand + 1, // 0 is reserved for hardware mouse
2017-08-24 17:42:27 -07:00
pos2D: laserTarget.position2D,
pos3D: laserTarget.position,
normal: laserTarget.normal,
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
2017-08-23 17:32:41 -07:00
button: "None"
};
2017-08-24 17:42:27 -07:00
if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
Overlays.sendHoverEnterOverlay(laserTarget.overlayID, pointerEvent);
2017-08-23 17:32:41 -07:00
}
}
2017-08-25 14:20:31 -07:00
function sendHoverOverEventToLaserTarget(hand, laserTarget) {
2017-08-24 17:42:27 -07:00
if (!laserTarget) {
return;
}
2017-08-23 17:32:41 -07:00
var pointerEvent = {
type: "Move",
id: hand + 1, // 0 is reserved for hardware mouse
2017-08-24 17:42:27 -07:00
pos2D: laserTarget.position2D,
pos3D: laserTarget.position,
normal: laserTarget.normal,
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
2017-08-23 17:32:41 -07:00
button: "None"
};
2017-08-24 17:42:27 -07:00
if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
Overlays.sendMouseMoveOnOverlay(laserTarget.overlayID, pointerEvent);
Overlays.sendHoverOverOverlay(laserTarget.overlayID, pointerEvent);
2017-08-23 17:32:41 -07:00
}
}
2017-08-25 14:20:31 -07:00
function sendTouchStartEventToLaserTarget(hand, laserTarget) {
2017-08-24 17:42:27 -07:00
if (!laserTarget) {
return;
}
2017-08-25 14:20:31 -07:00
2017-08-23 17:32:41 -07:00
var pointerEvent = {
type: "Press",
id: hand + 1, // 0 is reserved for hardware mouse
2017-08-24 17:42:27 -07:00
pos2D: laserTarget.position2D,
pos3D: laserTarget.position,
normal: laserTarget.normal,
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
2017-08-23 17:32:41 -07:00
button: "Primary",
isPrimaryHeld: true
};
2017-08-24 17:42:27 -07:00
if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
Overlays.sendMousePressOnOverlay(laserTarget.overlayID, pointerEvent);
2017-08-23 17:32:41 -07:00
}
}
2017-08-25 14:20:31 -07:00
function sendTouchEndEventToLaserTarget(hand, laserTarget) {
2017-08-24 17:42:27 -07:00
if (!laserTarget) {
return;
}
2017-08-23 17:32:41 -07:00
var pointerEvent = {
type: "Release",
id: hand + 1, // 0 is reserved for hardware mouse
2017-08-24 17:42:27 -07:00
pos2D: laserTarget.position2D,
pos3D: laserTarget.position,
normal: laserTarget.normal,
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
2017-08-23 17:32:41 -07:00
button: "Primary"
};
2017-08-24 17:42:27 -07:00
if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
Overlays.sendMouseReleaseOnOverlay(laserTarget.overlayID, pointerEvent);
2017-08-25 14:20:31 -07:00
Overlays.sendMouseReleaseOnOverlay(laserTarget.overlayID, pointerEvent);
2017-08-23 17:32:41 -07:00
}
}
2017-08-25 14:20:31 -07:00
function sendTouchMoveEventToLaserTarget(hand, laserTarget) {
2017-08-24 17:42:27 -07:00
if (!laserTarget) {
return;
}
2017-08-23 17:32:41 -07:00
var pointerEvent = {
type: "Move",
id: hand + 1, // 0 is reserved for hardware mouse
2017-08-24 17:42:27 -07:00
pos2D: laserTarget.position2D,
pos3D: laserTarget.position,
normal: laserTarget.normal,
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
2017-08-23 17:32:41 -07:00
button: "Primary",
isPrimaryHeld: true
};
2017-08-25 14:20:31 -07:00
2017-08-24 17:42:27 -07:00
if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
Overlays.sendMouseReleaseOnOverlay(laserTarget.overlayID, pointerEvent);
2017-08-23 17:32:41 -07:00
}
}
// will return undefined if overlayID does not exist.
2017-08-31 18:06:55 -07:00
function calculateLaserTargetFromOverlay(worldPos, overlayID) {
2017-08-23 17:32:41 -07:00
var overlayPosition = Overlays.getProperty(overlayID, "position");
if (overlayPosition === undefined) {
2017-08-25 14:20:31 -07:00
return null;
2017-08-23 17:32:41 -07:00
}
// project stylusTip onto overlay plane.
var overlayRotation = Overlays.getProperty(overlayID, "rotation");
if (overlayRotation === undefined) {
2017-08-25 14:20:31 -07:00
return null;
2017-08-23 17:32:41 -07:00
}
var normal = Vec3.multiplyQbyV(overlayRotation, {x: 0, y: 0, z: 1});
2017-08-31 18:06:55 -07:00
var distance = Vec3.dot(Vec3.subtract(worldPos, overlayPosition), normal);
2017-08-23 17:32:41 -07:00
// calclulate normalized position
var invRot = Quat.inverse(overlayRotation);
2017-08-31 18:06:55 -07:00
var localPos = Vec3.multiplyQbyV(invRot, Vec3.subtract(worldPos, overlayPosition));
2017-08-23 17:32:41 -07:00
var dpi = Overlays.getProperty(overlayID, "dpi");
var dimensions;
if (dpi) {
// Calculate physical dimensions for web3d overlay from resolution and dpi; "dimensions" property
// is used as a scale.
var resolution = Overlays.getProperty(overlayID, "resolution");
if (resolution === undefined) {
2017-08-25 14:20:31 -07:00
return null;
2017-08-23 17:32:41 -07:00
}
2017-08-31 18:06:55 -07:00
resolution.z = 1;// Circumvent divide-by-zero.
2017-08-23 17:32:41 -07:00
var scale = Overlays.getProperty(overlayID, "dimensions");
if (scale === undefined) {
2017-08-25 14:20:31 -07:00
return null;
2017-08-23 17:32:41 -07:00
}
2017-08-31 18:06:55 -07:00
scale.z = 0.01;// overlay dimensions are 2D, not 3D.
2017-08-23 17:32:41 -07:00
dimensions = Vec3.multiplyVbyV(Vec3.multiply(resolution, INCHES_TO_METERS / dpi), scale);
} else {
dimensions = Overlays.getProperty(overlayID, "dimensions");
if (dimensions === undefined) {
2017-08-25 14:20:31 -07:00
return null;
2017-08-23 17:32:41 -07:00
}
if (!dimensions.z) {
2017-08-31 18:06:55 -07:00
dimensions.z = 0.01;// sometimes overlay dimensions are 2D, not 3D.
2017-08-23 17:32:41 -07:00
}
}
var invDimensions = { x: 1 / dimensions.x, y: 1 / dimensions.y, z: 1 / dimensions.z };
var normalizedPosition = Vec3.sum(Vec3.multiplyVbyV(localPos, invDimensions), DEFAULT_REGISTRATION_POINT);
// 2D position on overlay plane in meters, relative to the bounding box upper-left hand corner.
2017-08-31 18:06:55 -07:00
var position2D = {
x: normalizedPosition.x * dimensions.x,
y: (1 - normalizedPosition.y) * dimensions.y // flip y-axis
};
2017-08-23 17:32:41 -07:00
return {
entityID: null,
overlayID: overlayID,
distance: distance,
2017-08-31 18:06:55 -07:00
position: worldPos,
2017-08-23 17:32:41 -07:00
position2D: position2D,
normal: normal,
normalizedPosition: normalizedPosition,
dimensions: dimensions,
valid: true
};
}
function distance2D(a, b) {
var dx = (a.x - b.x);
var dy = (a.y - b.y);
return Math.sqrt(dx * dx + dy * dy);
}
function OverlayLaserInput(hand) {
2017-08-23 17:32:41 -07:00
this.hand = hand;
2017-08-25 14:20:31 -07:00
this.active = false;
2017-08-24 17:42:27 -07:00
this.previousLaserClikcedTarget = false;
this.laserPressingTarget = false;
2017-08-25 17:40:30 -07:00
this.tabletScreenID = null;
2017-08-24 17:42:27 -07:00
this.mode = "none";
this.laserTargetID = null;
this.laserTarget = null;
this.pressEnterLaserTarget = null;
this.hover = false;
this.target = null;
2017-08-25 14:20:31 -07:00
this.lastValidTargetID = this.tabletTargetID;
2017-08-23 17:32:41 -07:00
this.parameters = makeDispatcherModuleParameters(
120,
2017-08-23 17:32:41 -07:00
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
[],
100);
this.getOtherHandController = function() {
return (this.hand === RIGHT_HAND) ? Controller.Standard.LeftHand : Controller.Standard.RightHand;
};
2017-08-25 14:20:31 -07:00
this.getOtherModule = function() {
return (this.hand === RIGHT_HAND) ? leftOverlayLaserInput : rightOverlayLaserInput;
2017-08-25 14:20:31 -07:00
};
2017-08-23 17:32:41 -07:00
this.handToController = function() {
return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
};
this.stealTouchFocus = function(laserTarget) {
2017-08-24 17:42:27 -07:00
this.requestTouchFocus(laserTarget);
2017-08-23 17:32:41 -07:00
};
this.requestTouchFocus = function(laserTarget) {
2017-08-25 14:20:31 -07:00
if (laserTarget !== null || laserTarget !== undefined) {
sendHoverEnterEventToLaserTarget(this.hand, this.laserTarget);
this.lastValidTargetID = laserTarget;
}
2017-08-23 17:32:41 -07:00
};
this.relinquishTouchFocus = function() {
// send hover leave event.
var pointerEvent = { type: "Move", id: this.hand + 1 };
2017-08-25 14:20:31 -07:00
Overlays.sendMouseMoveOnOverlay(this.lastValidTargetID, pointerEvent);
Overlays.sendHoverOverOverlay(this.lastValidTargetID, pointerEvent);
Overlays.sendHoverLeaveOverlay(this.lastValidID, pointerEvent);
2017-08-23 17:32:41 -07:00
};
this.updateLaserPointer = function(controllerData) {
var RADIUS = 0.005;
var dim = { x: RADIUS, y: RADIUS, z: RADIUS };
2017-08-25 14:20:31 -07:00
2017-08-24 17:42:27 -07:00
if (this.mode === "full") {
2017-08-23 17:32:41 -07:00
this.fullEnd.dimensions = dim;
2017-08-24 17:42:27 -07:00
LaserPointers.editRenderState(this.laserPointer, this.mode, {path: fullPath, end: this.fullEnd});
} else if (this.mode === "half") {
2017-08-23 17:32:41 -07:00
this.halfEnd.dimensions = dim;
2017-08-24 17:42:27 -07:00
LaserPointers.editRenderState(this.laserPointer, this.mode, {path: halfPath, end: this.halfEnd});
2017-08-23 17:32:41 -07:00
}
LaserPointers.enableLaserPointer(this.laserPointer);
2017-08-24 17:42:27 -07:00
LaserPointers.setRenderState(this.laserPointer, this.mode);
2017-08-23 17:32:41 -07:00
};
2017-08-24 17:42:27 -07:00
this.processControllerTriggers = function(controllerData) {
if (controllerData.triggerClicks[this.hand]) {
this.mode = "full";
this.laserPressingTarget = true;
this.hover = false;
} else if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
this.mode = "half";
this.laserPressingTarget = false;
this.hover = true;
2017-08-25 14:20:31 -07:00
this.requestTouchFocus(this.laserTargetID);
2017-08-24 17:42:27 -07:00
} else {
this.mode = "none";
this.laserPressingTarget = false;
this.hover = false;
this.relinquishTouchFocus();
2017-08-25 14:20:31 -07:00
2017-08-23 17:32:41 -07:00
}
};
2017-08-24 17:42:27 -07:00
this.hovering = function() {
2017-08-25 17:40:30 -07:00
if (!laserTargetHasKeyboardFocus(this.laserTagetID)) {
setKeyboardFocusOnLaserTarget(this.laserTargetID);
2017-08-24 17:42:27 -07:00
}
2017-08-25 17:40:30 -07:00
sendHoverOverEventToLaserTarget(this.hand, this.laserTarget);
2017-08-23 17:32:41 -07:00
};
2017-08-24 17:42:27 -07:00
this.laserPressEnter = function () {
2017-08-25 14:20:31 -07:00
sendTouchStartEventToLaserTarget(this.hand, this.laserTarget);
2017-08-23 17:32:41 -07:00
Controller.triggerHapticPulse(HAPTIC_STYLUS_STRENGTH, HAPTIC_STYLUS_DURATION, this.hand);
this.touchingEnterTimer = 0;
2017-08-24 17:42:27 -07:00
this.pressEnterLaserTarget = this.laserTarget;
2017-08-23 17:32:41 -07:00
this.deadspotExpired = false;
2017-08-25 14:20:31 -07:00
var LASER_PRESS_TO_MOVE_DEADSPOT = 0.026;
this.deadspotRadius = Math.tan(LASER_PRESS_TO_MOVE_DEADSPOT) * this.laserTarget.distance;
2017-08-23 17:32:41 -07:00
};
2017-08-24 17:42:27 -07:00
this.laserPressExit = function () {
2017-08-25 14:20:31 -07:00
if (this.laserTarget === null) {
2017-08-23 17:32:41 -07:00
return;
}
// special case to handle home button.
2017-08-24 17:42:27 -07:00
if (this.laserTargetID === HMD.homeButtonID) {
Messages.sendLocalMessage("home", this.laserTargetID);
2017-08-23 17:32:41 -07:00
}
// send press event
if (this.deadspotExpired) {
2017-08-25 14:20:31 -07:00
sendTouchEndEventToLaserTarget(this.hand, this.laserTarget);
2017-08-23 17:32:41 -07:00
} else {
2017-08-25 14:20:31 -07:00
sendTouchEndEventToLaserTarget(this.hand, this.pressEnterLaserTarget);
2017-08-23 17:32:41 -07:00
}
};
2017-08-24 17:42:27 -07:00
this.laserPressing = function (controllerData, dt) {
2017-08-23 17:32:41 -07:00
this.touchingEnterTimer += dt;
2017-08-24 17:42:27 -07:00
if (this.laserTarget) {
var POINTER_PRESS_TO_MOVE_DELAY = 0.33; // seconds
if (this.deadspotExpired || this.touchingEnterTimer > POINTER_PRESS_TO_MOVE_DELAY ||
2017-08-31 18:06:55 -07:00
distance2D( this.laserTarget.position2D,
this.pressEnterLaserTarget.position2D) > this.deadspotRadius) {
2017-08-25 14:20:31 -07:00
sendTouchMoveEventToLaserTarget(this.hand, this.laserTarget);
2017-08-24 17:42:27 -07:00
this.deadspotExpired = true;
2017-08-23 17:32:41 -07:00
}
} else {
2017-08-24 17:42:27 -07:00
this.laserPressingTarget = false;
2017-08-23 17:32:41 -07:00
}
};
2017-08-25 14:20:31 -07:00
this.releaseTouchEvent = function() {
sendTouchEndEventToLaserTarget(this.hand, this.pressEnterLaserTarget);
2017-08-31 18:06:55 -07:00
};
2017-08-25 14:20:31 -07:00
2017-08-25 17:40:30 -07:00
this.updateLaserTargets = function(controllerData) {
var intersection = controllerData.rayPicks[this.hand];
2017-08-25 14:20:31 -07:00
this.laserTargetID = intersection.objectID;
this.laserTarget = calculateLaserTargetFromOverlay(intersection.intersection, intersection.objectID);
2017-08-23 17:32:41 -07:00
};
2017-08-25 14:20:31 -07:00
this.shouldExit = function(controllerData) {
2017-08-25 17:40:30 -07:00
var intersection = controllerData.rayPicks[this.hand];
2017-09-08 11:50:19 -07:00
var nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay";
var nearGrabModule = getEnabledModuleByName(nearGrabName);
var status = nearGrabModule ? nearGrabModule.isReady(controllerData) : makeRunningValues(false, [], []);
2017-08-31 18:06:55 -07:00
var offOverlay = (intersection.type !== RayPick.INTERSECTED_OVERLAY);
2017-09-12 10:53:04 -07:00
var triggerOff = (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE);
2017-09-08 13:30:30 -07:00
return offOverlay || status.active || triggerOff;
2017-08-31 18:06:55 -07:00
};
2017-08-25 14:20:31 -07:00
this.exitModule = function() {
this.releaseTouchEvent();
this.relinquishTouchFocus();
this.reset();
this.updateLaserPointer();
LaserPointers.disableLaserPointer(this.laserPointer);
2017-08-31 18:06:55 -07:00
};
2017-08-25 14:20:31 -07:00
2017-08-24 17:42:27 -07:00
this.reset = function() {
this.hover = false;
this.pressEnterLaserTarget = null;
this.laserTarget = null;
this.laserTargetID = null;
this.laserPressingTarget = false;
this.previousLaserClickedTarget = null;
this.mode = "none";
2017-08-25 14:20:31 -07:00
this.active = false;
2017-08-24 17:42:27 -07:00
};
this.deleteContextOverlay = function() {
var farGrabModule = getEnabledModuleByName(this.hand === RIGHT_HAND ? "RightFarActionGrabEntity" : "LeftFarActionGrabEntity");
if (farGrabModule) {
var entityWithContextOverlay = farGrabModule.entityWithContextOverlay;
if (entityWithContextOverlay) {
ContextOverlay.destroyContextOverlay(entityWithContextOverlay);
farGrabModule.entityWithContextOverlay = false;
}
}
};
2017-08-25 14:20:31 -07:00
this.isReady = function (controllerData) {
this.target = null;
2017-08-25 17:40:30 -07:00
var intersection = controllerData.rayPicks[this.hand];
if (intersection.type === RayPick.INTERSECTED_OVERLAY) {
2017-08-25 14:20:31 -07:00
if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE && !this.getOtherModule().active) {
this.target = intersection.objectID;
2017-08-25 14:20:31 -07:00
this.active = true;
return makeRunningValues(true, [], []);
} else {
this.deleteContextOverlay();
2017-08-25 14:20:31 -07:00
}
}
this.reset();
return makeRunningValues(false, [], []);
};
2017-08-24 17:42:27 -07:00
2017-08-25 14:20:31 -07:00
this.run = function (controllerData, deltaTime) {
if (this.shouldExit(controllerData)) {
this.exitModule();
2017-08-23 17:32:41 -07:00
return makeRunningValues(false, [], []);
}
2017-08-24 17:42:27 -07:00
if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) {
this.deleteContextOverlay();
}
2017-08-25 17:40:30 -07:00
this.updateLaserTargets(controllerData);
2017-08-24 17:42:27 -07:00
this.processControllerTriggers(controllerData);
2017-08-23 17:32:41 -07:00
this.updateLaserPointer(controllerData);
2017-08-24 17:42:27 -07:00
if (!this.previousLaserClickedTarget && this.laserPressingTarget) {
this.laserPressEnter();
2017-08-23 17:32:41 -07:00
}
2017-08-24 17:42:27 -07:00
if (this.previousLaserClickedTarget && !this.laserPressingTarget) {
this.laserPressExit();
2017-08-23 17:32:41 -07:00
}
2017-08-24 17:42:27 -07:00
this.previousLaserClickedTarget = this.laserPressingTarget;
2017-08-23 17:32:41 -07:00
2017-08-24 17:42:27 -07:00
if (this.laserPressingTarget) {
this.laserPressing(controllerData, deltaTime);
}
2017-08-25 14:20:31 -07:00
2017-08-24 17:42:27 -07:00
if (this.hover) {
this.hovering();
}
2017-08-23 17:32:41 -07:00
return makeRunningValues(true, [], []);
};
this.cleanup = function () {
LaserPointers.disableLaserPointer(this.laserPointer);
LaserPointers.removeLaserPointer(this.laserPointer);
};
this.halfEnd = halfEnd;
this.fullEnd = fullEnd;
this.laserPointer = LaserPointers.createLaserPointer({
2017-08-31 18:06:55 -07:00
joint: (this.hand === RIGHT_HAND) ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND",
2017-08-23 17:32:41 -07:00
filter: RayPick.PICK_OVERLAYS,
maxDistance: PICK_MAX_DISTANCE,
posOffset: getGrabPointSphereOffset(this.handToController(), true),
2017-08-23 17:32:41 -07:00
renderStates: renderStates,
faceAvatar: true,
defaultRenderStates: defaultRenderStates
});
2017-08-24 17:42:27 -07:00
LaserPointers.setIgnoreOverlays(this.laserPointer, [HMD.tabletID]);
2017-08-31 18:06:55 -07:00
}
2017-08-25 14:20:31 -07:00
var leftOverlayLaserInput = new OverlayLaserInput(LEFT_HAND);
var rightOverlayLaserInput = new OverlayLaserInput(RIGHT_HAND);
2017-08-23 17:32:41 -07:00
enableDispatcherModule("LeftOverlayLaserInput", leftOverlayLaserInput);
enableDispatcherModule("RightOverlayLaserInput", rightOverlayLaserInput);
2017-08-23 17:32:41 -07:00
this.cleanup = function () {
leftOverlayLaserInput.cleanup();
rightOverlayLaserInput.cleanup();
disableDispatcherModule("LeftOverlayLaserInput");
disableDispatcherModule("RightOverlayLaserInput");
2017-08-23 17:32:41 -07:00
};
Script.scriptEnding.connect(this.cleanup);
}());