fix tablet grabbing and eslint changes

This commit is contained in:
druiz17 2017-09-25 14:31:13 -07:00
parent b1b31444f0
commit ec40df711d
3 changed files with 31 additions and 43 deletions

View file

@ -10,10 +10,17 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/* global Script, HMD, WebTablet, UIWebTablet, UserActivityLogger, Settings, Entities, Messages, Tablet, Overlays,
MyAvatar, Menu, AvatarInputs, Vec3 */
/* global Script, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND, Mat4, MyAvatar, Vec3, Camera, Quat,
getGrabPointSphereOffset, getEnabledModuleByName, makeRunningValues, Entities, NULL_UUID,
enableDispatcherModule, disableDispatcherModule, entityIsDistanceGrabbable,
makeDispatcherModuleParameters, MSECS_PER_SEC, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION,
PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD,
AVATAR_SELF_ID, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, ZERO_VEC, ensureDynamic,
getControllerWorldLocation, projectOntoEntityXYPlane, ContextOverlay, HMD, Reticle, Overlays, isPointingAtUI
*/
(function() {
Script.include("/~/system/libraries/controllers.js")
Script.include("/~/system/libraries/controllers.js");
var ControllerDispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
var halfPath = {
type: "line3d",
@ -82,18 +89,8 @@
{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;
var MARGIN = 25;
function distance2D(a, b) {
var dx = (a.x - b.x);
var dy = (a.y - b.y);
return Math.sqrt(dx * dx + dy * dy);
}
function HudOverlayPointer(hand) {
var _this = this;
this.hand = hand;
@ -118,15 +115,11 @@
return _this.triggerClicked;
};
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.updateRecommendedArea = function() {
this.updateRecommendedArea = function() {
var dims = Controller.getViewportDimensions();
this.reticleMaxX = dims.x - MARGIN;
this.reticleMaxY = dims.y - MARGIN;
@ -159,7 +152,7 @@
}
};
this.calculateNewReticlePosition = function(intersection) {
this.calculateNewReticlePosition = function(intersection) {
this.updateRecommendedArea();
var point2d = HMD.overlayFromWorldPoint(intersection);
point2d.x = Math.max(this.reticleMinX, Math.min(point2d.x, this.reticleMaxX));
@ -176,14 +169,6 @@
return (rayPick.objectID === HMD.tabletScreenID || rayPick.objectID === HMD.homeButtonID);
};
this.moveMouseAwayFromTablet = function() {
if (!this.movedAway) {
var point = {x: 25, y: 25};
// this.setReticlePosition(point);
this.movedAway = true;
}
}
this.processLaser = function(controllerData) {
var controllerLocation = controllerData.controllerLocations[this.hand];
if ((controllerData.triggerValues[this.hand] < ControllerDispatcherUtils.TRIGGER_ON_VALUE || !controllerLocation.valid) ||
@ -192,7 +177,6 @@
return false;
}
var hudRayPick = controllerData.hudRayPicks[this.hand];
var controllerLocation = controllerData.controllerLocations[this.hand];
var point2d = this.calculateNewReticlePosition(hudRayPick.intersection);
this.setReticlePosition(point2d);
if (!Reticle.isPointingAtSystemOverlay(point2d)) {
@ -208,10 +192,9 @@
};
this.exitModule = function() {
this.moveMouseAwayFromTablet();
LaserPointers.disableLaserPointer(this.laserPointer);
};
this.isReady = function (controllerData) {
if (this.processLaser(controllerData)) {
return ControllerDispatcherUtils.makeRunningValues(true, [], []);
@ -240,12 +223,12 @@
enabled: true,
defaultRenderStates: defaultRenderStates
});
}
}
var leftHudOverlayPointer = new HudOverlayPointer(LEFT_HAND);
var leftHudOverlayPointer = new HudOverlayPointer(LEFT_HAND);
var rightHudOverlayPointer = new HudOverlayPointer(RIGHT_HAND);
var clickMapping = Controller.newMapping('HudOverlayPointer-click');
clickMapping.from(rightHudOverlayPointer.isClicked).to(Controller.Actions.ReticleClick);
clickMapping.from(leftHudOverlayPointer.isClicked).to(Controller.Actions.ReticleClick);

View file

@ -13,9 +13,6 @@
(function() {
var ControllerDispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
var WEIGHTING = 1 / 20; // simple moving average over last 20 samples
var ONE_MINUS_WEIGHTING = 1 - WEIGHTING;
var AVERAGE_MOUSE_VELOCITY_FOR_SEEK_TO = 20;
function TimeLock(experation) {
this.experation = experation;
this.last = 0;
@ -27,7 +24,7 @@
return ((time || Date.now()) - this.last) > this.experation;
};
}
function MouseHMD() {
var _this = this;
this.mouseMoved = false;
@ -67,14 +64,15 @@
var result = controllerData.mouseRayPick;
Reticle.depth = result.intersects ? result.distance : APPARENT_MAXIMUM_DEPTH;
}
}
};
this.ignoreMouseActivity = function() {
if (!Reticle.allowMouseCapture) {
return true;
}
var pos = Reticle.position;
if (!pos || (pos.x == -1 && pos.y == -1)) {
if (!pos || (pos.x === -1 && pos.y === -1)) {
return true;
}
@ -99,7 +97,7 @@
return false;
};
this.isReady = function(controllerData, deltaTime) {
var now = Date.now();
this.triggersPressed(controllerData, now);
@ -113,7 +111,7 @@
return ControllerDispatcherUtils.makeRunningValues(false, [], []);
};
this.run = function(controllerData, deltaTime) {
var now = Date.now();
if (this.mouseActivity.expired(now) || this.triggersPressed(controllerData, now)) {

View file

@ -248,10 +248,17 @@ Script.include("/~/system/libraries/controllers.js");
}
};
this.nearGrabWantsToRun = function(controllerData) {
var moduleName = this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay";
var module = getEnabledModuleByName(moduleName);
var ready = module ? module.isReady(controllerData) : makeRunningValues(false, [], []);
return ready.active;
};
this.processStylus = function(controllerData) {
this.updateStylusTip();
if (!this.stylusTip.valid || this.overlayLaserActive(controllerData)) {
if (!this.stylusTip.valid || this.overlayLaserActive(controllerData) || this.nearGrabWantsToRun(controllerData)) {
this.pointFinger(false);
this.hideStylus();
return false;