From 84a3f6e8f433596c6b8aec99315da79030989fe0 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 1 Oct 2014 15:00:19 -0700 Subject: [PATCH] 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);