Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public Angle smoothAngle(Angle from, Angle to, float xsmooth, float ysmooth)
  2. {
  3. Angle delta = clampAngles(new Angle(from.x - to.x, from.y - to.y));
  4. delta.x *= xsmooth;
  5. delta.y *= ysmooth;
  6. return clampAngles(from.minus(delta));
  7. }
  8.  
  9. public static double normalizeAngle(double angle)
  10. {
  11. return (angle % 360.0D + 360.0D) % 360.0D;
  12. }
  13.  
  14. public Angle normalizeAngle(Angle a)
  15. {
  16. if (a.x > 180.0F) {
  17. a.x -= 360.0F;
  18. }
  19. if (a.x < -180.0F) {
  20. a.x += 360.0F;
  21. }
  22. if (a.y > 180.0F) {
  23. a.y -= 360.0F;
  24. }
  25. if (a.y < -180.0F) {
  26. a.y += 360.0F;
  27. }
  28. return a;
  29. }
  30.  
  31. public Angle clampAngles(Angle AngleToNormalize)
  32. {
  33. Angle vec = AngleToNormalize;
  34. if ((vec.x() > 89.0F) && (vec.x() <= 180.0F)) {
  35. vec.setX(89.0F);
  36. }
  37. while (vec.x() > 180.0F) {
  38. vec.setX(vec.x() - 360.0F);
  39. }
  40. while (vec.x() < -89.0F) {
  41. vec.setX(-89.0F);
  42. }
  43. while (vec.y() > 180.0F) {
  44. vec.setY(vec.x() - 360.0F);
  45. }
  46. while (vec.y() < -180.0F) {
  47. vec.setY(vec.y() + 360.0F);
  48. }
  49. return vec;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement