From 84a3f6e8f433596c6b8aec99315da79030989fe0 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 1 Oct 2014 15:00:19 -0700 Subject: [PATCH 1/3] Make recalibrate Leap-on-desk if avatar scale changes --- examples/leapHands.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/examples/leapHands.js b/examples/leapHands.js index cc50a328f8..422aed940f 100644 --- a/examples/leapHands.js +++ b/examples/leapHands.js @@ -30,7 +30,9 @@ var leapHands = (function () { CALIBRATED = 2, CALIBRATION_TIME = 1000, // milliseconds PI = 3.141593, - isWindows; + isWindows, + avatarScale, + settingsTimer; function printSkeletonJointNames() { var jointNames, @@ -164,6 +166,8 @@ var leapHands = (function () { calibrationStatus = CALIBRATING; + avatarScale = MyAvatar.scale; + // Set avatar arms vertical, forearms horizontal, as "zero" position for calibration MyAvatar.setJointData("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, -90.0)); MyAvatar.setJointData("LeftForeArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 180.0)); @@ -189,6 +193,13 @@ var leapHands = (function () { return false; } + function checkSettings() { + if (!isOnHMD && calibrationStatus && MyAvatar.scale !== avatarScale) { + print("Leap Motion: Recalibrate because avatar scale changed"); + calibrationStatus = UNCALIBRATED; + } + } + function setUp() { // TODO: Leap Motion controller joint naming doesn't match up with skeleton joint naming; numbers are out by 1. @@ -280,6 +291,8 @@ var leapHands = (function () { print("Leap Motion is on desk"); calibrationStatus = UNCALIBRATED; } + + settingsTimer = Script.setInterval(checkSettings, 2000); } function moveHands() { @@ -302,7 +315,7 @@ var leapHands = (function () { if (hands[h].controller.isActive()) { - // Calibrate when and if a controller is first active. + // Calibrate if necessary. if (!checkCalibration()) { return; } @@ -430,6 +443,8 @@ var leapHands = (function () { i, j; + Script.clearInterval(settingsTimer); + for (h = 0; h < NUM_HANDS; h += 1) { Controller.releaseInputController(hands[h].controller); Controller.releaseInputController(wrists[h].controller); From 38b6d5dd5d49bc8a77b14875d5f17ed0954ea9aa Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 1 Oct 2014 16:05:19 -0700 Subject: [PATCH 2/3] Make leapHands.js handle Leap-on-HMD setting changes --- examples/leapHands.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/examples/leapHands.js b/examples/leapHands.js index 422aed940f..c7da249892 100644 --- a/examples/leapHands.js +++ b/examples/leapHands.js @@ -14,6 +14,7 @@ var leapHands = (function () { var isOnHMD, + LEAP_ON_HMD_MENU_ITEM = "Leap Motion on HMD", LEAP_OFFSET = 0.019, // Thickness of Leap Motion plus HMD clip HMD_OFFSET = 0.100, // Eyeballs to front surface of Oculus DK2 TODO: Confirm and make depend on device and eye relief hands, @@ -193,11 +194,33 @@ var leapHands = (function () { return false; } + function setIsOnHMD() { + isOnHMD = Menu.isOptionChecked(LEAP_ON_HMD_MENU_ITEM); + if (isOnHMD) { + print("Leap Motion: Is on HMD"); + + // Offset of Leap Motion origin from physical eye position + hands[0].zeroPosition = { x: 0.0, y: 0.0, z: HMD_OFFSET + LEAP_OFFSET }; + hands[1].zeroPosition = { x: 0.0, y: 0.0, z: HMD_OFFSET + LEAP_OFFSET }; + + calibrationStatus = CALIBRATED; + } else { + print("Leap Motion: Is on desk"); + calibrationStatus = UNCALIBRATED; + } + } + function checkSettings() { + // There is no "scale changed" event so we need check periodically. if (!isOnHMD && calibrationStatus && MyAvatar.scale !== avatarScale) { print("Leap Motion: Recalibrate because avatar scale changed"); calibrationStatus = UNCALIBRATED; } + + // There is a "menu changed" event but we may as well check here. + if (isOnHMD !== Menu.isOptionChecked(LEAP_ON_HMD_MENU_ITEM)) { + setIsOnHMD(); + } } function setUp() { @@ -278,19 +301,7 @@ var leapHands = (function () { ] ]; - isOnHMD = Menu.isOptionChecked("Leap Motion on HMD"); - if (isOnHMD) { - print("Leap Motion is on HMD"); - - // Offset of Leap Motion origin from physical eye position - hands[0].zeroPosition = { x: 0.0, y: 0.0, z: HMD_OFFSET + LEAP_OFFSET }; - hands[1].zeroPosition = { x: 0.0, y: 0.0, z: HMD_OFFSET + LEAP_OFFSET }; - - calibrationStatus = CALIBRATED; - } else { - print("Leap Motion is on desk"); - calibrationStatus = UNCALIBRATED; - } + setIsOnHMD(); settingsTimer = Script.setInterval(checkSettings, 2000); } From 51f229af570deed0852ff0f08df4a12b246b191c Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 1 Oct 2014 18:34:56 -0700 Subject: [PATCH 3/3] Make recalibrate Leap-on-desk if avatar head or skeleton changes --- examples/leapHands.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/leapHands.js b/examples/leapHands.js index c7da249892..1095a9f4dc 100644 --- a/examples/leapHands.js +++ b/examples/leapHands.js @@ -33,6 +33,8 @@ var leapHands = (function () { PI = 3.141593, isWindows, avatarScale, + avatarFaceModelURL, + avatarSkeletonModelURL, settingsTimer; function printSkeletonJointNames() { @@ -168,6 +170,8 @@ var leapHands = (function () { calibrationStatus = CALIBRATING; avatarScale = MyAvatar.scale; + avatarFaceModelURL = MyAvatar.faceModelURL; + avatarSkeletonModelURL = MyAvatar.skeletonModelURL; // Set avatar arms vertical, forearms horizontal, as "zero" position for calibration MyAvatar.setJointData("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, -90.0)); @@ -212,8 +216,10 @@ var leapHands = (function () { function checkSettings() { // There is no "scale changed" event so we need check periodically. - if (!isOnHMD && calibrationStatus && MyAvatar.scale !== avatarScale) { - print("Leap Motion: Recalibrate because avatar scale changed"); + if (!isOnHMD && calibrationStatus > UNCALIBRATED && (MyAvatar.scale !== avatarScale + || MyAvatar.faceModelURL !== avatarFaceModelURL + || MyAvatar.skeletonModelURL !== avatarSkeletonModelURL)) { + print("Leap Motion: Recalibrate because avatar body or scale changed"); calibrationStatus = UNCALIBRATED; }