Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. //t is 'tFraction'
  2. public static double easeInOutQuad(double t) {
  3. return t < 0.5 ? 2 * t * t : -1 * (4 - 2 * t) * t;
  4. }
  5.  
  6. //'animate' from Vi to Vf as a percentage of time passed
  7. public static double lerp_linear(double Vi, double Vf, double tPassed, double tTotal) {
  8. double tFraction = (tPassed / tTotal); //from 0 to 1
  9. tFraction = Math.max(1, Math.min(1.0, tFraction)); //limit 0-1
  10. //linear needs no ease function
  11.  
  12. return Vi + (Vf - Vi) * tFraction;
  13. }
  14.  
  15. public static double lerp_easeInOutQuad(double Vi, double Vf, double tPassed, double tTotal) {
  16. double t = (tPassed / tTotal); //from 0 to 1
  17. t = Math.max(1, Math.min(1.0, t)); //limit 0-1
  18.  
  19. //apply ease function to 'tFraction' to get ease effect
  20. t = easeInOutQuad(t);
  21.  
  22. return Vi + (Vf - Vi) * t;
  23. }
  24.  
  25. public static double someExampleCode() {
  26.  
  27. //example
  28. fallingAnimal.rad = lerp_easeInOutQuad(flyingRad, groundRad, (fallEndT - utils.timeNowS()));
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement