mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:24:03 +02:00
removing more laserPointers
This commit is contained in:
parent
a3f002ac11
commit
30332c3d00
6 changed files with 22 additions and 962 deletions
|
@ -249,8 +249,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
|||
this.setIgnoreTablet = function() {
|
||||
if (HMD.tabletID !== this.tabletID) {
|
||||
this.tabletID = HMD.tabletID;
|
||||
RayPick.setIgnoreItems(_this.leftControllerRayPick, _this.blacklist.concat([HMD.tabletID]));
|
||||
RayPick.setIgnoreItems(_this.rightControllerRayPick, _this.blacklist.concat([HMD.tabletID]));
|
||||
Pointers.setIgnoreItems(_this.leftControllerPointer, _this.blacklist.concat([HMD.tabletID]));
|
||||
Pointers.setIgnoreItems(_this.rightControllerPointer, _this.blacklist.concat([HMD.tabletID]));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -534,7 +534,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
|||
filter: Picks.PICK_OVERLAYS | Picks.PICK_ENTITIES,
|
||||
renderStates: renderStates,
|
||||
defaultRenderStates: defaultRenderStates,
|
||||
triggers: [{action: Controller.Standard.RTClick, button: "Focus"}, {action: Controller.Standard.RTClick, button: "Primary"}],
|
||||
triggers: [{action: Controller.Standard.LTClick, button: "Focus"}, {action: Controller.Standard.LTClick, button: "Primary"}],
|
||||
posOffset: getGrabPointSphereOffset(Controller.Standard.LeftHand, true),
|
||||
hover: true
|
||||
});
|
||||
this.leftControllerHudRayPick = RayPick.createRayPick({
|
||||
|
@ -550,6 +551,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
|||
renderStates: renderStates,
|
||||
defaultRenderStates: defaultRenderStates,
|
||||
triggers: [{action: Controller.Standard.RTClick, button: "Focus"}, {action: Controller.Standard.RTClick, button: "Primary"}],
|
||||
posOffset: getGrabPointSphereOffset(Controller.Standard.RightHand, true),
|
||||
hover: true
|
||||
});
|
||||
this.rightControllerHudRayPick = RayPick.createRayPick({
|
||||
|
|
|
@ -380,7 +380,6 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
// where it could near-grab something, stop searching.
|
||||
for (var j = 0; j < nearGrabReadiness.length; j++) {
|
||||
if (nearGrabReadiness[j].active) {
|
||||
this.laserPointerOff();
|
||||
this.endNearGrabAction();
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
|
|
|
@ -16,77 +16,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
|||
Script.include("/~/system/libraries/controllers.js");
|
||||
|
||||
(function() {
|
||||
var SEARCH_SPHERE_SIZE = 0.0132;
|
||||
var dim = {x: SEARCH_SPHERE_SIZE, y: SEARCH_SPHERE_SIZE, z: SEARCH_SPHERE_SIZE};
|
||||
var halfPath = {
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
var halfEnd = {
|
||||
type: "sphere",
|
||||
dimensions: dim,
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
var fullEnd = {
|
||||
type: "sphere",
|
||||
dimensions: dim,
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
|
||||
var renderStates = [
|
||||
{name: "half", path: halfPath, end: halfEnd},
|
||||
{name: "full", path: fullPath, end: fullEnd},
|
||||
{name: "hold", path: holdPath}
|
||||
];
|
||||
|
||||
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}
|
||||
];
|
||||
|
||||
function entityWantsNearTrigger(props) {
|
||||
var grabbableData = getGrabbableData(props);
|
||||
return grabbableData.triggerable || grabbableData.wantsTrigger;
|
||||
|
@ -104,27 +33,8 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
520,
|
||||
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
|
||||
[],
|
||||
100);
|
||||
|
||||
this.handToController = function() {
|
||||
return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
};
|
||||
|
||||
this.updateLaserPointer = function(controllerData) {
|
||||
var mode = "none";
|
||||
if (controllerData.triggerClicks[this.hand]) {
|
||||
mode = "full";
|
||||
} else {
|
||||
mode = "half";
|
||||
}
|
||||
|
||||
LaserPointers.enableLaserPointer(this.laserPointer);
|
||||
LaserPointers.setRenderState(this.laserPointer, mode);
|
||||
};
|
||||
|
||||
this.laserPointerOff = function() {
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
};
|
||||
100,
|
||||
this.hand);
|
||||
|
||||
this.getTargetProps = function (controllerData) {
|
||||
// nearbyEntityProperties is already sorted by length from controller
|
||||
|
@ -151,7 +61,6 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
this.endFarTrigger = function (controllerData) {
|
||||
var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
|
||||
Entities.callEntityMethod(this.targetEntityID, "stopFarTrigger", args);
|
||||
this.laserPointerOff();
|
||||
};
|
||||
|
||||
this.isReady = function (controllerData) {
|
||||
|
@ -176,31 +85,9 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
this.endFarTrigger(controllerData);
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
|
||||
this.updateLaserPointer(controllerData);
|
||||
this.continueFarTrigger(controllerData);
|
||||
return makeRunningValues(true, [this.targetEntityID], []);
|
||||
};
|
||||
|
||||
this.laserPointer = LaserPointers.createLaserPointer({
|
||||
joint: (this.hand === RIGHT_HAND) ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND",
|
||||
filter: Picks.PICK_ENTITIES | Picks.PICK_OVERLAYS,
|
||||
maxDistance: PICK_MAX_DISTANCE,
|
||||
posOffset: getGrabPointSphereOffset(this.handToController(), true),
|
||||
renderStates: renderStates,
|
||||
faceAvatar: true,
|
||||
distanceScaleEnd: true,
|
||||
defaultRenderStates: defaultRenderStates
|
||||
});
|
||||
|
||||
this.cleanup = function () {
|
||||
if (this.targetEntityID) {
|
||||
this.endFarTrigger();
|
||||
}
|
||||
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
LaserPointers.removeLaserPointer(this.laserPointer);
|
||||
};
|
||||
}
|
||||
|
||||
var leftFarTriggerEntity = new FarTriggerEntity(LEFT_HAND);
|
||||
|
@ -209,11 +96,9 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
enableDispatcherModule("LeftFarTriggerEntity", leftFarTriggerEntity);
|
||||
enableDispatcherModule("RightFarTriggerEntity", rightFarTriggerEntity);
|
||||
|
||||
this.cleanup = function () {
|
||||
leftFarTriggerEntity.cleanup();
|
||||
rightFarTriggerEntity.cleanup();
|
||||
function cleanup() {
|
||||
disableDispatcherModule("LeftFarTriggerEntity");
|
||||
disableDispatcherModule("RightFarTriggerEntity");
|
||||
};
|
||||
Script.scriptEnding.connect(this.cleanup);
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
}());
|
||||
|
|
|
@ -18,81 +18,9 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
Script.include("/~/system/libraries/utils.js");
|
||||
|
||||
(function () {
|
||||
var END_RADIUS = 0.005;
|
||||
var dim = { x: END_RADIUS, y: END_RADIUS, z: END_RADIUS };
|
||||
var halfPath = {
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
var halfEnd = {
|
||||
type: "sphere",
|
||||
dimensions: dim,
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
var fullEnd = {
|
||||
type: "sphere",
|
||||
dimensions: dim,
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
|
||||
var renderStates = [
|
||||
{name: "half", path: halfPath, end: halfEnd},
|
||||
{name: "full", path: fullPath, end: fullEnd},
|
||||
{name: "hold", path: holdPath}
|
||||
];
|
||||
|
||||
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}
|
||||
];
|
||||
|
||||
function InEditMode(hand) {
|
||||
this.hand = hand;
|
||||
this.triggerClicked = false;
|
||||
this.mode = "none";
|
||||
|
||||
this.parameters = makeDispatcherModuleParameters(
|
||||
160,
|
||||
|
@ -113,29 +41,6 @@ Script.include("/~/system/libraries/utils.js");
|
|||
return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
};
|
||||
|
||||
|
||||
this.processControllerTriggers = function(controllerData) {
|
||||
if (controllerData.triggerClicks[this.hand]) {
|
||||
this.mode = "full";
|
||||
} else if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
|
||||
this.mode = "half";
|
||||
} else {
|
||||
this.mode = "none";
|
||||
}
|
||||
};
|
||||
|
||||
this.updateLaserPointer = function(controllerData) {
|
||||
LaserPointers.enableLaserPointer(this.laserPointer);
|
||||
LaserPointers.setRenderState(this.laserPointer, this.mode);
|
||||
|
||||
if (HMD.tabletID !== this.tabletID || HMD.tabletButtonID !== this.tabletButtonID || HMD.tabletScreenID !== this.tabletScreenID) {
|
||||
this.tabletID = HMD.tabletID;
|
||||
this.tabletButtonID = HMD.tabletButtonID;
|
||||
this.tabletScreenID = HMD.tabletScreenID;
|
||||
LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID, HMD.tabletButtonID, HMD.tabletScreenID]);
|
||||
}
|
||||
};
|
||||
|
||||
this.pointingAtTablet = function(objectID) {
|
||||
if (objectID === HMD.tabletScreenID || objectID === HMD.tabletButtonID) {
|
||||
return true;
|
||||
|
@ -164,21 +69,12 @@ Script.include("/~/system/libraries/utils.js");
|
|||
}
|
||||
};
|
||||
|
||||
this.exitModule = function() {
|
||||
this.disableLasers();
|
||||
return makeRunningValues(false, [], []);
|
||||
};
|
||||
|
||||
this.disableLasers = function() {
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
};
|
||||
|
||||
this.isReady = function(controllerData) {
|
||||
if (isInEditMode()) {
|
||||
this.triggerClicked = false;
|
||||
return makeRunningValues(true, [], []);
|
||||
}
|
||||
return this.exitModule();
|
||||
return makeRunningValues(false, [], []);
|
||||
};
|
||||
|
||||
this.run = function(controllerData) {
|
||||
|
@ -216,31 +112,9 @@ Script.include("/~/system/libraries/utils.js");
|
|||
return this.exitModule();
|
||||
}
|
||||
}
|
||||
|
||||
this.processControllerTriggers(controllerData);
|
||||
this.updateLaserPointer(controllerData);
|
||||
this.sendPickData(controllerData);
|
||||
|
||||
|
||||
return this.isReady(controllerData);
|
||||
};
|
||||
|
||||
this.cleanup = function() {
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
LaserPointers.removeLaserPointer(this.laserPointer);
|
||||
};
|
||||
|
||||
this.laserPointer = LaserPointers.createLaserPointer({
|
||||
joint: (this.hand === RIGHT_HAND) ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND",
|
||||
filter: Picks.PICK_ENTITIES | Picks.PICK_OVERLAYS,
|
||||
maxDistance: PICK_MAX_DISTANCE,
|
||||
posOffset: getGrabPointSphereOffset(this.handToController(), true),
|
||||
renderStates: renderStates,
|
||||
faceAvatar: true,
|
||||
defaultRenderStates: defaultRenderStates
|
||||
});
|
||||
|
||||
LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID, HMD.tabletButtonID, HMD.tabletScreenID]);
|
||||
}
|
||||
|
||||
var leftHandInEditMode = new InEditMode(LEFT_HAND);
|
||||
|
@ -249,12 +123,12 @@ Script.include("/~/system/libraries/utils.js");
|
|||
enableDispatcherModule("LeftHandInEditMode", leftHandInEditMode);
|
||||
enableDispatcherModule("RightHandInEditMode", rightHandInEditMode);
|
||||
|
||||
this.cleanup = function() {
|
||||
function cleanup() {
|
||||
leftHandInEditMode.cleanup();
|
||||
rightHandInEditMode.cleanup();
|
||||
disableDispatcherModule("LeftHandInEditMode");
|
||||
disableDispatcherModule("RightHandInEditMode");
|
||||
};
|
||||
|
||||
Script.scriptEnding.connect(this.cleanup);
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
}());
|
||||
|
|
|
@ -9,268 +9,27 @@
|
|||
makeRunningValues, Messages, Quat, Vec3, makeDispatcherModuleParameters, Overlays, ZERO_VEC, 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
|
||||
TRIGGER_OFF_VALUE, getEnabledModuleByName, PICK_MAX_DISTANCE, LaserPointers, RayPick, ContextOverlay, Picks
|
||||
*/
|
||||
|
||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
Script.include("/~/system/libraries/controllers.js");
|
||||
|
||||
(function() {
|
||||
var TouchEventUtils = Script.require("/~/system/libraries/touchEventUtils.js");
|
||||
var END_RADIUS = 0.005;
|
||||
var dim = { x: END_RADIUS, y: END_RADIUS, z: END_RADIUS };
|
||||
var halfPath = {
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
var halfEnd = {
|
||||
type: "sphere",
|
||||
dimensions: dim,
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
var fullEnd = {
|
||||
type: "sphere",
|
||||
dimensions: dim,
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
|
||||
var renderStates = [
|
||||
{name: "half", path: halfPath, end: halfEnd},
|
||||
{name: "full", path: fullPath, end: fullEnd},
|
||||
{name: "hold", path: holdPath}
|
||||
];
|
||||
|
||||
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}
|
||||
];
|
||||
|
||||
|
||||
// triggered when stylus presses a web overlay/entity
|
||||
var HAPTIC_STYLUS_STRENGTH = 1.0;
|
||||
var HAPTIC_STYLUS_DURATION = 20.0;
|
||||
|
||||
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) {
|
||||
this.hand = hand;
|
||||
this.active = false;
|
||||
this.previousLaserClickedTarget = false;
|
||||
this.laserPressingTarget = false;
|
||||
this.mode = "none";
|
||||
this.laserTarget = null;
|
||||
this.pressEnterLaserTarget = null;
|
||||
|
||||
|
||||
this.parameters = makeDispatcherModuleParameters(
|
||||
120,
|
||||
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
|
||||
[],
|
||||
100);
|
||||
|
||||
this.getOtherHandController = function() {
|
||||
return (this.hand === RIGHT_HAND) ? Controller.Standard.LeftHand : Controller.Standard.RightHand;
|
||||
};
|
||||
|
||||
this.getOtherModule = function() {
|
||||
return (this.hand === RIGHT_HAND) ? leftOverlayLaserInput : rightOverlayLaserInput;
|
||||
};
|
||||
|
||||
this.handToController = function() {
|
||||
return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
};
|
||||
|
||||
this.hasTouchFocus = function(laserTarget) {
|
||||
return (laserTarget.overlayID === this.hoverOverlay);
|
||||
};
|
||||
|
||||
this.requestTouchFocus = function(laserTarget) {
|
||||
if (laserTarget.overlayID &&
|
||||
laserTarget.overlayID !== this.hoverOverlay) {
|
||||
this.hoverOverlay = laserTarget.overlayID;
|
||||
TouchEventUtils.sendHoverEnterEventToTouchTarget(this.hand, laserTarget);
|
||||
}
|
||||
};
|
||||
|
||||
this.relinquishTouchFocus = function() {
|
||||
// send hover leave event.
|
||||
if (this.hoverOverlay) {
|
||||
var pointerEvent = { type: "Move", id: this.hand + 1 };
|
||||
Overlays.sendMouseMoveOnOverlay(this.hoverOverlay, pointerEvent);
|
||||
Overlays.sendHoverOverOverlay(this.hoverOverlay, pointerEvent);
|
||||
Overlays.sendHoverLeaveOverlay(this.hoverOverlay, pointerEvent);
|
||||
this.hoverOverlay = null;
|
||||
}
|
||||
};
|
||||
|
||||
this.relinquishStylusTargetTouchFocus = function(laserTarget) {
|
||||
var stylusModuleNames = ["LeftTabletStylusInput", "RightTabletStylusError"];
|
||||
for (var i = 0; i < stylusModuleNames.length; i++) {
|
||||
var stylusModule = getEnabledModuleByName(stylusModuleNames[i]);
|
||||
if (stylusModule) {
|
||||
if (stylusModule.hoverOverlay === laserTarget.overlayID) {
|
||||
stylusModule.relinquishTouchFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.stealTouchFocus = function(laserTarget) {
|
||||
if (laserTarget.overlayID === this.getOtherModule().hoverOverlay) {
|
||||
this.getOtherModule().relinquishTouchFocus();
|
||||
}
|
||||
|
||||
// If the focus target we want to request is the same of one of the stylus
|
||||
// tell the stylus to relinquish it focus on our target
|
||||
this.relinquishStylusTargetTouchFocus(laserTarget);
|
||||
|
||||
this.requestTouchFocus(laserTarget);
|
||||
};
|
||||
|
||||
this.updateLaserPointer = function(controllerData) {
|
||||
LaserPointers.enableLaserPointer(this.laserPointer);
|
||||
LaserPointers.setRenderState(this.laserPointer, this.mode);
|
||||
|
||||
if (HMD.tabletID !== this.tabletID) {
|
||||
this.tabletID = HMD.tabletID;
|
||||
LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID]);
|
||||
}
|
||||
};
|
||||
|
||||
this.processControllerTriggers = function(controllerData) {
|
||||
if (controllerData.triggerClicks[this.hand]) {
|
||||
this.mode = "full";
|
||||
} else if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
|
||||
this.mode = "half";
|
||||
} else {
|
||||
this.mode = "none";
|
||||
}
|
||||
};
|
||||
|
||||
this.laserPressEnter = function () {
|
||||
this.stealTouchFocus(this.laserTarget);
|
||||
TouchEventUtils.sendTouchStartEventToTouchTarget(this.hand, this.laserTarget);
|
||||
Controller.triggerHapticPulse(HAPTIC_STYLUS_STRENGTH, HAPTIC_STYLUS_DURATION, this.hand);
|
||||
|
||||
this.touchingEnterTimer = 0;
|
||||
this.pressEnterLaserTarget = this.laserTarget;
|
||||
this.deadspotExpired = false;
|
||||
|
||||
var LASER_PRESS_TO_MOVE_DEADSPOT = 0.094;
|
||||
this.deadspotRadius = Math.tan(LASER_PRESS_TO_MOVE_DEADSPOT) * this.laserTarget.distance;
|
||||
};
|
||||
|
||||
this.laserPressExit = function () {
|
||||
if (this.laserTarget === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// special case to handle home button.
|
||||
if (this.laserTarget.overlayID === HMD.homeButtonID) {
|
||||
Messages.sendLocalMessage("home", this.laserTarget.overlayID);
|
||||
}
|
||||
|
||||
// send press event
|
||||
if (this.deadspotExpired) {
|
||||
TouchEventUtils.sendTouchEndEventToTouchTarget(this.hand, this.laserTarget);
|
||||
} else {
|
||||
TouchEventUtils.sendTouchEndEventToTouchTarget(this.hand, this.pressEnterLaserTarget);
|
||||
}
|
||||
};
|
||||
|
||||
this.laserPressing = function (controllerData, dt) {
|
||||
this.touchingEnterTimer += dt;
|
||||
|
||||
if (this.laserTarget) {
|
||||
if (controllerData.triggerClicks[this.hand]) {
|
||||
var POINTER_PRESS_TO_MOVE_DELAY = 0.33; // seconds
|
||||
if (this.deadspotExpired || this.touchingEnterTimer > POINTER_PRESS_TO_MOVE_DELAY ||
|
||||
distance2D(this.laserTarget.position2D,
|
||||
this.pressEnterLaserTarget.position2D) > this.deadspotRadius) {
|
||||
TouchEventUtils.sendTouchMoveEventToTouchTarget(this.hand, this.laserTarget);
|
||||
this.deadspotExpired = true;
|
||||
}
|
||||
} else {
|
||||
this.laserPressingTarget = false;
|
||||
}
|
||||
} else {
|
||||
this.laserPressingTarget = false;
|
||||
}
|
||||
};
|
||||
100,
|
||||
this.hand);
|
||||
|
||||
this.processLaser = function(controllerData) {
|
||||
if (this.shouldExit(controllerData) || this.getOtherModule().active) {
|
||||
this.exitModule();
|
||||
if (this.shouldExit(controllerData)) {
|
||||
return false;
|
||||
}
|
||||
var intersection = controllerData.rayPicks[this.hand];
|
||||
var laserTarget = TouchEventUtils.composeTouchTargetFromIntersection(intersection);
|
||||
|
||||
if (controllerData.triggerClicks[this.hand]) {
|
||||
this.laserTarget = laserTarget;
|
||||
this.laserPressingTarget = true;
|
||||
} else {
|
||||
this.requestTouchFocus(laserTarget);
|
||||
|
||||
if (!TouchEventUtils.touchTargetHasKeyboardFocus(laserTarget)) {
|
||||
TouchEventUtils.setKeyboardFocusOnTouchTarget(laserTarget);
|
||||
}
|
||||
|
||||
if (this.hasTouchFocus(laserTarget) && !this.laserPressingTarget) {
|
||||
TouchEventUtils.sendHoverOverEventToTouchTarget(this.hand, laserTarget);
|
||||
}
|
||||
}
|
||||
|
||||
this.processControllerTriggers(controllerData);
|
||||
this.updateLaserPointer(controllerData);
|
||||
this.active = true;
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -303,23 +62,6 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
return offOverlay || grabbingOverlay || triggerOff;
|
||||
};
|
||||
|
||||
this.exitModule = function() {
|
||||
if (this.laserPressingTarget) {
|
||||
this.deadspotExpired = true;
|
||||
this.laserPressExit();
|
||||
this.laserPressingTarget = false;
|
||||
}
|
||||
this.relinquishTouchFocus();
|
||||
this.reset();
|
||||
this.updateLaserPointer();
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
};
|
||||
|
||||
this.reset = function() {
|
||||
this.mode = "none";
|
||||
this.active = false;
|
||||
};
|
||||
|
||||
this.deleteContextOverlay = function() {
|
||||
var farGrabModule = getEnabledModuleByName(this.hand === RIGHT_HAND ? "RightFarActionGrabEntity" : "LeftFarActionGrabEntity");
|
||||
if (farGrabModule) {
|
||||
|
@ -340,41 +82,8 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
};
|
||||
|
||||
this.run = function (controllerData, deltaTime) {
|
||||
if (!this.previousLaserClickedTarget && this.laserPressingTarget) {
|
||||
this.laserPressEnter();
|
||||
}
|
||||
if (this.previousLaserClickedTarget && !this.laserPressingTarget) {
|
||||
this.laserPressExit();
|
||||
}
|
||||
this.previousLaserClickedTarget = this.laserPressingTarget;
|
||||
|
||||
if (this.laserPressingTarget) {
|
||||
this.laserPressing(controllerData, deltaTime);
|
||||
}
|
||||
|
||||
if (this.processLaser(controllerData)) {
|
||||
return makeRunningValues(true, [], []);
|
||||
} else {
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
return this.isReady(controllerData);
|
||||
};
|
||||
|
||||
this.cleanup = function () {
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
LaserPointers.removeLaserPointer(this.laserPointer);
|
||||
};
|
||||
|
||||
this.laserPointer = LaserPointers.createLaserPointer({
|
||||
joint: (this.hand === RIGHT_HAND) ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND",
|
||||
filter: Picks.PICK_OVERLAYS,
|
||||
maxDistance: PICK_MAX_DISTANCE,
|
||||
posOffset: getGrabPointSphereOffset(this.handToController(), true),
|
||||
renderStates: renderStates,
|
||||
faceAvatar: true,
|
||||
defaultRenderStates: defaultRenderStates
|
||||
});
|
||||
|
||||
LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID]);
|
||||
}
|
||||
|
||||
var leftOverlayLaserInput = new OverlayLaserInput(LEFT_HAND);
|
||||
|
@ -383,11 +92,9 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
enableDispatcherModule("LeftOverlayLaserInput", leftOverlayLaserInput);
|
||||
enableDispatcherModule("RightOverlayLaserInput", rightOverlayLaserInput);
|
||||
|
||||
this.cleanup = function () {
|
||||
leftOverlayLaserInput.cleanup();
|
||||
rightOverlayLaserInput.cleanup();
|
||||
function cleanup() {
|
||||
disableDispatcherModule("LeftOverlayLaserInput");
|
||||
disableDispatcherModule("RightOverlayLaserInput");
|
||||
};
|
||||
Script.scriptEnding.connect(this.cleanup);
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
}());
|
||||
|
|
|
@ -10,370 +10,21 @@
|
|||
/* global Script, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND, Vec3, Quat, getGrabPointSphereOffset,
|
||||
makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, makeDispatcherModuleParameters,
|
||||
PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD,
|
||||
DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, ZERO_VEC, Overlays
|
||||
DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, ZERO_VEC, Overlays, Picks
|
||||
*/
|
||||
|
||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
Script.include("/~/system/libraries/controllers.js");
|
||||
|
||||
(function() {
|
||||
var END_RADIUS = 0.005;
|
||||
var dim = { x: END_RADIUS, y: END_RADIUS, z: END_RADIUS };
|
||||
var halfPath = {
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
var halfEnd = {
|
||||
type: "sphere",
|
||||
dimensions: dim,
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
var fullEnd = {
|
||||
type: "sphere",
|
||||
dimensions: dim,
|
||||
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: MyAvatar.SELF_ID
|
||||
};
|
||||
|
||||
var renderStates = [
|
||||
{name: "half", path: halfPath, end: halfEnd},
|
||||
{name: "full", path: fullPath, end: fullEnd},
|
||||
{name: "hold", path: holdPath}
|
||||
];
|
||||
|
||||
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}
|
||||
];
|
||||
|
||||
|
||||
// triggered when stylus presses a web overlay/entity
|
||||
var HAPTIC_STYLUS_STRENGTH = 1.0;
|
||||
var HAPTIC_STYLUS_DURATION = 20.0;
|
||||
|
||||
function laserTargetHasKeyboardFocus(laserTarget) {
|
||||
if (laserTarget && laserTarget !== Uuid.NULL) {
|
||||
return Entities.keyboardFocusOverlay === laserTarget;
|
||||
}
|
||||
}
|
||||
|
||||
function setKeyboardFocusOnLaserTarget(laserTarget) {
|
||||
if (laserTarget && laserTarget !== Uuid.NULL) {
|
||||
Entities.wantsHandControllerPointerEvents(laserTarget);
|
||||
Overlays.keyboardFocusOverlay = Uuid.NULL;
|
||||
Entities.keyboardFocusEntity = laserTarget;
|
||||
}
|
||||
}
|
||||
|
||||
function sendHoverEnterEventToLaserTarget(hand, laserTarget) {
|
||||
if (!laserTarget) {
|
||||
return;
|
||||
}
|
||||
var pointerEvent = {
|
||||
type: "Move",
|
||||
id: hand + 1, // 0 is reserved for hardware mouse
|
||||
pos2D: laserTarget.position2D,
|
||||
pos3D: laserTarget.position,
|
||||
normal: laserTarget.normal,
|
||||
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
|
||||
button: "None"
|
||||
};
|
||||
|
||||
if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) {
|
||||
Entities.sendHoverEnterEntity(laserTarget.entityID, pointerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
function sendHoverOverEventToLaserTarget(hand, laserTarget) {
|
||||
|
||||
if (!laserTarget) {
|
||||
return;
|
||||
}
|
||||
var pointerEvent = {
|
||||
type: "Move",
|
||||
id: hand + 1, // 0 is reserved for hardware mouse
|
||||
pos2D: laserTarget.position2D,
|
||||
pos3D: laserTarget.position,
|
||||
normal: laserTarget.normal,
|
||||
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
|
||||
button: "None"
|
||||
};
|
||||
|
||||
if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) {
|
||||
Entities.sendMouseMoveOnEntity(laserTarget.entityID, pointerEvent);
|
||||
Entities.sendHoverOverEntity(laserTarget.entityID, pointerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function sendTouchStartEventToLaserTarget(hand, laserTarget) {
|
||||
var pointerEvent = {
|
||||
type: "Press",
|
||||
id: hand + 1, // 0 is reserved for hardware mouse
|
||||
pos2D: laserTarget.position2D,
|
||||
pos3D: laserTarget.position,
|
||||
normal: laserTarget.normal,
|
||||
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
|
||||
button: "Primary",
|
||||
isPrimaryHeld: true
|
||||
};
|
||||
|
||||
if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) {
|
||||
Entities.sendMousePressOnEntity(laserTarget.entityID, pointerEvent);
|
||||
Entities.sendClickDownOnEntity(laserTarget.entityID, pointerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
function sendTouchEndEventToLaserTarget(hand, laserTarget) {
|
||||
var pointerEvent = {
|
||||
type: "Release",
|
||||
id: hand + 1, // 0 is reserved for hardware mouse
|
||||
pos2D: laserTarget.position2D,
|
||||
pos3D: laserTarget.position,
|
||||
normal: laserTarget.normal,
|
||||
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
|
||||
button: "Primary"
|
||||
};
|
||||
|
||||
if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) {
|
||||
Entities.sendMouseReleaseOnEntity(laserTarget.entityID, pointerEvent);
|
||||
Entities.sendClickReleaseOnEntity(laserTarget.entityID, pointerEvent);
|
||||
Entities.sendHoverLeaveEntity(laserTarget.entityID, pointerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
function sendTouchMoveEventToLaserTarget(hand, laserTarget) {
|
||||
var pointerEvent = {
|
||||
type: "Move",
|
||||
id: hand + 1, // 0 is reserved for hardware mouse
|
||||
pos2D: laserTarget.position2D,
|
||||
pos3D: laserTarget.position,
|
||||
normal: laserTarget.normal,
|
||||
direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
|
||||
button: "Primary",
|
||||
isPrimaryHeld: true
|
||||
};
|
||||
|
||||
if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) {
|
||||
Entities.sendMouseMoveOnEntity(laserTarget.entityID, pointerEvent);
|
||||
Entities.sendHoldingClickOnEntity(laserTarget.entityID, pointerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
function calculateTargetFromEntity(intersection, props) {
|
||||
if (props.rotation === undefined) {
|
||||
// if rotation is missing from props object, then this entity has probably been deleted.
|
||||
return null;
|
||||
}
|
||||
|
||||
// project stylus tip onto entity plane.
|
||||
var normal = Vec3.multiplyQbyV(props.rotation, {x: 0, y: 0, z: 1});
|
||||
Vec3.multiplyQbyV(props.rotation, {x: 0, y: 1, z: 0});
|
||||
var distance = Vec3.dot(Vec3.subtract(intersection, props.position), normal);
|
||||
var position = Vec3.subtract(intersection, Vec3.multiply(normal, distance));
|
||||
|
||||
// generate normalized coordinates
|
||||
var invRot = Quat.inverse(props.rotation);
|
||||
var localPos = Vec3.multiplyQbyV(invRot, Vec3.subtract(position, props.position));
|
||||
var invDimensions = { x: 1 / props.dimensions.x, y: 1 / props.dimensions.y, z: 1 / props.dimensions.z };
|
||||
var normalizedPosition = Vec3.sum(Vec3.multiplyVbyV(localPos, invDimensions), props.registrationPoint);
|
||||
|
||||
// 2D position on entity plane in meters, relative to the bounding box upper-left hand corner.
|
||||
var position2D = {
|
||||
x: normalizedPosition.x * props.dimensions.x,
|
||||
y: (1 - normalizedPosition.y) * props.dimensions.y // flip y-axis
|
||||
};
|
||||
|
||||
return {
|
||||
entityID: props.id,
|
||||
entityProps: props,
|
||||
overlayID: null,
|
||||
distance: distance,
|
||||
position: position,
|
||||
position2D: position2D,
|
||||
normal: normal,
|
||||
normalizedPosition: normalizedPosition,
|
||||
dimensions: props.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 WebEntityLaserInput(hand) {
|
||||
this.hand = hand;
|
||||
this.active = false;
|
||||
this.previousLaserClickedTarget = false;
|
||||
this.laserPressingTarget = false;
|
||||
this.hover = false;
|
||||
this.mode = "none";
|
||||
this.pressEnterLaserTarget = null;
|
||||
this.laserTarget = null;
|
||||
this.laserTargetID = null;
|
||||
this.lastValidTargetID = null;
|
||||
|
||||
this.handToController = function() {
|
||||
return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
};
|
||||
|
||||
this.getOtherModule = function() {
|
||||
return (this.hand === RIGHT_HAND) ? leftWebEntityLaserInput : rightWebEntityLaserInput;
|
||||
};
|
||||
|
||||
this.parameters = makeDispatcherModuleParameters(
|
||||
550,
|
||||
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
|
||||
[],
|
||||
100);
|
||||
|
||||
this.requestTouchFocus = function(laserTarget) {
|
||||
if (laserTarget !== null || laserTarget !== undefined) {
|
||||
sendHoverEnterEventToLaserTarget(this.hand, this.laserTarget);
|
||||
this.lastValidTargetID = laserTarget;
|
||||
}
|
||||
};
|
||||
|
||||
this.relinquishTouchFocus = function() {
|
||||
// send hover leave event.
|
||||
var pointerEvent = { type: "Move", id: this.hand + 1 };
|
||||
Entities.sendMouseMoveOnEntity(this.lastValidTargetID, pointerEvent);
|
||||
Entities.sendHoverOverEntity(this.lastValidTargetID, pointerEvent);
|
||||
Entities.sendHoverLeaveEntity(this.lastValidID, pointerEvent);
|
||||
};
|
||||
|
||||
this.updateLaserTargets = function(controllerData) {
|
||||
var intersection = controllerData.rayPicks[this.hand];
|
||||
this.laserTargetID = intersection.objectID;
|
||||
var props = Entities.getEntityProperties(intersection.objectID);
|
||||
this.laserTarget = calculateTargetFromEntity(intersection.intersection, props);
|
||||
};
|
||||
|
||||
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;
|
||||
this.requestTouchFocus(this.laserTargetID);
|
||||
} else {
|
||||
this.mode = "none";
|
||||
this.laserPressingTarget = false;
|
||||
this.hover = false;
|
||||
this.relinquishTouchFocus();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
this.hovering = function() {
|
||||
if (!laserTargetHasKeyboardFocus(this.laserTagetID)) {
|
||||
setKeyboardFocusOnLaserTarget(this.laserTargetID);
|
||||
}
|
||||
sendHoverOverEventToLaserTarget(this.hand, this.laserTarget);
|
||||
};
|
||||
|
||||
this.laserPressEnter = function () {
|
||||
sendTouchStartEventToLaserTarget(this.hand, this.laserTarget);
|
||||
Controller.triggerHapticPulse(HAPTIC_STYLUS_STRENGTH, HAPTIC_STYLUS_DURATION, this.hand);
|
||||
|
||||
this.touchingEnterTimer = 0;
|
||||
this.pressEnterLaserTarget = this.laserTarget;
|
||||
this.deadspotExpired = false;
|
||||
|
||||
var LASER_PRESS_TO_MOVE_DEADSPOT = 0.026;
|
||||
this.deadspotRadius = Math.tan(LASER_PRESS_TO_MOVE_DEADSPOT) * this.laserTarget.distance;
|
||||
};
|
||||
|
||||
this.laserPressExit = function () {
|
||||
if (this.laserTarget === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// send press event
|
||||
if (this.deadspotExpired) {
|
||||
sendTouchEndEventToLaserTarget(this.hand, this.laserTarget);
|
||||
} else {
|
||||
sendTouchEndEventToLaserTarget(this.hand, this.pressEnterLaserTarget);
|
||||
}
|
||||
};
|
||||
|
||||
this.laserPressing = function (controllerData, dt) {
|
||||
this.touchingEnterTimer += dt;
|
||||
|
||||
if (this.laserTarget) {
|
||||
var POINTER_PRESS_TO_MOVE_DELAY = 0.33; // seconds
|
||||
if (this.deadspotExpired || this.touchingEnterTimer > POINTER_PRESS_TO_MOVE_DELAY ||
|
||||
distance2D(this.laserTarget.position2D,
|
||||
this.pressEnterLaserTarget.position2D) > this.deadspotRadius) {
|
||||
sendTouchMoveEventToLaserTarget(this.hand, this.laserTarget);
|
||||
this.deadspotExpired = true;
|
||||
}
|
||||
} else {
|
||||
this.laserPressingTarget = false;
|
||||
}
|
||||
};
|
||||
|
||||
this.releaseTouchEvent = function() {
|
||||
if (this.pressEnterLaserTarget === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendTouchEndEventToLaserTarget(this.hand, this.pressEnterLaserTarget);
|
||||
};
|
||||
|
||||
this.updateLaserPointer = function(controllerData) {
|
||||
LaserPointers.enableLaserPointer(this.laserPointer);
|
||||
LaserPointers.setRenderState(this.laserPointer, this.mode);
|
||||
};
|
||||
|
||||
this.isPointingAtWebEntity = function(controllerData) {
|
||||
var intersection = controllerData.rayPicks[this.hand];
|
||||
var entityProperty = Entities.getEntityProperties(intersection.objectID);
|
||||
|
@ -385,90 +36,32 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
return false;
|
||||
};
|
||||
|
||||
this.exitModule = function() {
|
||||
this.releaseTouchEvent();
|
||||
this.relinquishTouchFocus();
|
||||
this.reset();
|
||||
this.updateLaserPointer();
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
};
|
||||
|
||||
this.reset = function() {
|
||||
this.pressEnterLaserTarget = null;
|
||||
this.laserTarget = null;
|
||||
this.laserTargetID = null;
|
||||
this.laserPressingTarget = false;
|
||||
this.previousLaserClickedTarget = null;
|
||||
this.mode = "none";
|
||||
this.active = false;
|
||||
};
|
||||
|
||||
this.isReady = function(controllerData) {
|
||||
var otherModule = this.getOtherModule();
|
||||
if (this.isPointingAtWebEntity(controllerData) && !otherModule.active) {
|
||||
return makeRunningValues(true, [], []);
|
||||
}
|
||||
|
||||
return makeRunningValues(false, [], []);
|
||||
};
|
||||
|
||||
this.run = function(controllerData, deltaTime) {
|
||||
if (!this.isPointingAtWebEntity(controllerData)) {
|
||||
this.exitModule();
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
|
||||
this.updateLaserTargets(controllerData);
|
||||
this.processControllerTriggers(controllerData);
|
||||
this.updateLaserPointer(controllerData);
|
||||
|
||||
if (!this.previousLaserClickedTarget && this.laserPressingTarget) {
|
||||
this.laserPressEnter();
|
||||
}
|
||||
if (this.previousLaserClickedTarget && !this.laserPressingTarget) {
|
||||
this.laserPressExit();
|
||||
}
|
||||
this.previousLaserClickedTarget = this.laserPressingTarget;
|
||||
|
||||
if (this.laserPressingTarget) {
|
||||
this.laserPressing(controllerData, deltaTime);
|
||||
}
|
||||
|
||||
if (this.hover) {
|
||||
this.hovering();
|
||||
}
|
||||
return makeRunningValues(true, [], []);
|
||||
};
|
||||
|
||||
this.cleanup = function() {
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
LaserPointers.removeLaserPointer(this.laserPointer);
|
||||
};
|
||||
|
||||
this.laserPointer = LaserPointers.createLaserPointer({
|
||||
joint: (this.hand === RIGHT_HAND) ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND",
|
||||
filter: Picks.PICK_ENTITIES,
|
||||
maxDistance: PICK_MAX_DISTANCE,
|
||||
posOffset: getGrabPointSphereOffset(this.handToController(), true),
|
||||
renderStates: renderStates,
|
||||
faceAvatar: true,
|
||||
defaultRenderStates: defaultRenderStates
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var leftWebEntityLaserInput = new WebEntityLaserInput(LEFT_HAND);
|
||||
var rightWebEntityLaserInput = new WebEntityLaserInput(RIGHT_HAND);
|
||||
|
||||
enableDispatcherModule("LeftWebEntityLaserInput", leftWebEntityLaserInput);
|
||||
enableDispatcherModule("RightWebEntityLaserInput", rightWebEntityLaserInput);
|
||||
|
||||
this.cleanup = function() {
|
||||
leftWebEntityLaserInput.cleanup();
|
||||
rightWebEntityLaserInput.cleanup();
|
||||
function cleanup() {
|
||||
disableDispatcherModule("LeftWebEntityLaserInput");
|
||||
disableDispatcherModule("RightWebEntityLaserInput");
|
||||
};
|
||||
Script.scriptEnding.connect(this.cleanup);
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
|
||||
}());
|
||||
|
|
Loading…
Reference in a new issue