Class CoordView


  • public class CoordView
    extends Object
    Provides view-related projections for a CoordFine, such as converting a world-space fine coordinate into screen-space or minimap-space positions.

    Internally, this uses the client's camera position, pitch, yaw, and viewport settings to perform the same kind of 3D → 2D projections as the game engine.

    • Field Detail

      • SINE

        public static final int[] SINE
        Precomputed sine table for 2048 discrete angles (0–2047) in the client angle space. Values are scaled by 65536 (1 << 16) for fixed-point math.
      • COSINE

        public static final int[] COSINE
        Precomputed cosine table for 2048 discrete angles (0–2047) in the client angle space. Values are scaled by 65536 (1 << 16) for fixed-point math.
    • Method Detail

      • getPolygon

        public Polygon getPolygon()
        Computes a screen-space polygon representing the tile (or sub-tile) occupied by this coordinate, using a default granularity of 1.

        A granularity of 1 corresponds to the full tile. See getPolygon(int) for details.

        Returns:
        a Polygon describing the screen-space quad covering this tile; an empty polygon if the tile is not visible on the screen
      • getPolygon

        public Polygon getPolygon​(int granularity)
        Computes a screen-space polygon representing the area around this CoordFine, optionally at sub-tile granularity.

        How granularity works:
        Granularity divides a tile into smaller logical segments based on an internal step granularity of g * 2 when calling CoordFine.translate(int, int, int):

        • granularity = 1 → full tile
        • granularity = 2 → 2x2
        • granularity = 4 → 4x4
        • granularity = 8 → 8x8
        Internally this is mapped to stepGranularity = granularity * 2, so each step translate(dx, dy, stepGranularity) moves the coordinate by 128 / (granularity * 2) fine units, and the full polygon width becomes 128 / granularity fine units.
        Parameters:
        granularity - the subdivision factor
        Returns:
        a Polygon representing the on-screen quad around this coordinate at the given granularity; or an empty polygon if off-screen
      • getSubPolygons

        public List<Polygon> getSubPolygons​(int granularity)
      • toScreen

        public Point toScreen()
        Projects this coordinate into the main 3D game viewport (screen space).

        This uses the client's camera position, pitch, yaw and viewport scale to perform a fixed-point 3D → 2D projection.

        Returns:
        a Point in screen coordinates, or (-1, -1) if the coordinate is not in a loaded scene region or outside the viewport, or null if camera pitch/yaw are invalid
      • toScreen

        public Point toScreen​(int zOffset)
        Projects this coordinate into the main 3D game viewport (screen space), applying a custom vertical Z-offset.

        This method performs a full fixed-point 3D → 2D projection using:

        • the client's camera position (X/Y/Z)
        • current camera pitch and yaw
        • the scene's floor height at this coordinate
        • the viewport size and scale
        The Z-offset is subtracted from the coordinate's world height before projection, allowing callers to draw labels or markers above/below objects.
        Parameters:
        zOffset - the vertical offset (in world units) applied before projection; positive values lower the projected point, negative values raise it
        Returns:
        a Point in screen coordinates, (-1, -1) if the coordinate is not visible or outside the viewport, or null if the camera's pitch or yaw values are invalid
      • projectTextOnViewport

        public Point projectTextOnViewport​(Graphics g,
                                           String text,
                                           Entity<?> entity)
        Computes a screen-space render point for drawing text above a given entity.

        This projects the entity's world coordinate into screen space and adjusts the horizontal position so that the provided text is centered horizontally.

        Parameters:
        g - the graphics context used to measure string bounds
        text - the text to be rendered
        entity - the target entity whose height is used as the Z-offset
        Returns:
        the top-left Point at which the text should be rendered, or null if the text is empty or invalid, or (-1, -1) if the coordinate cannot be projected onto the screen
      • projectTextOnViewport

        public Point projectTextOnViewport​(Graphics g,
                                           String text)
        Computes a screen-space render point for drawing text at this coordinate with no vertical Z-offset.

        This projects the coordinate into screen space and horizontally centers the provided text around that point.

        Parameters:
        g - the graphics context used to measure string bounds
        text - the text to be rendered
        Returns:
        the top-left Point at which the text should be drawn, or null if the text is empty or invalid, or (-1, -1) if the coordinate cannot be projected onto the screen
      • projectTextOnViewport

        public Point projectTextOnViewport​(Graphics g,
                                           String text,
                                           int zOffset)
        Computes a screen-space render point for drawing text at this coordinate, applying an explicit Z-offset.

        This method:

        1. Projects the world coordinate to screen space using toScreen(int)
        2. Centers the provided text horizontally using the given Graphics
        Parameters:
        g - the graphics context used to measure string bounds
        text - the text to be rendered
        zOffset - the vertical offset (in world units) applied before projection
        Returns:
        the top-left Point at which the text should be rendered, null if the text is empty, or (-1, -1) if projection fails
      • toMinimap

        public Point toMinimap()
        Projects this coordinate into minimap space.

        The returned point is the location of this world coordinate on the minimap widget, taking into account the player's position, minimap rotation, and the active interface layout (fixed, resized-line, resized-stone).

        When the player is on special transport (e.g., boats), the minimap's center shifts to the associated RSWorldEntity.

        Returns:
        a Point in minimap pixel coordinates, or (-1, -1) if the point lies outside the minimap bounds, the minimap component is hidden/unavailable, or the distance exceeds the minimap radius