Some shiny rendering methods (#13)
* Added getter methods to Actor * Added zOffset parameter to worldToCanvas() * Fixed formatting, added rendering functions to Actor and DevTools plugin * Changed getCanvasTilePoly() to use Perspective.LOCAL_TILE_SIZE
This commit is contained in:
@@ -22,9 +22,12 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.api;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import net.runelite.rs.api.CombatInfo1;
|
||||
import net.runelite.rs.api.CombatInfo2;
|
||||
import net.runelite.rs.api.CombatInfoList;
|
||||
@@ -33,6 +36,7 @@ import net.runelite.rs.api.Node;
|
||||
|
||||
public abstract class Actor extends Renderable
|
||||
{
|
||||
|
||||
private Client client;
|
||||
private net.runelite.rs.api.Actor actor;
|
||||
|
||||
@@ -107,4 +111,71 @@ public abstract class Actor extends Renderable
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public Point getLocalLocation()
|
||||
{
|
||||
return new Point(getX(), getY());
|
||||
}
|
||||
|
||||
private int getX()
|
||||
{
|
||||
return actor.getX();
|
||||
}
|
||||
|
||||
private int getY()
|
||||
{
|
||||
return actor.getY();
|
||||
}
|
||||
|
||||
public int getAnimation()
|
||||
{
|
||||
return actor.getAnimation();
|
||||
}
|
||||
|
||||
public int getModelHeight()
|
||||
{
|
||||
return actor.getModelHeight();
|
||||
}
|
||||
|
||||
public Polygon getCanvasTilePoly()
|
||||
{
|
||||
int plane = client.getPlane();
|
||||
int halfTile = Perspective.LOCAL_TILE_SIZE / 2;
|
||||
|
||||
Point p1 = Perspective.worldToCanvas(client, getX() - halfTile, getY() - halfTile, plane);
|
||||
Point p2 = Perspective.worldToCanvas(client, getX() - halfTile, getY() + halfTile, plane);
|
||||
Point p3 = Perspective.worldToCanvas(client, getX() + halfTile, getY() + halfTile, plane);
|
||||
Point p4 = Perspective.worldToCanvas(client, getX() + halfTile, getY() - halfTile, plane);
|
||||
|
||||
if (p1 == null || p2 == null || p3 == null || p4 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Polygon poly = new Polygon();
|
||||
poly.addPoint(p1.getX(), p1.getY());
|
||||
poly.addPoint(p2.getX(), p2.getY());
|
||||
poly.addPoint(p3.getX(), p3.getY());
|
||||
poly.addPoint(p4.getX(), p4.getY());
|
||||
|
||||
return poly;
|
||||
}
|
||||
|
||||
public Point getCanvasTextLocation(Graphics2D graphics, String text, int zOffset)
|
||||
{
|
||||
int plane = client.getPlane();
|
||||
|
||||
Point p = Perspective.worldToCanvas(client, getLocalLocation().getX(), getLocalLocation().getY(), plane, zOffset);
|
||||
|
||||
if (p == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
FontMetrics fm = graphics.getFontMetrics();
|
||||
Rectangle2D bounds = fm.getStringBounds(text, graphics);
|
||||
int xOffset = p.getX() - (int) (bounds.getWidth() / 2);
|
||||
|
||||
return new Point(xOffset, p.getY());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Perspective
|
||||
private static final double UNIT = Math.PI / 1024d; // How much of the circle each unit of SINE/COSINE is
|
||||
|
||||
private static final int LOCAL_COORD_BITS = 7;
|
||||
private static final int LOCAL_TILE_SIZE = 1 << LOCAL_COORD_BITS; // 128 - size of a tile in local coordinates
|
||||
public static final int LOCAL_TILE_SIZE = 1 << LOCAL_COORD_BITS; // 128 - size of a tile in local coordinates
|
||||
|
||||
public static final int[] SINE = new int[2048]; // sine angles for each of the 2048 units, * 65536 and stored as an int
|
||||
public static final int[] COSINE = new int[2048]; // cosine
|
||||
@@ -50,18 +50,36 @@ public class Perspective
|
||||
* @param client
|
||||
* @param x ground coordinate on the x axis
|
||||
* @param y ground coordinate on the y axis
|
||||
* @param var2
|
||||
* @param plane ground plane on the z axis
|
||||
* @return a {@link Point} on screen corresponding to the position in
|
||||
* 3D-space
|
||||
*/
|
||||
public static Point worldToCanvas(Client client, int x, int y, int var2)
|
||||
public static Point worldToCanvas(Client client, int x, int y, int plane)
|
||||
{
|
||||
return worldToCanvas(client, x, y, plane, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates two-dimensional ground coordinates within the 3D world to
|
||||
* their corresponding coordinates on the game screen.
|
||||
*
|
||||
* @param client
|
||||
* @param x ground coordinate on the x axis
|
||||
* @param y ground coordinate on the y axis
|
||||
* @param plane ground plane on the z axis
|
||||
* @param zOffset distance from ground on the z axis
|
||||
* @return a {@link Point} on screen corresponding to the position in
|
||||
* 3D-space
|
||||
*/
|
||||
public static Point worldToCanvas(Client client, int x, int y, int plane, int zOffset)
|
||||
{
|
||||
if (x >= 128 && y >= 128 && x <= 13056 && y <= 13056)
|
||||
{
|
||||
int z = getTileHeight(client, x, y, client.getPlane()) - var2;
|
||||
int z = getTileHeight(client, x, y, client.getPlane()) - plane;
|
||||
x -= client.getCameraX();
|
||||
z -= client.getCameraZ();
|
||||
y -= client.getCameraY();
|
||||
z -= client.getCameraZ();
|
||||
z -= zOffset;
|
||||
|
||||
int cameraPitch = client.getCameraPitch();
|
||||
int cameraYaw = client.getCameraYaw();
|
||||
|
||||
Reference in New Issue
Block a user