Search in sources :

Example 1 with Triangle

use of net.runelite.api.model.Triangle in project runelite by runelite.

the class RSPlayerMixin method getPolygons.

@Inject
@Override
public Polygon[] getPolygons() {
    Model model = getModel();
    if (model == null) {
        return null;
    }
    int localX = getX();
    int localY = getY();
    int orientation = getOrientation();
    List<Triangle> triangles = model.getTriangles();
    triangles = rotate(triangles, orientation);
    List<Polygon> polys = new ArrayList<Polygon>();
    for (Triangle triangle : triangles) {
        Vertex vx = triangle.getA();
        Vertex vy = triangle.getB();
        Vertex vz = triangle.getC();
        Point x = Perspective.worldToCanvas(client, localX - vx.getX(), localY - vx.getZ(), -vx.getY());
        Point y = Perspective.worldToCanvas(client, localX - vy.getX(), localY - vy.getZ(), -vy.getY());
        Point z = Perspective.worldToCanvas(client, localX - vz.getX(), localY - vz.getZ(), -vz.getY());
        int[] xx = { x.getX(), y.getX(), z.getX() };
        int[] yy = { x.getY(), y.getY(), z.getY() };
        polys.add(new Polygon(xx, yy, 3));
    }
    return polys.toArray(new Polygon[polys.size()]);
}
Also used : Vertex(net.runelite.api.model.Vertex) Model(net.runelite.api.Model) Triangle(net.runelite.api.model.Triangle) ArrayList(java.util.ArrayList) Point(net.runelite.api.Point) Polygon(java.awt.Polygon) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Example 2 with Triangle

use of net.runelite.api.model.Triangle in project runelite by runelite.

the class Perspective method get2DGeometry.

private static Area get2DGeometry(Client client, List<Triangle> triangles, int orientation, int tileX, int tileY) {
    int radius = 5;
    Area geometry = new Area();
    for (Triangle triangle : triangles) {
        Vertex _a = triangle.getA();
        Point a = worldToCanvas(client, tileX - _a.getX(), tileY - _a.getZ(), -_a.getY(), tileX, tileY);
        if (a == null) {
            continue;
        }
        Vertex _b = triangle.getB();
        Point b = worldToCanvas(client, tileX - _b.getX(), tileY - _b.getZ(), -_b.getY(), tileX, tileY);
        if (b == null) {
            continue;
        }
        Vertex _c = triangle.getC();
        Point c = worldToCanvas(client, tileX - _c.getX(), tileY - _c.getZ(), -_c.getY(), tileX, tileY);
        if (c == null) {
            continue;
        }
        int minX = Math.min(Math.min(a.getX(), b.getX()), c.getX());
        int minY = Math.min(Math.min(a.getY(), b.getY()), c.getY());
        // For some reason, this calculation is always 4 pixels short of the actual in-client one
        int maxX = Math.max(Math.max(a.getX(), b.getX()), c.getX()) + client.getViewportXOffset();
        int maxY = Math.max(Math.max(a.getY(), b.getY()), c.getY()) + client.getViewportYOffset();
        // ...and the rectangles in the fixed client are shifted 4 pixels right and down
        if (!client.isResized()) {
            minX += 4;
            minY += 4;
            maxX += 4;
            maxY += 4;
        }
        Rectangle clickableRect = new Rectangle(minX - radius, minY - radius, maxX - minX + radius, maxY - minY + radius);
        geometry.add(new Area(clickableRect));
    }
    return geometry;
}
Also used : Vertex(net.runelite.api.model.Vertex) Area(java.awt.geom.Area) Triangle(net.runelite.api.model.Triangle) Rectangle(java.awt.Rectangle) LocalPoint(net.runelite.api.coords.LocalPoint) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 3 with Triangle

use of net.runelite.api.model.Triangle in project runelite by runelite.

the class Perspective method getClickbox.

/**
 * You don't want this. Use {@link TileObject#getClickbox()} instead
 *
 * Get the on-screen clickable area of {@code model} as though it's for the object on the tile at
 * 	({@code tileX}, {@code tileY}) and rotated to angle {@code orientation}
 *
 * @param client
 * @param model the model to calculate a clickbox for
 * @param orientation the orientation of the model (0-2048, where 0 is north)
 * @param tileX the X coordinate of the tile that the object using the model is on
 * @param tileY the Y coordinate of the tile that the object using the model is on
 * @return the clickable area of {@code model}, rotated to angle {@code orientation}, at the height of tile ({@code tileX}, {@code tileY})
 */
