added new constructor for cubichermitespline that takes quat and vec3. this means we don't need computeSplineFromTipAndBase to be declared in multiple files

This commit is contained in:
amantley 2019-01-31 14:13:35 -08:00
parent ffd374e7d4
commit 61b019d176
5 changed files with 28 additions and 37 deletions

View file

@ -33,20 +33,10 @@ Rig::CharacterControllerState convertCharacterControllerState(CharacterControlle
};
}
static CubicHermiteSplineFunctorWithArcLength computeSplineFromTipAndBase(const AnimPose& tipPose, const AnimPose& basePose, float baseGain = 1.0f, float tipGain = 1.0f) {
float linearDistance = glm::length(basePose.trans() - tipPose.trans());
glm::vec3 p0 = basePose.trans();
glm::vec3 m0 = baseGain * linearDistance * (basePose.rot() * Vectors::UNIT_Y);
glm::vec3 p1 = tipPose.trans();
glm::vec3 m1 = tipGain * linearDistance * (tipPose.rot() * Vectors::UNIT_Y);
return CubicHermiteSplineFunctorWithArcLength(p0, m0, p1, m1);
}
static glm::vec3 computeSpine2WithHeadHipsSpline(MyAvatar* myAvatar, AnimPose hipsIKTargetPose, AnimPose headIKTargetPose) {
// the the ik targets to compute the spline with
CubicHermiteSplineFunctorWithArcLength splineFinal = computeSplineFromTipAndBase(headIKTargetPose, hipsIKTargetPose);
CubicHermiteSplineFunctorWithArcLength splineFinal(headIKTargetPose.rot(), headIKTargetPose.trans(), hipsIKTargetPose.rot(), hipsIKTargetPose.trans());
// measure the total arc length along the spline
float totalArcLength = splineFinal.arcLength(1.0f);

View file

@ -287,16 +287,6 @@ void AnimSplineIK::setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) {
lookUpIndices();
}
static CubicHermiteSplineFunctorWithArcLength computeSplineFromTipAndBase(const AnimPose& tipPose, const AnimPose& basePose, float baseGain = 1.0f, float tipGain = 1.0f) {
float linearDistance = glm::length(basePose.trans() - tipPose.trans());
glm::vec3 p0 = basePose.trans();
glm::vec3 m0 = baseGain * linearDistance * (basePose.rot() * Vectors::UNIT_Y);
glm::vec3 p1 = tipPose.trans();
glm::vec3 m1 = tipGain * linearDistance * (tipPose.rot() * Vectors::UNIT_Y);
return CubicHermiteSplineFunctorWithArcLength(p0, m0, p1, m1);
}
void AnimSplineIK::solveTargetWithSpline(const AnimContext& context, int base, const IKTarget& target, const AnimPoseVec& absolutePoses, bool debug, AnimChain& chainInfoOut) const {
// build spline from tip to base
@ -308,9 +298,9 @@ void AnimSplineIK::solveTargetWithSpline(const AnimContext& context, int base, c
// set gain factors so that more curvature occurs near the tip of the spline.
const float HIPS_GAIN = 0.5f;
const float HEAD_GAIN = 1.0f;
spline = computeSplineFromTipAndBase(tipPose, basePose, HIPS_GAIN, HEAD_GAIN);
spline = CubicHermiteSplineFunctorWithArcLength(tipPose.rot(), tipPose.trans(), basePose.rot(), basePose.trans(), HIPS_GAIN, HEAD_GAIN);
} else {
spline = computeSplineFromTipAndBase(tipPose, basePose);
spline = CubicHermiteSplineFunctorWithArcLength(tipPose.rot(),tipPose.trans(), basePose.rot(), basePose.trans());
}
float totalArcLength = spline.arcLength(1.0f);
@ -437,9 +427,9 @@ void AnimSplineIK::computeAndCacheSplineJointInfosForIKTarget(const AnimContext&
// set gain factors so that more curvature occurs near the tip of the spline.
const float HIPS_GAIN = 0.5f;
const float HEAD_GAIN = 1.0f;
spline = computeSplineFromTipAndBase(tipPose, basePose, HIPS_GAIN, HEAD_GAIN);
spline = CubicHermiteSplineFunctorWithArcLength(tipPose.rot(), tipPose.trans(), basePose.rot(), basePose.trans(), HIPS_GAIN, HEAD_GAIN);
} else {
spline = computeSplineFromTipAndBase(tipPose, basePose);
spline = CubicHermiteSplineFunctorWithArcLength(tipPose.rot(), tipPose.trans(), basePose.rot(), basePose.trans());
}
// measure the total arc length along the spline
float totalArcLength = spline.arcLength(1.0f);

View file

@ -35,7 +35,7 @@ public:
bool getPoleVectorEnabled() const { return _poleVectorEnabled; }
int getIndex() const { return _index; }
Type getType() const { return _type; }
int getNumFlexCoefficients() const { return _numFlexCoefficients; }
int getNumFlexCoefficients() const { return (int)_numFlexCoefficients; }
float getFlexCoefficient(size_t chainDepth) const;
void setPose(const glm::quat& rotation, const glm::vec3& translation);

View file

@ -1962,16 +1962,6 @@ void Avatar::buildUnscaledEyeHeightCache() {
}
}
static CubicHermiteSplineFunctorWithArcLength computeSplineFromTipAndBase(const AnimPose& tipPose, const AnimPose& basePose, float baseGain = 1.0f, float tipGain = 1.0f) {
float linearDistance = glm::length(basePose.trans() - tipPose.trans());
glm::vec3 p0 = basePose.trans();
glm::vec3 m0 = baseGain * linearDistance * (basePose.rot() * Vectors::UNIT_Y);
glm::vec3 p1 = tipPose.trans();
glm::vec3 m1 = tipGain * linearDistance * (tipPose.rot() * Vectors::UNIT_Y);
return CubicHermiteSplineFunctorWithArcLength(p0, m0, p1, m1);
}
void Avatar::buildSpine2SplineRatioCache() {
if (_skeletonModel) {
auto& rig = _skeletonModel->getRig();
@ -1988,7 +1978,7 @@ void Avatar::buildSpine2SplineRatioCache() {
_spine2SplineRatio = glm::dot(baseToSpine2, baseToTipNormal) / baseToTipLength;
CubicHermiteSplineFunctorWithArcLength defaultSpline = computeSplineFromTipAndBase(headRigDefaultPose, hipsRigDefaultPose);
CubicHermiteSplineFunctorWithArcLength defaultSpline(headRigDefaultPose.rot(), headRigDefaultPose.trans(), hipsRigDefaultPose.rot(), hipsRigDefaultPose.trans());
// measure the total arc length along the spline
float totalDefaultArcLength = defaultSpline.arcLength(1.0f);

View file

@ -79,6 +79,27 @@ public:
}
}
CubicHermiteSplineFunctorWithArcLength(const glm::quat& tipRot, const glm::vec3& tipTrans, const glm::quat& baseRot, const glm::vec3& baseTrans, float baseGain = 1.0f, float tipGain = 1.0f) : CubicHermiteSplineFunctor() {
float linearDistance = glm::length(baseTrans - tipTrans);
_p0 = baseTrans;
_m0 = baseGain * linearDistance * (baseRot * Vectors::UNIT_Y);
_p1 = tipTrans;
_m1 = tipGain * linearDistance * (tipRot * Vectors::UNIT_Y);
// initialize _values with the accumulated arcLength along the spline.
const float DELTA = 1.0f / NUM_SUBDIVISIONS;
float alpha = 0.0f;
float accum = 0.0f;
_values[0] = 0.0f;
for (int i = 1; i < NUM_SUBDIVISIONS + 1; i++) {
accum += glm::distance(this->operator()(alpha),
this->operator()(alpha + DELTA));
alpha += DELTA;
_values[i] = accum;
}
}
CubicHermiteSplineFunctorWithArcLength(const CubicHermiteSplineFunctorWithArcLength& orig) : CubicHermiteSplineFunctor(orig) {
memcpy(_values, orig._values, sizeof(float) * (NUM_SUBDIVISIONS + 1));
}