Search in sources :

Example 11 with LocalPoint

use of net.runelite.api.coords.LocalPoint in project runelite by runelite.

the class InstanceMapOverlay method drawPlayerDot.

/**
 * Draws the players position as a dot on the map.
 *
 * @param graphics graphics to be drawn to
 */
private void drawPlayerDot(Graphics2D graphics, Player player, Color dotColor, Color outlineColor) {
    LocalPoint playerLoc = player.getLocalLocation();
    Tile[][] tiles = getTiles();
    int tileX = playerLoc.getRegionX();
    // flip the y value
    int tileY = (tiles[0].length - 1) - playerLoc.getRegionY();
    int x = (int) (tileX * TILE_SIZE);
    int y = (int) (tileY * TILE_SIZE);
    graphics.setColor(dotColor);
    // draw the players point on the map
    graphics.fillRect(x, y, PLAYER_MARKER_SIZE, PLAYER_MARKER_SIZE);
    graphics.setColor(outlineColor);
    // outline
    graphics.drawRect(x, y, PLAYER_MARKER_SIZE, PLAYER_MARKER_SIZE);
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 12 with LocalPoint

use of net.runelite.api.coords.LocalPoint in project runelite by runelite.

the class RSClientMixin method getLocalDestinationLocation.

@Inject
@Override
@Nullable
public LocalPoint getLocalDestinationLocation() {
    int regionX = getDestinationX();
    int regionY = getDestinationY();
    if (regionX != 0 && regionY != 0) {
        return LocalPoint.fromRegion(regionX, regionY);
    }
    return null;
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject) Nullable(javax.annotation.Nullable)

Example 13 with LocalPoint

use of net.runelite.api.coords.LocalPoint in project runelite by runelite.

the class Perspective method worldToMiniMap.

/**
 * Translates two-dimensional ground coordinates within the 3D world to
 * their corresponding coordinates on the Minimap.
 *
 * @param client
 * @param x ground coordinate on the x axis
 * @param y ground coordinate on the y axis
 * @param distance max distance from local player to minimap point
 * @return a {@link Point} on screen corresponding to the position in
 * 3D-space
 */
public static Point worldToMiniMap(Client client, int x, int y, int distance) {
    int angle = client.getMapAngle() & 0x7FF;
    LocalPoint localLocation = client.getLocalPlayer().getLocalLocation();
    x = x / 32 - localLocation.getX() / 32;
    y = y / 32 - localLocation.getY() / 32;
    int dist = x * x + y * y;
    if (dist < distance) {
        int sin = SINE[angle];
        int cos = COSINE[angle];
        int xx = y * sin + cos * x >> 16;
        int yy = sin * x - y * cos >> 16;
        int miniMapX = client.isResized() ? client.getCanvas().getWidth() - 167 : Constants.GAME_FIXED_WIDTH - 208;
        x = (miniMapX + 167 / 2) + xx;
        y = (167 / 2 - 1) + yy;
        return new Point(x, y);
    }
    return new Point(-1, -1);
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) LocalPoint(net.runelite.api.coords.LocalPoint) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 14 with LocalPoint

use of net.runelite.api.coords.LocalPoint in project runelite by runelite.

the class Perspective method getCanvasTileAreaPoly.

/**
 * Returns a polygon representing an area.
 *
 * @param client
 * @param localLocation Center location of the AoE
 * @param size size of the area. Ex. Lizardman Shaman AoE is a 3x3, so
 * size = 3
 * @return a polygon representing the tiles in the area
 */
public static Polygon getCanvasTileAreaPoly(Client client, LocalPoint localLocation, int size) {
    int plane = client.getPlane();
    int halfTile = LOCAL_TILE_SIZE / 2;
    // If the size is 5, we need to shift it up and left 2 units, then expand by 5 units to make a 5x5
    int aoeSize = size / 2;
    // Shift over one half tile as localLocation is the center point of the tile, and then shift the area size
    Point topLeft = new Point(localLocation.getX() - (aoeSize * LOCAL_TILE_SIZE) - halfTile, localLocation.getY() - (aoeSize * LOCAL_TILE_SIZE) - halfTile);
    // expand by size
    Point bottomRight = new Point(topLeft.getX() + size * LOCAL_TILE_SIZE - 1, topLeft.getY() + size * LOCAL_TILE_SIZE - 1);
    // Take the x of top left and the y of bottom right to create bottom left
    Point bottomLeft = new Point(topLeft.getX(), bottomRight.getY());
    // Similarly for top right
    Point topRight = new Point(bottomRight.getX(), topLeft.getY());
    Point p1 = worldToCanvas(client, topLeft.getX(), topLeft.getY(), plane);
    Point p2 = worldToCanvas(client, topRight.getX(), topRight.getY(), plane);
    Point p3 = worldToCanvas(client, bottomRight.getX(), bottomRight.getY(), plane);
    Point p4 = worldToCanvas(client, bottomLeft.getX(), bottomLeft.getY(), plane);
    if (p1 == null || p2 == null || p3 == null || p4 == null) {
        return null;
    }
    Polygon poly = new Polygon();
    poly.addPoint(p1.getX(), p1.getY());
    poly.addPoint(p2.getX(), p2.getY());
    poly.addPoint(p3.getX(), p3.getY());
    poly.addPoint(p4.getX(), p4.getY());
    return poly;
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) Polygon(java.awt.Polygon) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 15 with LocalPoint

use of net.runelite.api.coords.LocalPoint in project runelite by runelite.

the class Perspective method getMiniMapImageLocation.

/**
 * Calculates image position and centers depending on image size.
 *
 * @param client
 * @param localLocation local location of the tile
 * @param image image for size measurement
 * @return a {@link Point} on screen corresponding to the given
 * localLocation.
 */
public static Point getMiniMapImageLocation(Client client, LocalPoint localLocation, BufferedImage image) {
    Point p = Perspective.worldToMiniMap(client, localLocation.getX(), localLocation.getY());
    if (p == null) {
        return null;
    }
    int xOffset = p.getX() - image.getWidth() / 2;
    int yOffset = p.getY() - image.getHeight() / 2;
    return new Point(xOffset, yOffset);
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) LocalPoint(net.runelite.api.coords.LocalPoint)

Aggregations

LocalPoint (net.runelite.api.coords.LocalPoint)33 Point (net.runelite.api.Point)8 Polygon (java.awt.Polygon)7 Color (java.awt.Color)5 WorldPoint (net.runelite.api.coords.WorldPoint)5 FontMetrics (java.awt.FontMetrics)4 GameObject (net.runelite.api.GameObject)4 Rectangle2D (java.awt.geom.Rectangle2D)3 Player (net.runelite.api.Player)3 Tile (net.runelite.api.Tile)3 Area (java.awt.geom.Area)2 Region (net.runelite.api.Region)2 ProgressPie (net.runelite.client.ui.overlay.components.ProgressPie)2 Subscribe (com.google.common.eventbus.Subscribe)1 Inject (com.google.inject.Inject)1 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1