Skip to content

Instantly share code, notes, and snippets.

@serguei-k
Last active April 9, 2024 02:58
Show Gist options
  • Save serguei-k/108b7326e35db5749b800f314522d3c8 to your computer and use it in GitHub Desktop.
Save serguei-k/108b7326e35db5749b800f314522d3c8 to your computer and use it in GitHub Desktop.
Variable FK 2
// ...
const float t = float(i) / float(sampleCount - 1);
for (auto j = 0; j < controlCount; ++j)
{
const float& param = controlParams[j];
const float& falloff = controlFalloffs[j];
const MVector& scale = controlScales[j];
float weight = 1.0f - std::abs(t - param) / falloff;
weight = std::max(std::min(weight, 1.0f), 0.0f);
weight = weight * weight * weight * (weight * (weight * 6 - 15) + 10);
if (weight <= 0.0f) continue;
// weighted rotation matrix
MMatrix rotation = slerp(MQuaternion::identity,
MEulerRotation(controlRotations[j]).asQuaternion(),
weight).asMatrix();
// weighted translation matrix
MMatrix txform;
const MVector translation(controlTranslations[j] * weight);
txform[3][0] = translation.x;
txform[3][1] = translation.y;
txform[3][2] = translation.z;
// weighted scale matrix
MMatrix sclxform;
sclxform[1][1] = 1.0 + (scale.y - 1.0) * weight;
sclxform[2][2] = 1.0 + (scale.z - 1.0) * weight;
// compose the full transformation
xform = rotation * xform;
sampleXform = sclxform * rotation * sampleXform * txform;
controlsHandle.next();
}
parentXform = xform;
sampleFrames.append(sampleXform);
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment