Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import org.tribot.api2007.Game;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Projection;
- import org.tribot.api2007.types.RSTile;
- import org.tribot.script.Script;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.Painting;
- import java.awt.*;
- @ScriptManifest(authors = { "IceKontroI" }, category = "@ Util", name = "Projection Test", version = 0.01, description = "Recreation and testing of the Projection methods of TRiBot.")
- public class ProjectionTest extends Script implements Painting {
- RSTile tile = null;
- @Override
- public void run() {
- tile = Player.getPosition();
- tile = new RSTile(tile.getX() + 1, tile.getY());
- while (true) sleep(1000);
- }
- @Override
- public void onPaint(Graphics G) {
- G.setColor(Color.white);
- G.drawString("Viewport scale: " + Game.getViewportScale(), 300, 300);
- Point p1 = tileToScreen(tile, 0, 0);
- Point p2 = tileToScreen(tile, 1, 0);
- Point p3 = tileToScreen(tile, 0, 1);
- Point p4 = tileToScreen(tile, 1, 1);
- // PAINT ALL 4 CORNERS OF THE TILE
- G.setColor(Color.green);
- G.fillOval(p1.x, p1.y, 7, 7);
- G.fillOval(p2.x, p2.y, 7, 7);
- G.fillOval(p3.x, p3.y, 7, 7);
- G.fillOval(p4.x, p4.y, 7, 7);
- // THEN PAINT TRIBOT'S PROJECTION BOX FOR COMPARISON
- G.setColor(Color.blue);
- G.drawPolygon(Projection.getTileBoundsPoly(tile, 0));
- }
- int[] SIN = new int[2048];
- int[] COS = new int[2048];
- {
- for (int i = 0; i < 2048; i++) {
- SIN[i] = (int) (65536.0D * Math.sin((double) i * 0.0030679615D));
- COS[i] = (int) (65536.0D * Math.cos((double) i * 0.0030679615D));
- }
- }
- public Point tileToScreen(RSTile tile, double dx, double dy) {
- return tileToCamera((int) ((tile.getX() - Game.getBaseX() + dx) * 128), (int) ((tile.getY() - Game.getBaseY() + dy) * 128), Projection.getTileHeight(tile));
- }
- public Point tileToCamera(int x, int y, int height) {
- if (x < 128 || y < 128 || x > 13056 || y > 13056) {
- return new Point(-1, -1);
- }
- int z = height;
- x -= Game.getCameraX();
- y -= Game.getCameraY();
- z -= Game.getCameraZ();
- int sinP = SIN[Game.getCameraPitch()];
- int cosP = COS[Game.getCameraPitch()];
- int sinY = SIN[Game.getCameraYaw()];
- int cosY = COS[Game.getCameraYaw()];
- int angle = y * sinY + x * cosY >> 16;
- y = y * cosY - x * sinY >> 16;
- x = angle;
- angle = z * cosP - y * sinP >> 16;
- y = z * sinP + y * cosP >> 16;
- if (y >= 50) {
- int tempX = 256 + (x << 9) / y;
- int tempY = (angle << 9) / y + 167;
- int centerX = Game.getViewportWidth() / 2;
- int centerY = Game.getViewportHeight() / 2;
- int finalX = (int) ((tempX - centerX) * (Game.getViewportScale() / 512.0));
- int finalY = (int) ((tempY - centerY) * (Game.getViewportScale() / 512.0));
- return new Point(finalX + centerX, finalY + centerY);
- }
- return new Point(-1, -1);
- }
- }
Add Comment
Please, Sign In to add comment