public static Area getClickbox(Client client, Model model, int orientation, int tileX, int tileY) {
    if (model == null) {
        return null;
    }
    List<Triangle> triangles = model.getTriangles().stream().map(triangle -> triangle.rotate(orientation)).collect(Collectors.toList());
    List<Vertex> vertices = model.getVertices().stream().map(v -> v.rotate(orientation)).collect(Collectors.toList());
    Area clickBox = get2DGeometry(client, triangles, orientation, tileX, tileY);
    Area visibleAABB = getAABB(client, vertices, orientation, tileX, tileY);
    if (visibleAABB == null || clickBox == null) {
        return null;
    }
    clickBox.intersect(visibleAABB);
    return clickBox;
}
Also used : Polygon(java.awt.Polygon) Rectangle(java.awt.Rectangle) LocalPoint(net.runelite.api.coords.LocalPoint) BufferedImage(java.awt.image.BufferedImage) Vertex(net.runelite.api.model.Vertex) Area(java.awt.geom.Area) Rectangle2D(java.awt.geom.Rectangle2D) Triangle(net.runelite.api.model.Triangle) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) FontMetrics(java.awt.FontMetrics) Graphics2D(java.awt.Graphics2D) Jarvis(net.runelite.api.model.Jarvis) Vertex(net.runelite.api.model.Vertex) Area(java.awt.geom.Area) Triangle(net.runelite.api.model.Triangle)

Example 4 with Triangle

use of net.runelite.api.model.Triangle in project runelite by runelite.

the class RSPlayerMixin method rotate.

@Inject
private List<Triangle> rotate(List<Triangle> triangles, int orientation) {
    List<Triangle> rotatedTriangles = new ArrayList<Triangle>();
    for (Triangle triangle : triangles) {
        Vertex a = triangle.getA();
        Vertex b = triangle.getB();
        Vertex c = triangle.getC();
        Triangle rotatedTriangle = new Triangle(a.rotate(orientation), b.rotate(orientation), c.rotate(orientation));
        rotatedTriangles.add(rotatedTriangle);
    }
    return rotatedTriangles;
}
Also used : Vertex(net.runelite.api.model.Vertex) Triangle(net.runelite.api.model.Triangle) ArrayList(java.util.ArrayList) Inject(net.runelite.api.mixins.Inject)

Example 5 with Triangle

use of net.runelite.api.model.Triangle in project runelite by runelite.

the class RSModelMixin method getTriangles.

@Override
@Inject
public List<Triangle> getTriangles() {
    int[] trianglesX = getTrianglesX();
    int[] trianglesY = getTrianglesY();
    int[] trianglesZ = getTrianglesZ();
    List<Vertex> vertices = getVertices();
    List<Triangle> triangles = new ArrayList<Triangle>(getTrianglesCount());
    for (int i = 0; i < getTrianglesCount(); ++i) {
        int triangleX = trianglesX[i];
        int triangleY = trianglesY[i];
        int triangleZ = trianglesZ[i];
        Triangle triangle = new Triangle(vertices.get(triangleX), vertices.get(triangleY), vertices.get(triangleZ));
        triangles.add(triangle);
    }
    return triangles;
}
Also used : Vertex(net.runelite.api.model.Vertex) Triangle(net.runelite.api.model.Triangle) ArrayList(java.util.ArrayList) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Aggregations

Triangle (net.runelite.api.model.Triangle)5 Vertex (net.runelite.api.model.Vertex)5 ArrayList (java.util.ArrayList)4 Inject (net.runelite.api.mixins.Inject)3 Polygon (java.awt.Polygon)2 Rectangle (java.awt.Rectangle)2 Area (java.awt.geom.Area)2 Point (net.runelite.api.Point)2 LocalPoint (net.runelite.api.coords.LocalPoint)2 FontMetrics (java.awt.FontMetrics)1 Graphics2D (java.awt.Graphics2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Model (net.runelite.api.Model)1 Jarvis (net.runelite.api.model.Jarvis)1