Guest User

Untitled

a guest
Aug 27th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package net.minefs.MineStrike.Map;
  2.  
  3. import org.bukkit.Location;
  4.  
  5. public class MapPosition {
  6. public int x, y;
  7.  
  8. public MapPosition(int x, int y) {
  9. this.x = x;
  10. this.y = y;
  11. }
  12.  
  13. // Khởi tạo vị trí bản đồ dựa trên vị trí thực
  14. // l: vị trí người chơi (người xem bản đồ)
  15. // el: vị trí cần chuyển đổi
  16. // rad: góc quay của người chơi tính theo radian
  17. public static MapPosition calculatedPos(Location l, Location el, double rad) {
  18. // 2 là scale của map
  19. double xe = (el.getX() - l.getX()) * 2;
  20. double ye = (el.getZ() - l.getZ()) * 2;
  21.  
  22. // Công thức quay
  23. int xe1 = (int) Math.round(xe * Math.cos(rad) - ye * Math.sin(rad));
  24. int ye1 = (int) Math.round(ye * Math.cos(rad) + xe * Math.sin(rad));
  25.  
  26. // Nếu xe1, ye1 nằm ngoài map thì di chuyển lại gần rìa
  27. if (xe1 < -63)
  28. xe1 = -63;
  29. if (xe1 > 63)
  30. xe1 = 63;
  31. if (ye1 < -63)
  32. ye1 = -63;
  33. if (ye1 > 63)
  34. ye1 = 63;
  35.  
  36. // Chuyển tâm O(0,0) lên góc trên trái, thay vì ban đầu tâm O nằm ở tọa độ 64,64 trên bản đồ
  37. xe1 += 64;
  38. ye1 += 64;
  39. return new MapPosition(xe1, ye1);
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment