Fix transform computation

This commit is contained in:
Atlante45 2017-02-17 18:29:00 -08:00
parent 0440e2fd60
commit e503542b6a

View file

@ -2481,21 +2481,21 @@ bool MyAvatar::pinJoint(int index, const glm::vec3& position, const glm::quat& o
qWarning() << "Pinning is only supported for the hips joint at the moment."; qWarning() << "Pinning is only supported for the hips joint at the moment.";
return false; return false;
} }
qApp->getActiveDisplayPlugin()->resetSensors();
auto jointTranslation = getAbsoluteJointTranslationInObjectFrame(index); auto jointTranslation = getAbsoluteJointTranslationInObjectFrame(index);
auto jointRotation = getAbsoluteJointRotationInObjectFrame(index); auto jointRotation = getAbsoluteJointRotationInObjectFrame(index);
Transform final(orientation, Vectors::ONE, position); auto targetOrientation = orientation * glm::conjugate(glm::normalize(jointRotation));
Transform joint(jointRotation, Vectors::ONE, jointTranslation); auto targetPosition = position - orientation * jointTranslation;
Transform avatarTransform(final.getMatrix() * joint.getInverseMatrix()); setPosition(targetPosition);
setPosition(avatarTransform.getTranslation()); setOrientation(targetOrientation);
setOrientation(avatarTransform.getRotation());
_rig->setMaxHipsOffsetLength(0.0f); _rig->setMaxHipsOffsetLength(0.0f);
auto it = std::find(_pinnedJoints.begin(), _pinnedJoints.end(), index); auto it = std::find(_pinnedJoints.begin(), _pinnedJoints.end(), index);
if (it != _pinnedJoints.end()) { if (it == _pinnedJoints.end()) {
_pinnedJoints.push_back(index); _pinnedJoints.push_back(index);
} }