viveMotionCapture.js: can now disable puck control, with a second controller squeeze

This commit is contained in:
Anthony J. Thibault 2017-04-25 15:05:52 -07:00
parent 4336e22f5a
commit ce8b71ff94

View file

@ -8,7 +8,7 @@ var TRACKED_OBJECT_POSES = [
"TrackedObject12", "TrackedObject13", "TrackedObject14", "TrackedObject15" "TrackedObject12", "TrackedObject13", "TrackedObject14", "TrackedObject15"
]; ];
var calibrated = false; var triggerPressHandled = false;
var rightTriggerPressed = false; var rightTriggerPressed = false;
var leftTriggerPressed = false; var leftTriggerPressed = false;
@ -43,21 +43,6 @@ var SENSOR_CONFIG_NAMES = [
"Auto" "Auto"
]; ];
var ANIM_VARS = [
"leftFootType",
"leftFootPosition",
"leftFootRotation",
"rightFootType",
"rightFootPosition",
"rightFootRotation",
"hipsType",
"hipsPosition",
"hipsRotation",
"spine2Type",
"spine2Position",
"spine2Rotation"
];
var sensorConfig = AUTO; var sensorConfig = AUTO;
var Y_180 = {x: 0, y: 1, z: 0, w: 0}; var Y_180 = {x: 0, y: 1, z: 0, w: 0};
@ -86,7 +71,7 @@ function computeDefaultToReferenceXform() {
return defaultToReferenceXform; return defaultToReferenceXform;
} else { } else {
return new Xform.ident(); return Xform.ident();
} }
} }
@ -200,71 +185,86 @@ function computeIKTargetXform(jointInfo) {
function update(dt) { function update(dt) {
if (rightTriggerPressed && leftTriggerPressed) { if (rightTriggerPressed && leftTriggerPressed) {
if (!calibrated) { if (!triggerPressHandled) {
calibrate(); triggerPressHandled = true;
calibrated = true;
if (handlerId) { if (handlerId) {
MyAvatar.removeAnimationStateHandler(handlerId); print("AJT: UN-CALIBRATE!");
}
handlerId = MyAvatar.addAnimationStateHandler(function (props) { // go back to normal, vive pucks will be ignored.
leftFoot = undefined;
var result = {}, xform; rightFoot = undefined;
if (rightFoot) { hips = undefined;
xform = computeIKTargetXform(rightFoot); spine2 = undefined;
result.rightFootType = ikTypes.RotationAndPosition; if (handlerId) {
result.rightFootPosition = xform.pos; print("AJT: un-hooking animation state handler");
result.rightFootRotation = xform.rot; MyAvatar.removeAnimationStateHandler(handlerId);
} else { handlerId = undefined;
result.rightFootType = props.rightFootType;
result.rightFootPosition = props.rightFootPosition;
result.rightFootRotation = props.rightFootRotation;
} }
} else {
print("AJT: CALIBRATE!");
calibrate();
var animVars = [];
if (leftFoot) { if (leftFoot) {
xform = computeIKTargetXform(leftFoot); animVars.push("leftFootType");
result.leftFootType = ikTypes.RotationAndPosition; animVars.push("leftFootPosition");
result.leftFootPosition = xform.pos; animVars.push("leftFootRotation");
result.leftFootRotation = xform.rot; }
} else { if (rightFoot) {
result.leftFootType = props.leftFootType; animVars.push("rightFootType");
result.leftFootPosition = props.leftFootPosition; animVars.push("rightFootPosition");
result.leftFootRotation = props.leftFootRotation; animVars.push("rightFootRotation");
} }
if (hips) { if (hips) {
xform = computeIKTargetXform(hips); animVars.push("hipsType");
result.hipsType = ikTypes.RotationAndPosition; animVars.push("hipsPosition");
result.hipsPosition = xform.pos; animVars.push("hipsRotation");
result.hipsRotation = xform.rot;
} else {
result.hipsType = props.hipsType;
result.hipsPosition = props.hipsPosition;
result.hipsRotation = props.hipsRotation;
} }
if (spine2) { if (spine2) {
xform = computeIKTargetXform(spine2); animVars.push("spine2Type");
result.spine2Type = ikTypes.RotationAndPosition; animVars.push("spine2Position");
result.spine2Position = xform.pos; animVars.push("spine2Rotation");
result.spine2Rotation = xform.rot;
} else {
result.spine2Type = ikTypes.Off;
} }
return result; // hook up new anim state handler that maps vive pucks to ik system.
}, ANIM_VARS); handlerId = MyAvatar.addAnimationStateHandler(function (props) {
var result = {}, xform;
if (rightFoot) {
xform = computeIKTargetXform(rightFoot);
result.rightFootType = ikTypes.RotationAndPosition;
result.rightFootPosition = xform.pos;
result.rightFootRotation = xform.rot;
}
if (leftFoot) {
xform = computeIKTargetXform(leftFoot);
result.leftFootType = ikTypes.RotationAndPosition;
result.leftFootPosition = xform.pos;
result.leftFootRotation = xform.rot;
}
if (hips) {
xform = computeIKTargetXform(hips);
result.hipsType = ikTypes.RotationAndPosition;
result.hipsPosition = xform.pos;
result.hipsRotation = xform.rot;
}
if (spine2) {
xform = computeIKTargetXform(spine2);
result.spine2Type = ikTypes.RotationAndPosition;
result.spine2Position = xform.pos;
result.spine2Rotation = xform.rot;
}
return result;
}, animVars);
}
} }
} else { } else {
calibrated = false; triggerPressHandled = false;
} }
var drawMarkers = false; var drawMarkers = false;
if (drawMarkers) { if (drawMarkers) {
var RED = {x: 1, y: 0, z: 0, w: 1}; var RED = {x: 1, y: 0, z: 0, w: 1};
var GREEN = {x: 0, y: 1, z: 0, w: 1};
var BLUE = {x: 0, y: 0, z: 1, w: 1}; var BLUE = {x: 0, y: 0, z: 1, w: 1};
if (leftFoot) { if (leftFoot) {
@ -304,4 +304,4 @@ Script.scriptEnding.connect(function () {
Controller.disableMapping(MAPPING_NAME); Controller.disableMapping(MAPPING_NAME);
Script.update.disconnect(update); Script.update.disconnect(update);
}); });
var TRIGGER_OFF_VALUE = 0.1;