Attempting to rotate longitudinally at elbow, rather than wrist.

This commit is contained in:
Andrzej Kapolka 2013-12-03 11:05:38 -08:00
parent 2633223f4e
commit 817946bed5
3 changed files with 22 additions and 3 deletions

View file

@ -141,6 +141,24 @@ void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingerJoin
float sign = (jointIndex == geometry.rightHandJointIndex) ? 1.0f : -1.0f;
glm::quat palmRotation;
getJointRotation(jointIndex, palmRotation, true);
// start by rotating the elbow into place
int parentIndex = geometry.joints[jointIndex].parentIndex;
if (parentIndex != -1) {
glm::vec3 boneVector = extractTranslation(_jointStates[jointIndex].transform) -
extractTranslation(_jointStates[parentIndex].transform);
float boneLength = glm::length(boneVector);
if (boneLength > EPSILON) {
boneVector /= boneLength;
applyRotationDelta(parentIndex, rotationBetween(
glm::cross(boneVector, glm::cross(palmRotation * geometry.palmDirection, boneVector)),
glm::cross(boneVector, glm::cross(palm.getNormal(), boneVector))), false);
updateJointState(jointIndex);
getJointRotation(jointIndex, palmRotation, true);
}
}
// continue with the wrist
applyRotationDelta(jointIndex, rotationBetween(palmRotation * geometry.palmDirection, palm.getNormal()));
getJointRotation(jointIndex, palmRotation, true);

View file

@ -680,10 +680,11 @@ float Model::getLimbLength(int jointIndex) const {
return length;
}
void Model::applyRotationDelta(int jointIndex, const glm::quat& delta) {
void Model::applyRotationDelta(int jointIndex, const glm::quat& delta, bool constrain) {
JointState& state = _jointStates[jointIndex];
const FBXJoint& joint = _geometry->getFBXGeometry().joints[jointIndex];
if (joint.rotationMin == glm::vec3(-180.0f, -180.0f, -180.0f) && joint.rotationMax == glm::vec3(180.0f, 180.0f, 180.0f)) {
if (!constrain || (joint.rotationMin == glm::vec3(-180.0f, -180.0f, -180.0f) &&
joint.rotationMax == glm::vec3(180.0f, 180.0f, 180.0f))) {
// no constraints
state.rotation = state.rotation * glm::inverse(state.combinedRotation) * delta * state.combinedRotation;
state.combinedRotation = delta * state.combinedRotation;

View file

@ -157,7 +157,7 @@ protected:
/// first free ancestor.
float getLimbLength(int jointIndex) const;
void applyRotationDelta(int jointIndex, const glm::quat& delta);
void applyRotationDelta(int jointIndex, const glm::quat& delta, bool constrain = true);
private: