Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /**
  2. * jme3 implementation of the c++ quaternion spherical linear interpolation from wikipedia
  3. * modified by @author JDC, to return v1 if they are close together
  4. *
  5. * DOT_THRESHOLD should be something like 0.9995f, adjust per se
  6. *
  7. * @param v0 - start quaternion
  8. * @param v1 - end quaternion
  9. * @param t - scale between
  10. * @return
  11. */
  12. public static Quaternion jqSlerp2(Quaternion v0, Quaternion v1, float t) {
  13. v0.normalizeLocal();
  14. v1.normalizeLocal();
  15.  
  16. float dot = v0.dot(v1);
  17.  
  18. if (dot < 0.0f) {
  19. v1.negate();
  20. dot = -dot;
  21. }
  22.  
  23. if (dot > DOT_THRESHOLD) {
  24. return v1;
  25. }
  26.  
  27. float theta_0 = FastMath.acos(dot);
  28. float theta = theta_0 * t;
  29. float sin_theta = FastMath.sin(theta);
  30. float sin_theta_0 = FastMath.sin(theta_0);
  31.  
  32. float s0 = FastMath.cos(theta) - dot * sin_theta / sin_theta_0;
  33. float s1 = sin_theta / sin_theta_0;
  34.  
  35. return new Quaternion(v0.multLocal(s0)).addLocal(v1.multLocal(s1));
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement