From ca07b3ef6fbc6fd507fd54981860de07f54c7ab2 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sun, 28 Oct 2018 17:00:41 +0800 Subject: [PATCH] Fix hand pose Considering the hand direction when calculate the base plane of rotation. --- src/tetrapodposer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tetrapodposer.cpp b/src/tetrapodposer.cpp index bed80f9a..3cd07138 100644 --- a/src/tetrapodposer.cpp +++ b/src/tetrapodposer.cpp @@ -35,7 +35,13 @@ void TetrapodPoser::commit() const RiggerBone &bone = bones()[boneIndex]; if (bone.name == "LeftHand" || bone.name == "RightHand") { QVector3D handDirection = bone.tailPosition - bone.headPosition; - QVector3D rotateAxis = QVector3D::crossProduct(handDirection, bone.name == "RightHand" ? QVector3D(1, 0, 0) : QVector3D(-1, 0, 0)).normalized(); + QVector3D referenceDirection = bone.name == "RightHand" ? QVector3D(1, 0, 0) : QVector3D(-1, 0, 0); + auto angleWithX = (int)angleBetweenVectors(handDirection, -referenceDirection); + auto angleWithZ = (int)angleBetweenVectors(handDirection, QVector3D(0, 0, -1)); + qDebug() << "angleWithX:" << angleWithX << "angleWithZ:" << angleWithZ; + QVector3D rotateAxis = angleWithX < angleWithZ ? + QVector3D::crossProduct(handDirection, referenceDirection).normalized() : + QVector3D::crossProduct(handDirection, QVector3D(0, 0, -1)).normalized(); QQuaternion rotation = QQuaternion::fromAxisAndAngle(rotateAxis, intersectionAngle); m_jointNodeTree.updateRotation(boneIndex, rotation); continue;