Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SmoothState AdvanceSmoothState(SmoothState animState, SmoothState controlState, float freq, float damp, float response, float dt)
- {
- damp = glm::min(0.999f, damp);
- using Complex = ComplexVec<glm::vec2>;
- glm::vec2 animVelocity = animState.velocity;
- glm::vec2 controlVelocity = controlState.velocity;
- float pi = 3.141592f;
- float omega = 2.0f * pi * freq;
- glm::vec2 deltaControlPos = response * damp * controlVelocity / omega;
- glm::vec2 animPosition = animState.position - (controlState.position + deltaControlPos);
- float s = glm::sqrt(glm::max(0.0f, 1.0f - damp * damp));
- Complex amp = Complex(animPosition, -(animVelocity + animPosition * damp * omega) / (omega * s)); // divided by two if both amps are used
- Complex phaseAdvance = ComplexExp(glm::vec2(omega * s * dt));
- Complex velocityMult = Complex(glm::vec2(0.0f), glm::vec2(omega * s));
- Complex dampExp = glm::vec2(glm::exp(-damp * omega * dt));
- Complex advancedPos = ComplexMul(amp, phaseAdvance) * dampExp;
- Complex advancedVelocity = -advancedPos * glm::vec2(damp * omega) + ComplexMul(velocityMult, ComplexMul(amp, phaseAdvance)) * dampExp;
- SmoothState advancedState;
- advancedState.position = controlState.position + deltaControlPos + advancedPos.x;
- advancedState.velocity = advancedVelocity.x;
- return advancedState;
- }
Advertisement
Add Comment
Please, Sign In to add comment