I thought some people might make use of this for either custom interaction or checking if entity is visible. Don't mind the ghetto fire entity check.
import org.osbot.rs07.api.Client;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.Model;
import org.osbot.rs07.api.util.GraphicUtilities;
import java.awt.*;
public class Calculations {
public static Polygon getModelPolygon(Entity entity, Client client, Model model, int gridX, int gridY) {
if (model == null) {
return new Polygon();
}
if (entity.getName().equalsIgnoreCase("Fire")) {
return entity.getPosition().getPolygon(client.getBot());
} else {
short[][] screenCoordinates = GraphicUtilities.getScreenCoordinates(client.getBot(), gridX, gridY, client.accessor.getPlane(), model);
Polygon temp = new Polygon();
for (int triangleId = 0; triangleId < model.getTriangleCount(); triangleId++)
try {
int triangleA = model.getVertexXIndices()[triangleId];
int triangleB = model.getVertexYIndices()[triangleId];
int triangleC = model.getVertexZIndices()[triangleId];
short[] pointA = screenCoordinates[triangleA];
short[] pointB = screenCoordinates[triangleB];
short[] pointC = screenCoordinates[triangleC];
Polygon aw = entity.getPosition().getPolygon(client.getBot());
if (pointA != null && pointB != null && pointC != null) {
if (pointA[0] <= -1 || pointA[1] <= -1 || pointB[0] <= -1 || pointB[1] <= -1 || pointC[0] <= -1 || pointC[1] <= -1)
continue;
for (int xpoints : aw.xpoints) {
for (int ypoints : aw.ypoints) {
if (pointA[1] <= ypoints && pointA[0] <= xpoints) {
temp.addPoint(pointA[0], pointA[1]);
}
if (pointB[1] <= ypoints && pointB[0] <= xpoints) {
temp.addPoint(pointB[0], pointB[1]);
}
if (pointC[1] <= ypoints && pointC[0] <= xpoints) {
temp.addPoint(pointC[0], pointC[1]);
}
}
}
}
} catch (ArrayIndexOutOfBoundsException var13) {
}
return temp;
}
}
}
public boolean isVisible(Script s, Entity entity) {
Polygon polygon = Calculations.getModelPolygon(entity, s.client, entity.getModel(), entity.getGridX(), entity.getGridY());
if (polygon != null) {
Rectangle rectangle = new Rectangle(4, 4, 512, 334);
return rectangle.intersects(polygon.getBounds());
}
return false;
}
public Rectangle visibleRectangle(Polygon polygon) {
if (polygon != null) {
Rectangle rectangle = new Rectangle(4, 4, 512, 334);
return rectangle.intersection(polygon.getBounds());
}
return null;
}
You could do without the null checks as well.