Clear finger joints when finger poses no longer being updated

This commit is contained in:
David Rowe 2017-06-23 16:15:40 +12:00
parent 8682cee17a
commit b26f5c5811
2 changed files with 29 additions and 23 deletions

View file

@ -4562,19 +4562,28 @@ void Application::update(float deltaTime) {
auto avatarToSensorMatrix = worldToSensorMatrix * myAvatarMatrix; auto avatarToSensorMatrix = worldToSensorMatrix * myAvatarMatrix;
myAvatar->setHandControllerPosesInSensorFrame(leftHandPose.transform(avatarToSensorMatrix), rightHandPose.transform(avatarToSensorMatrix)); myAvatar->setHandControllerPosesInSensorFrame(leftHandPose.transform(avatarToSensorMatrix), rightHandPose.transform(avatarToSensorMatrix));
// If have previously done finger poses or there are new valid finger poses, update finger pose values. This so that if
// fingers are not being controlled, finger joints are not updated in MySkeletonModel.
// Assumption: Finger poses are either all present and valid or not present at all; thus can test just one joint.
MyAvatar::FingerPosesMap leftHandFingerPoses; MyAvatar::FingerPosesMap leftHandFingerPoses;
for (int i = (int)controller::Action::LEFT_HAND_THUMB1; i <= (int)controller::Action::LEFT_HAND_PINKY4; i++) { if (myAvatar->getLeftHandFingerControllerPosesInSensorFrame().size() > 0
leftHandFingerPoses[i] = { || userInputMapper->getPoseState(controller::Action::LEFT_HAND_THUMB1).isValid()) {
userInputMapper->getPoseState((controller::Action)i).transform(avatarToSensorMatrix), for (int i = (int)controller::Action::LEFT_HAND_THUMB1; i <= (int)controller::Action::LEFT_HAND_PINKY4; i++) {
userInputMapper->getActionName((controller::Action)i) leftHandFingerPoses[i] = {
}; userInputMapper->getPoseState((controller::Action)i).transform(avatarToSensorMatrix),
userInputMapper->getActionName((controller::Action)i)
};
}
} }
MyAvatar::FingerPosesMap rightHandFingerPoses; MyAvatar::FingerPosesMap rightHandFingerPoses;
for (int i = (int)controller::Action::RIGHT_HAND_THUMB1; i <= (int)controller::Action::RIGHT_HAND_PINKY4; i++) { if (myAvatar->getRightHandFingerControllerPosesInSensorFrame().size() > 0
rightHandFingerPoses[i] = { || userInputMapper->getPoseState(controller::Action::RIGHT_HAND_THUMB1).isValid()) {
userInputMapper->getPoseState((controller::Action)i).transform(avatarToSensorMatrix), for (int i = (int)controller::Action::RIGHT_HAND_THUMB1; i <= (int)controller::Action::RIGHT_HAND_PINKY4; i++) {
userInputMapper->getActionName((controller::Action)i) rightHandFingerPoses[i] = {
}; userInputMapper->getPoseState((controller::Action)i).transform(avatarToSensorMatrix),
userInputMapper->getActionName((controller::Action)i)
};
}
} }
myAvatar->setFingerControllerPosesInSensorFrame(leftHandFingerPoses, rightHandFingerPoses); myAvatar->setFingerControllerPosesInSensorFrame(leftHandFingerPoses, rightHandFingerPoses);

View file

@ -172,18 +172,13 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
_rig.updateFromEyeParameters(eyeParams); _rig.updateFromEyeParameters(eyeParams);
updateFingers(myAvatar->getLeftHandFingerControllerPosesInSensorFrame());
if (leftHandPose.isValid()) { updateFingers(myAvatar->getRightHandFingerControllerPosesInSensorFrame());
updateFingers(myAvatar->getLeftHandFingerControllerPosesInSensorFrame());
}
if (rightHandPose.isValid()) {
updateFingers(myAvatar->getRightHandFingerControllerPosesInSensorFrame());
}
} }
void MySkeletonModel::updateFingers(const MyAvatar::FingerPosesMap& fingerPoses) { void MySkeletonModel::updateFingers(const MyAvatar::FingerPosesMap& fingerPoses) {
// Assumes that finger poses are kept in the poses map in order. // Assumes that finger poses are kept in order in the poses map.
if (fingerPoses.size() == 0) { if (fingerPoses.size() == 0) {
return; return;
@ -194,21 +189,23 @@ void MySkeletonModel::updateFingers(const MyAvatar::FingerPosesMap& fingerPoses)
bool isLeftHand = posesMapItr->first < (int)controller::Action::RIGHT_HAND_THUMB1; bool isLeftHand = posesMapItr->first < (int)controller::Action::RIGHT_HAND_THUMB1;
MyAvatar* myAvatar = static_cast<MyAvatar*>(_owningAvatar); MyAvatar* myAvatar = static_cast<MyAvatar*>(_owningAvatar);
glm::quat handJointRotation = isLeftHand auto handPose = isLeftHand
? myAvatar->getLeftHandControllerPoseInSensorFrame().getRotation() ? myAvatar->getLeftHandControllerPoseInSensorFrame()
: myAvatar->getRightHandControllerPoseInSensorFrame().getRotation(); : myAvatar->getRightHandControllerPoseInSensorFrame();
auto handJointRotation = handPose.getRotation();
bool isHandValid = handPose.isValid();
bool isFingerValid = false; bool isFingerValid = false;
glm::quat previousJointRotation; glm::quat previousJointRotation;
while (posesMapItr != fingerPoses.end()) { while (posesMapItr != fingerPoses.end()) {
auto jointName = posesMapItr->second.second; auto jointName = posesMapItr->second.second;
if (jointName.right(1) == "1") { if (isHandValid && jointName.right(1) == "1") {
isFingerValid = posesMapItr->second.first.isValid(); isFingerValid = posesMapItr->second.first.isValid();
previousJointRotation = handJointRotation; previousJointRotation = handJointRotation;
} }
if (isFingerValid) { if (isHandValid && isFingerValid) {
auto thisJointRotation = posesMapItr->second.first.getRotation(); auto thisJointRotation = posesMapItr->second.first.getRotation();
const float CONTROLLER_PRIORITY = 2.0f; const float CONTROLLER_PRIORITY = 2.0f;
_rig.setJointRotation(_rig.indexOfJoint(jointName), true, glm::inverse(previousJointRotation) * thisJointRotation, _rig.setJointRotation(_rig.indexOfJoint(jointName), true, glm::inverse(previousJointRotation) * thisJointRotation,