• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

# Untitled

a guest Feb 20th, 2013 808 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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. }
RAW Paste Data
Top