Advertisement
snake5

lerp + delta time

Nov 18th, 2013
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //// CODE
  2.  
  3. include "math";
  4.  
  5. function lerp(a,b,t){return a+(b-a)*t;}
  6.  
  7. from = 5;
  8. to = 7;
  9. factor = 0.5;
  10.  
  11. x = from;
  12. delta = 0.1;
  13. println( "from = 5, to = 7, factor = 0.5" );
  14. println( "10 frames" );
  15. for( i = 0; i < 10; ++i )
  16. {
  17.     x = lerp( x, to, 1 - pow( factor, delta ) );
  18.     println( "frame "$i+1$" / 10: "$x );
  19. }
  20.  
  21. x = from;
  22. delta = 0.05;
  23. println( "20 frames" );
  24. for( i = 0; i < 20; ++i )
  25. {
  26.     x = lerp( x, to, 1 - pow( factor, delta ) );
  27.     println( "frame "$i+1$" / 10: "$x );
  28. }
  29.  
  30.  
  31. //// RESULTS
  32. from = 5, to = 7, factor = 0.5
  33. 10 frames
  34. frame 1 / 10: 5.13393
  35. frame 2 / 10: 5.2589
  36. frame 3 / 10: 5.3755
  37. frame 4 / 10: 5.48428
  38. frame 5 / 10: 5.58579
  39. frame 6 / 10: 5.68049
  40. frame 7 / 10: 5.76886
  41. frame 8 / 10: 5.8513
  42. frame 9 / 10: 5.92823
  43. frame 10 / 10: 6
  44. 20 frames
  45. frame 1 / 10: 5.06813
  46. frame 2 / 10: 5.13393
  47. frame 3 / 10: 5.1975
  48. frame 4 / 10: 5.2589
  49. frame 5 / 10: 5.31821
  50. frame 6 / 10: 5.3755
  51. frame 7 / 10: 5.43083
  52. frame 8 / 10: 5.48428
  53. frame 9 / 10: 5.53591
  54. frame 10 / 10: 5.58579
  55. frame 11 / 10: 5.63396
  56. frame 12 / 10: 5.68049
  57. frame 13 / 10: 5.72544
  58. frame 14 / 10: 5.76886
  59. frame 15 / 10: 5.81079
  60. frame 16 / 10: 5.8513
  61. frame 17 / 10: 5.89043
  62. frame 18 / 10: 5.92823
  63. frame 19 / 10: 5.96474
  64. frame 20 / 10: 6
  65.  
  66. ////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement