Brainfree Posted May 27, 2013 Share Posted May 27, 2013 Hello, Being that the models for items that are elevated are broken(there heights are wrong), I have come up with a method to advert this pesky problem, it simply builds a Prism around were the model should be, and collides its corner vertices to derive it's midpoint, which in most cases, is were exactly the models center point is. Cool stuff. Example: And the src code: package rdpv2; import org.osbot.script.Script; import org.osbot.script.ScriptManifest; import org.osbot.script.rs2.utility.Utilities; import java.awt.*; @ScriptManifest( author = "Brainfree", version = 1.00, info = "Generates a point of elevation were a item on table should be, roughly", name = "Elevated Point Grabber" ) public class TableGrabbing extends Script { public Point[] getLid(int x, int y, int height, double compression) { Point A = getScreenPoint(x, y, 0, 0, height); if (A.x == -1) return null; Point B = getScreenPoint(x, y, 0, 1, height); if (B.x == -1) return null; Point C = getScreenPoint(x, y, 1, 1, height); if (C.x == -1) return null; Point D = getScreenPoint(x, y, 1, 0, height); if (D.x == -1) return null; Point c = getInterceptionPoint(A.x, A.y, C.x, C.y, B.x, B.y, D.x, D.y); Point Ac = getPointOnLineAtDistance(A.x, A.y, c.x, c.y, compression); Point Bc = getPointOnLineAtDistance(B.x, B.y, c.x, c.y, compression); Point Cc = getPointOnLineAtDistance(C.x, C.y, c.x, c.y, compression); Point Dc = getPointOnLineAtDistance(D.x, D.y, c.x, c.y, compression); return new Point[]{Ac, Bc, Cc, Dc}; } private Point getScreenPoint(int x, int y, int sx, int sy, int height) { return Utilities.getScreenCoordinates(bot, (x - client.getMapBaseX() + sx) << 7, (y - client.getMapBaseY() + sy) << 7, height); } public static Point getInterceptionPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { double dot = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); if (dot == 0) new Point(-1, -1); double X = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / dot; double Y = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / dot; return new Point((int) X, (int) Y); } public static Point getPointOnLineAtDistance( double OriginX, double OriginY, double EndLocationX, double EndLocationY, double scale) { final double LegXLength = (EndLocationX - OriginX); final double LegYLength = (EndLocationY - OriginY); double HypotenuseLength = Math.sqrt(LegXLength * LegXLength + LegYLength * LegYLength); double InverseX = HypotenuseLength * scale * LegXLength / HypotenuseLength; double InverseY = (HypotenuseLength * scale * LegYLength) / HypotenuseLength; return new Point( (int) (InverseX + OriginX), (int) (InverseY + OriginY) ); } /** * * Builds a 3D prism around were the ground items model should be in cases * of were the model in a elevated height, and is client failed to interpret it. * * @param tileX The Position X for which the ground item is located. * @param tileY The Position Y for which the ground item is located. * @param heightMin The lower elevation height of the prism. * @param heightMax The upper elevation height of the prism. * @param compression 1.0 = Full Tile bounds length, .75 = 3/4 of the side bounds length * @return The midpoint of the prism. */ public Point getElevatedPoint(int tileX, int tileY, int heightMin, int heightMax, double compression) { Point[] bottom = getLid(tileX, tileX, heightMin, compression); if (bottom == null) return null; Point[] top = getLid(tileX, tileY, heightMax, compression); if (top == null) return null; return getInterceptionPoint( top[0].x, top[0].y, bottom[2].x, bottom[2].y, top[1].x, top[1].y, bottom[3].x, bottom[3].y ); } public int onLoop() { Point wereTheMidPointOfTheModelOfThisItemShouldBe = getElevatedPoint(3232, 3399, 80, 120, .75); return 45; } private void drawLid(Point[] lid, Graphics graphics) { for (int i = 0; i < 4; i++) { graphics.drawLine( lid[i].x, lid[i].y, lid[i == 3 ? 0 : i + 1].x, lid[i == 3 ? 0 : i + 1].y); } } public void drawBounds(int tileX, int tileY, int heightMin, int heightMax, double compression, Graphics g) { Point[] bottom = getLid(tileX, tileY, heightMin, compression); if (bottom == null) return; Point[] top = getLid(tileX, tileY, heightMax, compression); if (top == null) return; for (int i = 0; i < 4; i++) { g.drawLine(bottom[i].x, bottom[i].y, top[i].x, top[i].y); } drawLid(bottom, g); drawLid(top, g); Point center = getInterceptionPoint( top[0].x, top[0].y, bottom[2].x, bottom[2].y, top[1].x, top[1].y, bottom[3].x, bottom[3].y ); g.setColor(Color.red); g.drawString(".", center.x, center.y); } public void onPaint(Graphics graphics) { drawBounds(3232, 3399, 80, 120, .75, graphics); } } Hope you can find great use of it. 2 Link to comment Share on other sites More sharing options...
Wizard Posted May 27, 2013 Share Posted May 27, 2013 Again, helpful code by you!! thank you! Link to comment Share on other sites More sharing options...
Rare Posted May 27, 2013 Share Posted May 27, 2013 Very nice work! This should help with some things. +1 Even though I don't script, I know this is big news. Link to comment Share on other sites More sharing options...
Toadfly Posted May 27, 2013 Share Posted May 27, 2013 (edited) I too don't script, but this is nice. Now we need a method for agility objects, because as far as I'm concerned, I'm almost positive agility objects aren't recognized. Edited May 27, 2013 by Toadfly Link to comment Share on other sites More sharing options...