mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 20:58:38 +02:00
Simplify fade normalization, eliminating a loop.
This commit is contained in:
parent
653e46fdd3
commit
f51b5be167
1 changed files with 8 additions and 18 deletions
|
@ -464,35 +464,25 @@ void Rig::updateAnimations(float deltaTime, glm::mat4 parentTransform) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// collect the remaining fade data
|
// sum the remaining fade data
|
||||||
float fadeSum = 0.0f;
|
float fadeTotal = 0.0f;
|
||||||
std::vector<float> normalizedFades(_runningAnimations.count());
|
|
||||||
int animationIndex = 0;
|
|
||||||
foreach (const AnimationHandlePointer& handle, _runningAnimations) {
|
foreach (const AnimationHandlePointer& handle, _runningAnimations) {
|
||||||
float fade = handle->getFade();
|
fadeTotal += handle->getFade();
|
||||||
normalizedFades[animationIndex++] = fade;
|
|
||||||
fadeSum += fade;
|
|
||||||
}
|
}
|
||||||
// normalize our copy of the fade data
|
float fadeSumSoFar = 0.0f;
|
||||||
for (int i = 0; i < _runningAnimations.count(); i++) {
|
|
||||||
normalizedFades[i] /= fadeSum;
|
|
||||||
}
|
|
||||||
// set the mix based on the normalized fade data
|
|
||||||
animationIndex = 0;
|
|
||||||
fadeSum = 0.0f;
|
|
||||||
foreach (const AnimationHandlePointer& handle, _runningAnimations) {
|
foreach (const AnimationHandlePointer& handle, _runningAnimations) {
|
||||||
handle->setPriority(1.0f);
|
handle->setPriority(1.0f);
|
||||||
float normalizedFade = normalizedFades[animationIndex++];
|
float normalizedFade = handle->getFade() / fadeTotal;
|
||||||
// simulate() will blend each animation result into the result so far, based on the pairwise mix at at each step.
|
// simulate() will blend each animation result into the result so far, based on the pairwise mix at at each step.
|
||||||
// i.e., slerp the 'mix' distance from the result so far towards this iteration's animation result.
|
// i.e., slerp the 'mix' distance from the result so far towards this iteration's animation result.
|
||||||
// The formula here for mix is based on the idea that, at each step:
|
// The formula here for mix is based on the idea that, at each step:
|
||||||
// fadeSum is to normalizedFade, as (1 - mix) is to mix
|
// fadeSum is to normalizedFade, as (1 - mix) is to mix
|
||||||
// i.e., fadeSum/normalizedFade = (1 - mix)/mix
|
// i.e., fadeSumSoFar/normalizedFade = (1 - mix)/mix
|
||||||
// Then we solve for mix.
|
// Then we solve for mix.
|
||||||
// Sanity check: For the first animation, fadeSum = 0, and the mix will always be 1.
|
// Sanity check: For the first animation, fadeSum = 0, and the mix will always be 1.
|
||||||
// Sanity check: For equal blending, the formula is equivalent to mix = 1 / nAnimationsSoFar++
|
// Sanity check: For equal blending, the formula is equivalent to mix = 1 / nAnimationsSoFar++
|
||||||
float mix = 1.0f / ((fadeSum / normalizedFade) + 1.0f);
|
float mix = 1.0f / ((fadeSumSoFar / normalizedFade) + 1.0f);
|
||||||
fadeSum += normalizedFade;
|
fadeSumSoFar += normalizedFade;
|
||||||
handle->setMix(mix);
|
handle->setMix(mix);
|
||||||
handle->simulate(deltaTime);
|
handle->simulate(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue