Guest User

Untitled

a guest
Jul 5th, 2022
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1.   SmoothState AdvanceSmoothState(SmoothState animState, SmoothState controlState, float freq, float damp, float response, float dt)
  2.   {
  3.     damp = glm::min(0.999f, damp);
  4.     using Complex = ComplexVec<glm::vec2>;
  5.     glm::vec2 animVelocity = animState.velocity;
  6.     glm::vec2 controlVelocity = controlState.velocity;
  7.     float pi = 3.141592f;
  8.     float omega = 2.0f * pi * freq;
  9.  
  10.     glm::vec2 deltaControlPos = response * damp * controlVelocity / omega;
  11.     glm::vec2 animPosition = animState.position - (controlState.position + deltaControlPos);
  12.  
  13.     float s = glm::sqrt(glm::max(0.0f, 1.0f - damp * damp));
  14.     Complex amp = Complex(animPosition, -(animVelocity + animPosition * damp * omega) / (omega * s)); // divided by two if both amps are used
  15.  
  16.     Complex phaseAdvance = ComplexExp(glm::vec2(omega * s * dt));
  17.  
  18.     Complex velocityMult = Complex(glm::vec2(0.0f), glm::vec2(omega * s));
  19.  
  20.     Complex dampExp = glm::vec2(glm::exp(-damp * omega * dt));
  21.     Complex advancedPos = ComplexMul(amp, phaseAdvance) * dampExp;
  22.     Complex advancedVelocity = -advancedPos * glm::vec2(damp * omega) + ComplexMul(velocityMult, ComplexMul(amp, phaseAdvance)) * dampExp;
  23.  
  24.     SmoothState advancedState;
  25.     advancedState.position = controlState.position + deltaControlPos + advancedPos.x;
  26.     advancedState.velocity = advancedVelocity.x;
  27.     return advancedState;
  28.   }
Advertisement
Add Comment
Please, Sign In to add comment