Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minefs.MineStrike.Map;
- import org.bukkit.Location;
- public class MapPosition {
- public int x, y;
- public MapPosition(int x, int y) {
- this.x = x;
- this.y = y;
- }
- // Khởi tạo vị trí bản đồ dựa trên vị trí thực
- // l: vị trí người chơi (người xem bản đồ)
- // el: vị trí cần chuyển đổi
- // rad: góc quay của người chơi tính theo radian
- public static MapPosition calculatedPos(Location l, Location el, double rad) {
- // 2 là scale của map
- double xe = (el.getX() - l.getX()) * 2;
- double ye = (el.getZ() - l.getZ()) * 2;
- // Công thức quay
- int xe1 = (int) Math.round(xe * Math.cos(rad) - ye * Math.sin(rad));
- int ye1 = (int) Math.round(ye * Math.cos(rad) + xe * Math.sin(rad));
- // Nếu xe1, ye1 nằm ngoài map thì di chuyển lại gần rìa
- if (xe1 < -63)
- xe1 = -63;
- if (xe1 > 63)
- xe1 = 63;
- if (ye1 < -63)
- ye1 = -63;
- if (ye1 > 63)
- ye1 = 63;
- // 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 đồ
- xe1 += 64;
- ye1 += 64;
- return new MapPosition(xe1, ye1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment