Draw hull on decorative objects too

This commit is contained in:
Adam
2017-08-15 20:34:30 -04:00
parent c8b12cbc13
commit 981767b399
5 changed files with 103 additions and 51 deletions

View File

@@ -24,6 +24,8 @@
*/
package net.runelite.api;
import java.awt.Polygon;
/**
* Decorative object, such as objects on walls
*
@@ -56,4 +58,36 @@ public class DecorativeObject extends TileObject
{
return decorativeObject.getY();
}
public Renderable getRenderable()
{
return Renderable.of(decorativeObject.getRenderable());
}
public Polygon getConvexHull()
{
Renderable renderable = getRenderable();
if (renderable == null)
{
return null;
}
Model model;
if (renderable instanceof Model)
{
model = (Model) renderable;
}
else
{
model = renderable.getModel();
}
if (model == null)
{
return null;
}
return getConvexHull(model, decorativeObject.getOrientation());
}
}

View File

@@ -25,10 +25,6 @@
package net.runelite.api;
import java.awt.Polygon;
import java.util.ArrayList;
import java.util.List;
import net.runelite.api.model.Jarvis;
import net.runelite.api.model.Vertex;
/**
*
@@ -91,52 +87,6 @@ public class GameObject extends TileObject
return null;
}
int localX = gameObject.getX();
int localY = gameObject.getY();
// models are orientated north (1024) and there are 2048 angles total
int orientation = (gameObject.getOrientation() + 1024) % 2048;
List<Vertex> verticies = model.getVertices();
if (orientation != 0)
{
// rotate verticies
for (int i = 0; i < verticies.size(); ++i)
{
Vertex v = verticies.get(i);
verticies.set(i, v.rotate(orientation));
}
}
List<Point> points = new ArrayList<>();
for (Vertex v : verticies)
{
// Compute canvas location of vertex
Point p = Perspective.worldToCanvas(client,
localX - v.getX(),
localY - v.getZ(),
-v.getY());
if (p != null)
{
points.add(p);
}
}
// Run Jarvis march algorithm
points = Jarvis.convexHull(points);
if (points == null)
{
return null;
}
// Convert to a polygon
Polygon p = new Polygon();
for (Point point : points)
{
p.addPoint(point.getX(), point.getY());
}
return p;
return getConvexHull(model, gameObject.getOrientation());
}
}

View File

@@ -26,6 +26,10 @@ package net.runelite.api;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.util.ArrayList;
import java.util.List;
import net.runelite.api.model.Jarvis;
import net.runelite.api.model.Vertex;
public abstract class TileObject
{
@@ -79,4 +83,56 @@ public abstract class TileObject
{
return Perspective.worldToMiniMap(client, getLocalX(), getLocalY());
}
protected Polygon getConvexHull(Model model, int orientation)
{
int localX = getLocalX();
int localY = getLocalY();
// models are orientated north (1024) and there are 2048 angles total
orientation = (orientation + 1024) % 2048;
List<Vertex> verticies = model.getVertices();
if (orientation != 0)
{
// rotate verticies
for (int i = 0; i < verticies.size(); ++i)
{
Vertex v = verticies.get(i);
verticies.set(i, v.rotate(orientation));
}
}
List<Point> points = new ArrayList<>();
for (Vertex v : verticies)
{
// Compute canvas location of vertex
Point p = Perspective.worldToCanvas(client,
localX - v.getX(),
localY - v.getZ(),
-v.getY());
if (p != null)
{
points.add(p);
}
}
// Run Jarvis march algorithm
points = Jarvis.convexHull(points);
if (points == null)
{
return null;
}
// Convert to a polygon
Polygon p = new Polygon();
for (Point point : points)
{
p.addPoint(point.getX(), point.getY());
}
return p;
}
}

View File

@@ -298,6 +298,12 @@ public class DevToolsOverlay extends Overlay
{
OverlayUtil.renderTileOverlay(graphics, decorObject, "ID: " + decorObject.getId(), DEEP_PURPLE);
}
Polygon p = decorObject.getConvexHull();
if (p != null)
{
graphics.drawPolygon(p);
}
}
}

View File

@@ -36,4 +36,10 @@ public interface DecorativeObject
@Import("y")
int getY();
@Import("rotation")
int getOrientation();
@Import("renderable1")
Renderable getRenderable();
}