From d78f253d24063a0c3d4cea95ff8e92bb28a04e60 Mon Sep 17 00:00:00 2001 From: amantley Date: Fri, 15 Feb 2019 17:43:53 -0800 Subject: [PATCH] code to generate pole vector from theta --- interface/src/avatar/MyAvatar.cpp | 7 ++--- .../src/AnimPoleVectorConstraint.cpp | 5 ++-- libraries/animation/src/Rig.cpp | 30 ++++++++++++++----- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index ea5f2163fe..c2e7292a0a 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2943,8 +2943,7 @@ void MyAvatar::setAnimGraphUrl(const QUrl& url) { connect(&(_skeletonModel->getRig()), SIGNAL(onLoadComplete()), this, SLOT(animGraphLoaded())); } -#define FAKE_Q_OS_ANDROID - +#define USE_Q_OS_ANDROID void MyAvatar::initAnimGraph() { QUrl graphUrl; if (!_prefOverrideAnimGraphUrl.get().isEmpty()) { @@ -2953,8 +2952,8 @@ void MyAvatar::initAnimGraph() { graphUrl = _fstAnimGraphOverrideUrl; } else { graphUrl = PathUtils::resourcesUrl("avatar/avatar-animation.json"); - //#ifdef FAKE_Q_OS_ANDROID - #ifdef Q_OS_ANDROID + + #if defined(Q_OS_ANDROID) || defined(USE_Q_OS_ANDROID) graphUrl = PathUtils::resourcesUrl("avatar/avatar-animation_withSplineIKNode.json"); #endif } diff --git a/libraries/animation/src/AnimPoleVectorConstraint.cpp b/libraries/animation/src/AnimPoleVectorConstraint.cpp index 998368a0c6..505471efdd 100644 --- a/libraries/animation/src/AnimPoleVectorConstraint.cpp +++ b/libraries/animation/src/AnimPoleVectorConstraint.cpp @@ -13,7 +13,7 @@ #include "AnimUtil.h" #include "GLMHelpers.h" -#define FAKE_Q_OS_ANDROID true; +#define USE_Q_OS_ANDROID const float FRAMES_PER_SECOND = 30.0f; const float INTERP_DURATION = 6.0f; @@ -114,8 +114,7 @@ const AnimPoseVec& AnimPoleVectorConstraint::evaluate(const AnimVariantMap& anim glm::vec3 poleVectorProj = poleVector - glm::dot(poleVector, unitAxis) * unitAxis; float poleVectorProjLength = glm::length(poleVectorProj); -//#ifdef FAKE_Q_OS_ANDROID -#ifdef Q_OS_ANDROID +#if defined(Q_OS_ANDROID) || defined(USE_Q_OS_ANDROID) // get theta set by optimized ik for Quest if ((_skeleton->nameToJointIndex("RightHand") == _tipJointIndex) || (_skeleton->nameToJointIndex("LeftHand") == _tipJointIndex)) { diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index e224c4f571..ab35186bfd 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -34,8 +34,7 @@ #include "IKTarget.h" #include "PathUtils.h" -#define FAKE_Q_OS_ANDROID true; - +#define USE_Q_OS_ANDROID static int nextRigId = 1; static std::map rigRegistry; static std::mutex rigRegistryMutex; @@ -1460,8 +1459,7 @@ void Rig::updateHands(bool leftHandEnabled, bool rightHandEnabled, bool hipsEnab int elbowJointIndex = _animSkeleton->nameToJointIndex("LeftForeArm"); int oppositeArmJointIndex = _animSkeleton->nameToJointIndex("RightArm"); if (ENABLE_POLE_VECTORS && handJointIndex >= 0 && armJointIndex >= 0 && elbowJointIndex >= 0 && oppositeArmJointIndex >= 0) { - //#ifdef FAKE_Q_OS_ANDROID - #ifdef Q_OS_ANDROID + #if defined(Q_OS_ANDROID) || defined(USE_Q_OS_ANDROID) bool isLeft = true; float poleTheta; bool usePoleTheta = calculateElbowPoleVectorOptimized(handJointIndex, elbowJointIndex, armJointIndex, isLeft, poleTheta); @@ -1531,9 +1529,8 @@ void Rig::updateHands(bool leftHandEnabled, bool rightHandEnabled, bool hipsEnab if (ENABLE_POLE_VECTORS && handJointIndex >= 0 && armJointIndex >= 0 && elbowJointIndex >= 0 && oppositeArmJointIndex >= 0) { - //#ifdef FAKE_Q_OS_ANDROID - #ifdef Q_OS_ANDROID - isLeft = false; + #if defined(Q_OS_ANDROID) || defined(USE_Q_OS_ANDROID) + bool isLeft = false; float poleTheta; bool usePoleTheta = calculateElbowPoleVectorOptimized(handJointIndex, elbowJointIndex, armJointIndex, isLeft, poleTheta); if (usePoleTheta) { @@ -1848,7 +1845,7 @@ bool Rig::calculateElbowPoleVectorOptimized(int handIndex, int elbowIndex, int s } if (!left) { - qCDebug(animation) << "flex ave: " << (_flexThetaRunningAverageRight / PI) * 180.0f << " twist ave: " << (_twistThetaRunningAverageRight / PI) * 180.0f << " ulnar deviation ave: " << (_ulnarRadialThetaRunningAverageRight / PI) * 180.0f; + //qCDebug(animation) << "flex ave: " << (_flexThetaRunningAverageRight / PI) * 180.0f << " twist ave: " << (_twistThetaRunningAverageRight / PI) * 180.0f << " ulnar deviation ave: " << (_ulnarRadialThetaRunningAverageRight / PI) * 180.0f; } const float POWER = 2.0f; @@ -1995,6 +1992,23 @@ bool Rig::calculateElbowPoleVectorOptimized(int handIndex, int elbowIndex, int s poleTheta = thetaRadians; } + float xValue = sin(poleTheta); + float yValue = cos(poleTheta); + float zValue = 0.0f; + glm::vec3 thetaVector(xValue, yValue, zValue); + glm::vec3 xAxis = glm::cross(Vectors::UNIT_Y, armToHand); + glm::vec3 up = glm::cross(armToHand, xAxis); + glm::quat armAxisRotation; + glm::vec3 u, v, w; + glm::vec3 fwd = armToHand/glm::length(armToHand); + + generateBasisVectors(Vectors::UNIT_Y, fwd, u, v, w); + AnimPose armAxisPose(glm::mat4(glm::vec4(w, 0.0f), glm::vec4(u, 0.0f), glm::vec4(v, 0.0f), glm::vec4(glm::vec3(0.0f, 0.0f, 0.0f), 1.0f))); + glm::vec3 pole = armAxisPose * thetaVector; + + qCDebug(animation) << "the pole from theta is " << pole; + + return true; }