icekontroi

Untitled

Jul 26th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. package scripts;
  2.  
  3. import org.tribot.api2007.Game;
  4. import org.tribot.api2007.Player;
  5. import org.tribot.api2007.Projection;
  6. import org.tribot.api2007.types.RSTile;
  7. import org.tribot.script.Script;
  8. import org.tribot.script.ScriptManifest;
  9. import org.tribot.script.interfaces.Painting;
  10.  
  11. import java.awt.*;
  12.  
  13. @ScriptManifest(authors = { "IceKontroI" }, category = "@ Util", name = "Projection Test", version = 0.01, description = "Recreation and testing of the Projection methods of TRiBot.")
  14.  
  15. public class ProjectionTest extends Script implements Painting {
  16.  
  17. RSTile tile = null;
  18.  
  19. @Override
  20. public void run() {
  21.  
  22. tile = Player.getPosition();
  23.  
  24. tile = new RSTile(tile.getX() + 1, tile.getY());
  25.  
  26. while (true) sleep(1000);
  27. }
  28.  
  29. @Override
  30. public void onPaint(Graphics G) {
  31.  
  32. G.setColor(Color.white);
  33.  
  34. G.drawString("Viewport scale: " + Game.getViewportScale(), 300, 300);
  35.  
  36. Point p1 = tileToScreen(tile, 0, 0);
  37. Point p2 = tileToScreen(tile, 1, 0);
  38. Point p3 = tileToScreen(tile, 0, 1);
  39. Point p4 = tileToScreen(tile, 1, 1);
  40.  
  41. // PAINT ALL 4 CORNERS OF THE TILE
  42.  
  43. G.setColor(Color.green);
  44.  
  45. G.fillOval(p1.x, p1.y, 7, 7);
  46. G.fillOval(p2.x, p2.y, 7, 7);
  47. G.fillOval(p3.x, p3.y, 7, 7);
  48. G.fillOval(p4.x, p4.y, 7, 7);
  49.  
  50. // THEN PAINT TRIBOT'S PROJECTION BOX FOR COMPARISON
  51.  
  52. G.setColor(Color.blue);
  53.  
  54. G.drawPolygon(Projection.getTileBoundsPoly(tile, 0));
  55. }
  56.  
  57. int[] SIN = new int[2048];
  58. int[] COS = new int[2048];
  59.  
  60. {
  61. for (int i = 0; i < 2048; i++) {
  62. SIN[i] = (int) (65536.0D * Math.sin((double) i * 0.0030679615D));
  63. COS[i] = (int) (65536.0D * Math.cos((double) i * 0.0030679615D));
  64. }
  65. }
  66.  
  67. public Point tileToScreen(RSTile tile, double dx, double dy) {
  68.  
  69. return tileToCamera((int) ((tile.getX() - Game.getBaseX() + dx) * 128), (int) ((tile.getY() - Game.getBaseY() + dy) * 128), Projection.getTileHeight(tile));
  70. }
  71.  
  72. public Point tileToCamera(int x, int y, int height) {
  73.  
  74. if (x < 128 || y < 128 || x > 13056 || y > 13056) {
  75. return new Point(-1, -1);
  76. }
  77.  
  78. int z = height;
  79.  
  80. x -= Game.getCameraX();
  81. y -= Game.getCameraY();
  82. z -= Game.getCameraZ();
  83.  
  84. int sinP = SIN[Game.getCameraPitch()];
  85. int cosP = COS[Game.getCameraPitch()];
  86. int sinY = SIN[Game.getCameraYaw()];
  87. int cosY = COS[Game.getCameraYaw()];
  88.  
  89. int angle = y * sinY + x * cosY >> 16;
  90.  
  91. y = y * cosY - x * sinY >> 16;
  92. x = angle;
  93. angle = z * cosP - y * sinP >> 16;
  94. y = z * sinP + y * cosP >> 16;
  95.  
  96. if (y >= 50) {
  97.  
  98. int tempX = 256 + (x << 9) / y;
  99. int tempY = (angle << 9) / y + 167;
  100.  
  101. int centerX = Game.getViewportWidth() / 2;
  102. int centerY = Game.getViewportHeight() / 2;
  103.  
  104. int finalX = (int) ((tempX - centerX) * (Game.getViewportScale() / 512.0));
  105. int finalY = (int) ((tempY - centerY) * (Game.getViewportScale() / 512.0));
  106.  
  107. return new Point(finalX + centerX, finalY + centerY);
  108. }
  109.  
  110. return new Point(-1, -1);
  111. }
  112. }
Add Comment
Please, Sign In to add comment