From 0e17506137b22c043429773b6e545c29fdc72e6a Mon Sep 17 00:00:00 2001 From: PhilipRosedale Date: Mon, 29 Feb 2016 16:21:06 -0800 Subject: [PATCH 1/6] hand controller doesn't take mouse if set down, renamed file. --- ...dRotationTest.js => handControllerMouse.js} | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) rename examples/controllers/{reticleHandRotationTest.js => handControllerMouse.js} (83%) diff --git a/examples/controllers/reticleHandRotationTest.js b/examples/controllers/handControllerMouse.js similarity index 83% rename from examples/controllers/reticleHandRotationTest.js rename to examples/controllers/handControllerMouse.js index 631486d1a3..f42d95e819 100644 --- a/examples/controllers/reticleHandRotationTest.js +++ b/examples/controllers/handControllerMouse.js @@ -1,5 +1,5 @@ // -// reticleHandRotationTest.js +// handControllerMouse.js // examples/controllers // // Created by Brad Hefta-Gaub on 2015/12/15 @@ -11,6 +11,10 @@ var DEBUGGING = false; +var angularVelocityTrailingAverage = 0.0; // Global trailing average used to decide whether to move reticle at all +var lastX = 0; +var lastY = 0; + Math.clamp=function(a,b,c) { return Math.max(b,Math.min(c,a)); } @@ -76,7 +80,7 @@ Script.update.connect(function(deltaTime) { } // Velocity filter the hand rotation used to position reticle so that it is easier to target small things with the hand controllers - var VELOCITY_FILTER_GAIN = 1.0; + var VELOCITY_FILTER_GAIN = 0.5; filteredRotatedLeft = Vec3.mix(filteredRotatedLeft, rotatedLeft, Math.clamp(Vec3.length(poseLeft.angularVelocity) * VELOCITY_FILTER_GAIN, 0.0, 1.0)); filteredRotatedRight = Vec3.mix(filteredRotatedRight, rotatedRight, Math.clamp(Vec3.length(poseRight.angularVelocity) * VELOCITY_FILTER_GAIN, 0.0, 1.0)); var rotated = Vec3.mix(filteredRotatedLeft, filteredRotatedRight, leftRightBias); @@ -96,11 +100,17 @@ Script.update.connect(function(deltaTime) { var y = screenSizeY * yRatio; // don't move the reticle with the hand controllers unless the controllers are actually being moved - var MINIMUM_CONTROLLER_ANGULAR_VELOCITY = 0.0001; + // take a time average of angular velocity, and don't move mouse at all if it's below threshold + + var AVERAGING_INTERVAL = 0.95; + var MINIMUM_CONTROLLER_ANGULAR_VELOCITY = 0.03; var angularVelocityMagnitude = Vec3.length(poseLeft.angularVelocity) * (1.0 - leftRightBias) + Vec3.length(poseRight.angularVelocity) * leftRightBias; + angularVelocityTrailingAverage = angularVelocityTrailingAverage * AVERAGING_INTERVAL + angularVelocityMagnitude * (1.0 - AVERAGING_INTERVAL); - if (!(xRatio == 0.5 && yRatio == 0) && (angularVelocityMagnitude > MINIMUM_CONTROLLER_ANGULAR_VELOCITY)) { + if (!(xRatio == 0.5 && yRatio == 0) && (angularVelocityTrailingAverage > MINIMUM_CONTROLLER_ANGULAR_VELOCITY) && ((x != lastX) || (y != lastY))) { moveReticleAbsolute(x, y); + lastX = x; + lastY = y; } }); From 86249cc9db6dbfa3c9f2154aa906565101f676bf Mon Sep 17 00:00:00 2001 From: PhilipRosedale Date: Mon, 29 Feb 2016 16:23:03 -0800 Subject: [PATCH 2/6] add hand controller mouse to default scripts --- examples/defaultScripts.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index 35af5f4eae..d612e617e1 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -17,6 +17,7 @@ Script.load("inspect.js"); Script.load("notifications.js"); Script.load("users.js"); Script.load("controllers/handControllerGrab.js"); +Script.load("controllers/handControllerMouse.js"); Script.load("controllers/squeezeHands.js"); Script.load("grab.js"); Script.load("directory.js"); From b89b6be210011acbdecf7329c7e0eaf7a31784cc Mon Sep 17 00:00:00 2001 From: PhilipRosedale Date: Mon, 29 Feb 2016 16:45:00 -0800 Subject: [PATCH 3/6] look for hydra first --- examples/controllers/handControllerMouse.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/controllers/handControllerMouse.js b/examples/controllers/handControllerMouse.js index f42d95e819..d353afab5e 100644 --- a/examples/controllers/handControllerMouse.js +++ b/examples/controllers/handControllerMouse.js @@ -35,12 +35,13 @@ function moveReticleAbsolute(x, y) { var MAPPING_NAME = "com.highfidelity.testing.reticleWithHandRotation"; var mapping = Controller.newMapping(MAPPING_NAME); -mapping.from(Controller.Hardware.Hydra.L3).peek().to(Controller.Actions.ReticleClick); -mapping.from(Controller.Hardware.Hydra.R4).peek().to(Controller.Actions.ReticleClick); +if (Controller.Hardware.hydra !== undefined) { + mapping.from(Controller.Hardware.Hydra.L3).peek().to(Controller.Actions.ReticleClick); + mapping.from(Controller.Hardware.Hydra.R4).peek().to(Controller.Actions.ReticleClick); +} + mapping.enable(); - - function debugPrint(message) { if (DEBUGGING) { print(message); From efe53c1a85a037f60078ddc267c595fe5ddf5a40 Mon Sep 17 00:00:00 2001 From: PhilipRosedale Date: Mon, 29 Feb 2016 17:12:43 -0800 Subject: [PATCH 4/6] actually don't add to default yet --- examples/defaultScripts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index d612e617e1..35af5f4eae 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -17,7 +17,6 @@ Script.load("inspect.js"); Script.load("notifications.js"); Script.load("users.js"); Script.load("controllers/handControllerGrab.js"); -Script.load("controllers/handControllerMouse.js"); Script.load("controllers/squeezeHands.js"); Script.load("grab.js"); Script.load("directory.js"); From e01524abbe4c6657341ee78c1037edce20c28196 Mon Sep 17 00:00:00 2001 From: PhilipRosedale Date: Fri, 4 Mar 2016 11:24:35 -0800 Subject: [PATCH 5/6] fix for clicking --- examples/controllers/handControllerMouse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/controllers/handControllerMouse.js b/examples/controllers/handControllerMouse.js index d353afab5e..8807fb9794 100644 --- a/examples/controllers/handControllerMouse.js +++ b/examples/controllers/handControllerMouse.js @@ -35,7 +35,7 @@ function moveReticleAbsolute(x, y) { var MAPPING_NAME = "com.highfidelity.testing.reticleWithHandRotation"; var mapping = Controller.newMapping(MAPPING_NAME); -if (Controller.Hardware.hydra !== undefined) { +if (Controller.Hardware.Hydra !== undefined) { mapping.from(Controller.Hardware.Hydra.L3).peek().to(Controller.Actions.ReticleClick); mapping.from(Controller.Hardware.Hydra.R4).peek().to(Controller.Actions.ReticleClick); } From 87e7dd9ce3088c79bd91e7d19c4be27e7122f983 Mon Sep 17 00:00:00 2001 From: PhilipRosedale Date: Fri, 4 Mar 2016 16:16:05 -0800 Subject: [PATCH 6/6] add vive button mapping --- examples/controllers/handControllerMouse.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/controllers/handControllerMouse.js b/examples/controllers/handControllerMouse.js index 8807fb9794..e53fc34df1 100644 --- a/examples/controllers/handControllerMouse.js +++ b/examples/controllers/handControllerMouse.js @@ -10,7 +10,6 @@ // var DEBUGGING = false; - var angularVelocityTrailingAverage = 0.0; // Global trailing average used to decide whether to move reticle at all var lastX = 0; var lastY = 0; @@ -39,6 +38,10 @@ if (Controller.Hardware.Hydra !== undefined) { mapping.from(Controller.Hardware.Hydra.L3).peek().to(Controller.Actions.ReticleClick); mapping.from(Controller.Hardware.Hydra.R4).peek().to(Controller.Actions.ReticleClick); } +if (Controller.Hardware.Vive !== undefined) { + mapping.from(Controller.Hardware.Vive.LeftPrimaryThumb).peek().to(Controller.Actions.ReticleClick); + mapping.from(Controller.Hardware.Vive.RightPrimaryThumb).peek().to(Controller.Actions.ReticleClick); +} mapping.enable();