From 981767b399cffd108d4aa2711aace3cbad891cab Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 15 Aug 2017 20:34:30 -0400 Subject: [PATCH] Draw hull on decorative objects too --- .../net/runelite/api/DecorativeObject.java | 34 +++++++++++ .../java/net/runelite/api/GameObject.java | 52 +---------------- .../java/net/runelite/api/TileObject.java | 56 +++++++++++++++++++ .../plugins/devtools/DevToolsOverlay.java | 6 ++ .../net/runelite/rs/api/DecorativeObject.java | 6 ++ 5 files changed, 103 insertions(+), 51 deletions(-) diff --git a/runelite-api/src/main/java/net/runelite/api/DecorativeObject.java b/runelite-api/src/main/java/net/runelite/api/DecorativeObject.java index e79e014745..68808cca5c 100644 --- a/runelite-api/src/main/java/net/runelite/api/DecorativeObject.java +++ b/runelite-api/src/main/java/net/runelite/api/DecorativeObject.java @@ -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()); + } } diff --git a/runelite-api/src/main/java/net/runelite/api/GameObject.java b/runelite-api/src/main/java/net/runelite/api/GameObject.java index 2c83eb9b4c..54a5a65ef2 100644 --- a/runelite-api/src/main/java/net/runelite/api/GameObject.java +++ b/runelite-api/src/main/java/net/runelite/api/GameObject.java @@ -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 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 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()); } } diff --git a/runelite-api/src/main/java/net/runelite/api/TileObject.java b/runelite-api/src/main/java/net/runelite/api/TileObject.java index eec8ac6eb5..590a1951a1 100644 --- a/runelite-api/src/main/java/net/runelite/api/TileObject.java +++ b/runelite-api/src/main/java/net/runelite/api/TileObject.java @@ -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 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 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; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsOverlay.java index 33cf660d8d..c4ccb66e45 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsOverlay.java @@ -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); + } } } diff --git a/runescape-api/src/main/java/net/runelite/rs/api/DecorativeObject.java b/runescape-api/src/main/java/net/runelite/rs/api/DecorativeObject.java index 4c225f879d..efeb6c6edd 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/DecorativeObject.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/DecorativeObject.java @@ -36,4 +36,10 @@ public interface DecorativeObject @Import("y") int getY(); + + @Import("rotation") + int getOrientation(); + + @Import("renderable1") + Renderable getRenderable(); }