mirror of
https://github.com/overte-org/overte.git
synced 2025-04-24 12:13:36 +02:00
Finger IK, take two.
This commit is contained in:
parent
3e4c5f84ed
commit
76d8bd0a9c
3 changed files with 8 additions and 11 deletions
|
@ -176,15 +176,10 @@ void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingerJoin
|
|||
float proportion = fingerIndices.size() / (float)fingerJointIndices.size();
|
||||
for (int i = 0; i < fingerJointIndices.size(); i++) {
|
||||
int fingerIndex = fingerIndices.at(roundf(i * proportion)).index;
|
||||
glm::vec3 fingerVector = palm.getFingers()[fingerIndex].getTipPosition() -
|
||||
palm.getFingers()[fingerIndex].getRootPosition();
|
||||
|
||||
int fingerJointIndex = fingerJointIndices.at(i);
|
||||
int fingertipJointIndex = fingertipJointIndices.at(i);
|
||||
glm::vec3 jointVector = extractTranslation(geometry.joints.at(fingertipJointIndex).bindTransform) -
|
||||
extractTranslation(geometry.joints.at(fingerJointIndex).bindTransform);
|
||||
|
||||
setJointRotation(fingerJointIndex, rotationBetween(palmRotation * jointVector, fingerVector) * palmRotation, true);
|
||||
setJointPosition(fingertipJointIndex, palm.getFingers()[fingerIndex].getTipPosition(),
|
||||
fingerJointIndex, true, -palm.getNormal());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -584,7 +584,8 @@ bool Model::getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Model::setJointPosition(int jointIndex, const glm::vec3& position, int lastFreeIndex, const glm::vec3& alignment) {
|
||||
bool Model::setJointPosition(int jointIndex, const glm::vec3& position, int lastFreeIndex,
|
||||
bool allIntermediatesFree, const glm::vec3& alignment) {
|
||||
if (jointIndex == -1 || _jointStates.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -605,7 +606,7 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position, int last
|
|||
for (int j = 1; freeLineage.at(j - 1) != lastFreeIndex; j++) {
|
||||
int index = freeLineage.at(j);
|
||||
const FBXJoint& joint = geometry.joints.at(index);
|
||||
if (!joint.isFree) {
|
||||
if (!(joint.isFree || allIntermediatesFree)) {
|
||||
continue;
|
||||
}
|
||||
JointState& state = _jointStates[index];
|
||||
|
@ -625,7 +626,8 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position, int last
|
|||
glm::vec3 projectedCenterOfMass = glm::cross(jointVector,
|
||||
glm::cross(positionSum / (j - 1.0f) - jointPosition, jointVector));
|
||||
glm::vec3 projectedAlignment = glm::cross(jointVector, glm::cross(worldAlignment, jointVector));
|
||||
if (glm::length(projectedCenterOfMass) > EPSILON && glm::length(projectedAlignment) > EPSILON) {
|
||||
const float LENGTH_EPSILON = 0.001f;
|
||||
if (glm::length(projectedCenterOfMass) > LENGTH_EPSILON && glm::length(projectedAlignment) > LENGTH_EPSILON) {
|
||||
applyRotationDelta(index, rotationBetween(projectedCenterOfMass, projectedAlignment));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ protected:
|
|||
bool getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind = false) const;
|
||||
|
||||
bool setJointPosition(int jointIndex, const glm::vec3& position, int lastFreeIndex = -1,
|
||||
const glm::vec3& alignment = glm::vec3(0.0f, -1.0f, 0.0f));
|
||||
bool allIntermediatesFree = false, const glm::vec3& alignment = glm::vec3(0.0f, -1.0f, 0.0f));
|
||||
bool setJointRotation(int jointIndex, const glm::quat& rotation, bool fromBind = false);
|
||||
|
||||
/// Restores the indexed joint to its default position.
|
||||
|
|
Loading…
Reference in a new issue