code to generate pole vector from theta

This commit is contained in:
amantley 2019-02-15 17:43:53 -08:00
parent 95530e6ba5
commit d78f253d24
3 changed files with 27 additions and 15 deletions

View file

@ -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
}

View file

@ -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)) {

View file

@ -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<int, Rig*> 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;
}