From f0379740ca58a99527a64b142161605d4cafc7cb Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Wed, 7 Nov 2018 23:46:26 +0800 Subject: [PATCH] Fix wrong middle bone index --- src/animalposer.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/animalposer.cpp b/src/animalposer.cpp index b6a5fb8c..95d6d705 100644 --- a/src/animalposer.cpp +++ b/src/animalposer.cpp @@ -127,9 +127,10 @@ void AnimalPoser::resolveChainRotation(const std::vector &limbBoneNames qDebug() << middleBoneName << "'s positions not found"; return; } - - float matchLimbLength = (matchBeginBonePositions.second.first - matchBeginBonePositions.second.second).length() + - (matchMiddleBonePositions.second.first - matchMiddleBonePositions.second.second).length(); + + float matchBeginBoneLength = (matchBeginBonePositions.second.first - matchBeginBonePositions.second.second).length(); + float matchMiddleBoneLength = (matchMiddleBonePositions.second.first - matchMiddleBonePositions.second.second).length(); + float matchLimbLength = matchBeginBoneLength + matchMiddleBoneLength; auto matchDistanceBetweenBeginAndEndBones = (matchBeginBonePositions.second.first - matchMiddleBonePositions.second.second).length(); auto matchRotatePlaneNormal = QVector3D::crossProduct((matchBeginBonePositions.second.second - matchBeginBonePositions.second.first).normalized(), (matchMiddleBonePositions.second.second - matchBeginBonePositions.second.second).normalized()); @@ -148,14 +149,12 @@ void AnimalPoser::resolveChainRotation(const std::vector &limbBoneNames qDebug() << middleBoneName << "not found in rigged bones"; return; } - const auto &middleBone = bones()[beginBoneIndex]; + const auto &middleBone = bones()[middleBoneIndex]; float targetBeginBoneLength = (beginBone.headPosition - beginBone.tailPosition).length(); float targetMiddleBoneLength = (middleBone.headPosition - middleBone.tailPosition).length(); float targetLimbLength = targetBeginBoneLength + targetMiddleBoneLength; - //qDebug() << beginBoneName << "targetLimbLength:" << targetLimbLength << "matchLimbLength:" << matchLimbLength; - float targetDistanceBetweenBeginAndEndBones = matchDistanceBetweenBeginAndEndBones * (targetLimbLength / matchLimbLength); QVector3D targetEndBoneStartPosition = beginBone.headPosition + matchDirectionBetweenBeginAndEndPones * targetDistanceBetweenBeginAndEndBones;