revert pointer changes

This commit is contained in:
James B. Pollack 2016-08-02 21:26:48 -07:00
parent fed39d9056
commit 5ad5899140

View file

@ -56,12 +56,8 @@ function Trigger(label) {
that.rawTriggerValue = 0;
that.triggerValue = 0; // rolling average of trigger value
that.triggerClicked = false;
that.triggerClick = function(value) {
that.triggerClicked = value;
};
that.triggerPress = function(value) {
that.rawTriggerValue = value;
};
that.triggerClick = function (value) { that.triggerClicked = value; };
that.triggerPress = function (value) { that.rawTriggerValue = value; };
that.updateSmoothedTrigger = function () { // e.g., call once/update for effect
var triggerValue = that.rawTriggerValue;
// smooth out trigger value
@ -119,7 +115,6 @@ function updateFieldOfView() {
// SHIMS ----------
//
var weMovedReticle = false;
function ignoreMouseActivity() {
// If we're paused, or if change in cursor position is from this script, not the hardware mouse.
if (!Reticle.allowMouseCapture) {
@ -137,10 +132,7 @@ function ignoreMouseActivity() {
return true;
}
var MARGIN = 25;
var reticleMinX = MARGIN,
reticleMaxX, reticleMinY = MARGIN,
reticleMaxY;
var reticleMinX = MARGIN, reticleMaxX, reticleMinY = MARGIN, reticleMaxY;
function updateRecommendedArea() {
var dims = Controller.getViewportDimensions();
reticleMaxX = dims.x - MARGIN;
@ -162,7 +154,6 @@ function findRayIntersection(pickRay) {
}
return result;
}
function isPointingAtOverlay(optionalHudPosition2d) {
return Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(optionalHudPosition2d || Reticle.position);
}
@ -170,7 +161,6 @@ function isPointingAtOverlay(optionalHudPosition2d) {
// Generalized HUD utilities, with or without HMD:
// This "var" is for documentation. Do not change the value!
var PLANAR_PERPENDICULAR_HUD_DISTANCE = 1;
function calculateRayUICollisionPoint(position, direction) {
// Answer the 3D intersection of the HUD by the given ray, or falsey if no intersection.
if (HMD.active) {
@ -190,7 +180,6 @@ function calculateRayUICollisionPoint(position, direction) {
return Vec3.sum(position, Vec3.multiply(scale, direction));
}
var DEGREES_TO_HALF_RADIANS = Math.PI / 360;
function overlayFromWorldPoint(point) {
// Answer the 2d pixel-space location in the HUD that covers the given 3D point.
// REQUIRES: that the 3d point be on the hud surface!
@ -210,10 +199,7 @@ function overlayFromWorldPoint(point) {
var verticalFraction = 1 - (cameraY / hudHeight + 0.5);
var horizontalPixels = size.x * horizontalFraction;
var verticalPixels = size.y * verticalFraction;
return {
x: horizontalPixels,
y: verticalPixels
};
return { x: horizontalPixels, y: verticalPixels };
}
function activeHudPoint2d(activeHand) { // if controller is valid, update reticle position and answer 2d point. Otherwise falsey.
@ -245,17 +231,12 @@ function activeHudPoint2d(activeHand) { // if controller is valid, update reticl
// MOUSE ACTIVITY --------
//
var isSeeking = false;
var averageMouseVelocity = 0,
lastIntegration = 0,
lastMouse;
var averageMouseVelocity = 0, lastIntegration = 0, lastMouse;
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 isShakingMouse() { // True if the person is waving the mouse around trying to find it.
var now = Date.now(),
mouse = Reticle.position,
isShaking = false;
var now = Date.now(), mouse = Reticle.position, isShaking = false;
if (lastIntegration && (lastIntegration !== now)) {
var velocity = Vec3.length(Vec3.subtract(mouse, lastMouse)) / (now - lastIntegration);
averageMouseVelocity = (ONE_MINUS_WEIGHTING * averageMouseVelocity) + (WEIGHTING * velocity);
@ -269,7 +250,6 @@ function isShakingMouse() { // True if the person is waving the mouse around try
}
var NON_LINEAR_DIVISOR = 2;
var MINIMUM_SEEK_DISTANCE = 0.1;
function updateSeeking(doNotStartSeeking) {
if (!doNotStartSeeking && (!Reticle.visible || isShakingMouse())) {
if (!isSeeking) {
@ -288,7 +268,6 @@ function updateSeeking(doNotStartSeeking) {
return; // E.g., if parallel to location in HUD
}
var copy = Reticle.position;
function updateDimension(axis) {
var distanceBetween = lookAt2D[axis] - Reticle.position[axis];
var move = distanceBetween / NON_LINEAR_DIVISOR;
@ -298,8 +277,7 @@ function updateSeeking(doNotStartSeeking) {
copy[axis] += move;
return true;
}
var okX = !updateDimension('x'),
okY = !updateDimension('y'); // Evaluate both. Don't short-circuit.
var okX = !updateDimension('x'), okY = !updateDimension('y'); // Evaluate both. Don't short-circuit.
if (okX && okY) {
print('Finished seeking mouse');
isSeeking = false;
@ -322,19 +300,16 @@ function updateMouseActivity(isClick) {
handControllerLockOut.update(now);
Reticle.visible = true;
}
function expireMouseCursor(now) {
if (!isPointingAtOverlay() && mouseCursorActivity.expired(now)) {
Reticle.visible = false;
}
}
function hudReticleDistance() { // 3d distance from camera to the reticle position on hud
// (The camera is only in the center of the sphere on reset.)
var reticlePositionOnHUD = HMD.worldPointFromOverlay(Reticle.position);
return Vec3.distance(reticlePositionOnHUD, HMD.position);
}
function onMouseMove() {
// Display cursor at correct depth (as in depthReticle.js), and updateMouseActivity.
if (ignoreMouseActivity()) {
@ -352,7 +327,6 @@ function onMouseMove() {
}
updateMouseActivity(); // After the above, just in case the depth movement is awkward when becoming visible.
}
function onMouseClick() {
updateMouseActivity(true);
}
@ -371,7 +345,6 @@ var LEFT_HUD_LASER = 1;
var RIGHT_HUD_LASER = 2;
var BOTH_HUD_LASERS = LEFT_HUD_LASER + RIGHT_HUD_LASER;
var activeHudLaser = RIGHT_HUD_LASER;
function toggleHand() { // unequivocally switch which hand controls mouse position
if (activeHand === Controller.Standard.RightHand) {
activeHand = Controller.Standard.LeftHand;
@ -384,7 +357,6 @@ function toggleHand() { // unequivocally switch which hand controls mouse positi
}
clearSystemLaser();
}
function makeToggleAction(hand) { // return a function(0|1) that makes the specified hand control mouse when 1
return function (on) {
if (on && (activeHand !== hand)) {
@ -426,9 +398,7 @@ clickMapping.from(leftTrigger.full).when(isPointingAtOverlayStartedNonFullTrigge
// clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(Controller.Actions.ContextMenu);
// except that we first update the reticle position from the appropriate hand position, before invoking the ContextMenu.
var wantsMenu = 0;
clickMapping.from(function() {
return wantsMenu;
}).to(Controller.Actions.ContextMenu);
clickMapping.from(function () { return wantsMenu; }).to(Controller.Actions.ContextMenu);
clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(function (clicked) {
if (clicked) {
activeHudPoint2d(Controller.Standard.RightHand);
@ -459,25 +429,10 @@ clickMapping.enable();
// VISUAL AID -----------
// Same properties as handControllerGrab search sphere
var LASER_ALPHA = 0.5;
var LASER_SEARCH_COLOR_XYZW = {
x: 10 / 255,
y: 10 / 255,
z: 255 / 255,
w: LASER_ALPHA
};
var LASER_TRIGGER_COLOR_XYZW = {
x: 250 / 255,
y: 10 / 255,
z: 10 / 255,
w: LASER_ALPHA
};
var SYSTEM_LASER_DIRECTION = {
x: 0,
y: 0,
z: -1
};
var LASER_SEARCH_COLOR_XYZW = {x: 10 / 255, y: 10 / 255, z: 255 / 255, w: LASER_ALPHA};
var LASER_TRIGGER_COLOR_XYZW = {x: 250 / 255, y: 10 / 255, z: 10 / 255, w: LASER_ALPHA};
var SYSTEM_LASER_DIRECTION = {x: 0, y: 0, z: -1};
var systemLaserOn = false;
function clearSystemLaser() {
if (!systemLaserOn) {
return;
@ -485,12 +440,8 @@ function clearSystemLaser() {
HMD.disableHandLasers(BOTH_HUD_LASERS);
systemLaserOn = false;
weMovedReticle = true;
Reticle.position = {
x: -1,
y: -1
};
Reticle.position = { x: -1, y: -1 };
}
function setColoredLaser() { // answer trigger state if lasers supported, else falsey.
var color = (activeTrigger.state === 'full') ? LASER_TRIGGER_COLOR_XYZW : LASER_SEARCH_COLOR_XYZW;
return HMD.setHandLasers(activeHudLaser, true, color, SYSTEM_LASER_DIRECTION) && activeTrigger.state;
@ -500,7 +451,6 @@ function setColoredLaser() { // answer trigger state if lasers supported, else f
//
function update() {
var now = Date.now();
function off() {
expireMouseCursor();
clearSystemLaser();
@ -558,27 +508,3 @@ Script.scriptEnding.connect(function() {
Script.clearInterval(settingsChecker);
OffscreenFlags.navigationFocusDisabled = false;
});
var isDisabled = false;
var handleHandMessages = function(channel, message, sender) {
var data;
if (sender === MyAvatar.sessionUUID) {
if (channel === 'Hifi-Hand-Pointer-Disabler') {
if (message === 'both') {
isDisabled = 'both';
}
if (message === 'left') {
isDisabled = 'left';
}
if (message === 'right') {
isDisabled = 'right';
}
if (message === 'none') {
isDisabled = false;
}
}
}
}
Messages.subscribe('Hifi-Hand-Pointer-Disabler');
Messages.messageReceived.connect(handleHandMessages);