Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 20th, 2013  |  syntax: C++  |  size: 0.99 KB  |  views: 792  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // A bit of code from some camera-path stabilization code
  2.  
  3. void Path::computeSteps(FloatFunction velocity, float totalLength, float stepTime) {
  4.   float curTime = 0.0f;
  5.   float curLength = 0.0f;
  6.   steps.push_back(Vector2(fx(curTime), fy(curTime)));
  7.  
  8.   while(curLength < totalLength) {
  9.     float vel = velocity(curTime);
  10.     float s = vel * stepTime;
  11.  
  12.     std::cout << "S: " << s << std::endl;
  13.     std::cout << "CurTime: " << curTime << std::endl;
  14.    
  15.     // Oh God Why
  16.     float nextTime = findZero([&](float x){
  17.         return romberg([&](float y){
  18.             return sqrt(pow(derivative([&](float z){
  19.                     return fx(z);}, y), 2) + pow(derivative([&](float z) {
  20.                           return fy(z);}, y), 2));}
  21.             , curTime, x, 3) - s;}
  22.         , curTime + 2 * curTime + 0.01);
  23.  
  24.     curTime = nextTime;
  25.     std::cout << "NextTime: " << nextTime << std::endl;
  26.     curLength += s;
  27.     steps.push_back(Vector2(fx(curTime), fy(curTime)));
  28.   }
  29.   if(forward)
  30.     position = steps.begin();
  31.   else
  32.     position = steps.end();
  33. }
clone this paste RAW Paste Data