Make recalibrate Leap-on-desk if avatar scale changes

This commit is contained in:
David Rowe 2014-10-01 15:00:19 -07:00
parent b6fba04d4f
commit 84a3f6e8f4

View file

@ -30,7 +30,9 @@ var leapHands = (function () {
CALIBRATED = 2, CALIBRATED = 2,
CALIBRATION_TIME = 1000, // milliseconds CALIBRATION_TIME = 1000, // milliseconds
PI = 3.141593, PI = 3.141593,
isWindows; isWindows,
avatarScale,
settingsTimer;
function printSkeletonJointNames() { function printSkeletonJointNames() {
var jointNames, var jointNames,
@ -164,6 +166,8 @@ var leapHands = (function () {
calibrationStatus = CALIBRATING; calibrationStatus = CALIBRATING;
avatarScale = MyAvatar.scale;
// Set avatar arms vertical, forearms horizontal, as "zero" position for calibration // Set avatar arms vertical, forearms horizontal, as "zero" position for calibration
MyAvatar.setJointData("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, -90.0)); MyAvatar.setJointData("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, -90.0));
MyAvatar.setJointData("LeftForeArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 180.0)); MyAvatar.setJointData("LeftForeArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 180.0));
@ -189,6 +193,13 @@ var leapHands = (function () {
return false; return false;
} }
function checkSettings() {
if (!isOnHMD && calibrationStatus && MyAvatar.scale !== avatarScale) {
print("Leap Motion: Recalibrate because avatar scale changed");
calibrationStatus = UNCALIBRATED;
}
}
function setUp() { function setUp() {
// TODO: Leap Motion controller joint naming doesn't match up with skeleton joint naming; numbers are out by 1. // 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"); print("Leap Motion is on desk");
calibrationStatus = UNCALIBRATED; calibrationStatus = UNCALIBRATED;
} }
settingsTimer = Script.setInterval(checkSettings, 2000);
} }
function moveHands() { function moveHands() {
@ -302,7 +315,7 @@ var leapHands = (function () {
if (hands[h].controller.isActive()) { if (hands[h].controller.isActive()) {
// Calibrate when and if a controller is first active. // Calibrate if necessary.
if (!checkCalibration()) { if (!checkCalibration()) {
return; return;
} }
@ -430,6 +443,8 @@ var leapHands = (function () {
i, i,
j; j;
Script.clearInterval(settingsTimer);
for (h = 0; h < NUM_HANDS; h += 1) { for (h = 0; h < NUM_HANDS; h += 1) {
Controller.releaseInputController(hands[h].controller); Controller.releaseInputController(hands[h].controller);
Controller.releaseInputController(wrists[h].controller); Controller.releaseInputController(wrists[h].controller);