Class Coord
- java.lang.Object
-
- org.rspeer.game.coord.Coord
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.rspeer.game.adapter.type.SceneNode
SceneNode.Query<Q extends SceneNode.Query<Q>>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Coorddx(int x)Coorddy(int y)booleanequals(Object obj)static Coordfrom(int x, int y)Creates a newCoordat the specified world X/Y coordinates on floor level0.static Coordfrom(int x, int y, int floorLevel)Creates a newCoordfrom world-space X/Y coordinates and a floor level.static Coordfrom(int x, int y, int floorLevel, float subX, float subY)static CoordfromFine(RSWorldMatrix matrix, CoordFine fine)static CoordfromFine(CoordFine fine)Converts aCoordFineinto a worldCoord, resolving the associatedRSWorldMatrixviaGame.getMatrix(int).static CoordfromGrid(int matrixId, CoordGrid grid)Converts aCoordGridinto a world-spaceCoordby resolving the associatedRSWorldMatrixusing the given matrix ID.static CoordfromGrid(RSWorldMatrix matrix, CoordGrid grid)Converts aCoordGrid(matrix-local tile coordinate) into a world-spaceCoordusing the givenRSWorldMatrix.static CoordfromGrid(CoordGrid grid)static CoordfromPacked(int packed)Unpacks a 32-bit packed coordinate into aCoord.CoordgetCoord()CoordFinegetCoordFine()CoordViewgetCoordView()intgetFloorLevel()List<Coord>getInstanced()intgetMatrixId()PositiongetPosition()floatgetPreciseX()floatgetPreciseY()intgetRegionId()Returns the region ID for this coordinate.CoordgetSource()Returns the underlying world-space coordinate that thisCoordwas derived from during instance or subworld transformation.floatgetSubX()floatgetSubY()intgetX()intgetY()inthashCode()static intpack(int x, int y, int floor)Packs a tile coordinate into a 32-bit integer using the standard RuneScape-style coordinate packing format.static Coordrotate(Coord coord, int rotation)Rotates a coordinate within its containing 8x8 chunk by the given rotation.StringtoString()Coordtranslate(int x, int y)Coordtranslate(Direction direction)-
Methods inherited from interface org.rspeer.game.adapter.type.SceneNode
distance, distance, distance, distance, getArea, getCoordArea, getCoordArea, getEntityPositionHeight, getEntityPositionWidth, getSceneContext, getWorldEntity, getWorldEntity, isInFieldOfViewOf, isInFieldOfViewOf
-
-
-
-
Field Detail
-
NIL
public static final Coord NIL
-
-
Method Detail
-
from
public static Coord from(int x, int y, int floorLevel, float subX, float subY)
-
from
public static Coord from(int x, int y, int floorLevel)
Creates a newCoordfrom world-space X/Y coordinates and a floor level.This is the primary factory method for constructing world coordinates.
- Parameters:
x- the world X coordinatey- the world Y coordinatefloorLevel- the floor/plane (typically 0–3)- Returns:
- a new
Coordrepresenting the given world position
-
from
public static Coord from(int x, int y)
Creates a newCoordat the specified world X/Y coordinates on floor level0.This is a convenience overload for situations where the floor is implicitly ground level.
- Parameters:
x- the world X coordinatey- the world Y coordinate- Returns:
- a new
Coordat the given world position on floor0
-
fromGrid
public static Coord fromGrid(RSWorldMatrix matrix, CoordGrid grid)
Converts aCoordGrid(matrix-local tile coordinate) into a world-spaceCoordusing the givenRSWorldMatrix.In the engine, a
CoordGridstores coordinates relative to the originating matrix/scene. To convert these to absolute world coordinates, the matrix base is applied:worldX = grid.x + matrix.getBaseX() worldY = grid.y + matrix.getBaseY()
The floor level is preserved.
- Parameters:
matrix- the world matrix providing base coordinate offsets; must not benullgrid- the matrix-local tile coordinate to convert- Returns:
- the corresponding world-space
Coord
-
fromGrid
public static Coord fromGrid(int matrixId, CoordGrid grid)
Converts aCoordGridinto a world-spaceCoordby resolving the associatedRSWorldMatrixusing the given matrix ID.This is equivalent to:
Coord.fromGrid(Game.getMatrix(matrixId), grid)
- Parameters:
matrixId- the matrix ID used to look up theRSWorldMatrixgrid- the matrix-local tile coordinate to convert- Returns:
- the world-space
Coord, orCoord.NILif the matrix cannot be resolved
-
fromGrid
public static Coord fromGrid(CoordGrid grid)
Converts aCoordGridinto a world-spaceCoordusing the matrix referenced directly by the grid's ownmatrixId.This is the most convenient overload and is equivalent to:
Coord.fromGrid(Game.getMatrix(grid.getMatrixId()), grid)
- Parameters:
grid- the matrix-local tile coordinate to convert- Returns:
- the corresponding world-space
Coord, orCoord.NILif the grid's matrix cannot be resolved
-
fromFine
public static Coord fromFine(RSWorldMatrix matrix, CoordFine fine)
Converts aCoordFine(fine-coordinate space, usually 128 sub-units per tile) into a world-spaceCoord, preserving sub-tile precision and automatically resolving instance and subworld transformations.This method performs the following steps in order:
- Instance coordinate translation:
If the fine coordinate originates inside a dynamically-built instanced region, the underlying instance template chunk is resolved and converted into its corresponding top-level world tile viafromInstance(...). - Subworld → root world transformation:
If the providedRSWorldMatrixdoes not match the game's top-level world matrix, the coordinate is transformed using the appropriate baseX/baseY offset viafromMatrix(...). - Fine → world tile conversion:
The fine-coordinate X/Y values are divided byCoordFine.UNITS_PER_SQUAREto recover the integer grid coordinate, and the remainder is used to computesubX/subY, which describe the precise fractional position within the tile (0.0–1.0).
The returned
Coordalways describes the final, fully-resolved world position as seen by pathfinding, collision, and interaction systems. If an instance/subworld transformation is required, the intermediate transformedCoordretains a reference to its pre-transformed world-space source coordinate viagetSource().- Parameters:
matrix- the world matrix used to interpret the fine coordinate's local basefine- the fine-resolution coordinate to convert- Returns:
- a fully resolved, world-space
Coordwith sub-tile precision
- Instance coordinate translation:
-
fromFine
public static Coord fromFine(CoordFine fine)
Converts aCoordFineinto a worldCoord, resolving the associatedRSWorldMatrixviaGame.getMatrix(int).This is a convenience overload that calls
fromFine(RSWorldMatrix, CoordFine)with the matrix referenced byfine.getMatrixId().- Parameters:
fine- the fine-coordinate to convert; must not be null- Returns:
- a
Coordrepresenting the world coord derived from the fine position
-
fromPacked
public static Coord fromPacked(int packed)
Unpacks a 32-bit packed coordinate into aCoord.The packed format uses:
- bits 28–29: floor level (0–3)
- bits 14–27: X coordinate (0–16383)
- bits 0–13 : Y coordinate (0–16383)
- Parameters:
packed- the packed coordinate value- Returns:
- a
Coordextracted from the packed integer
-
rotate
public static Coord rotate(Coord coord, int rotation)
Rotates a coordinate within its containing 8x8 chunk by the given rotation.Rotation is performed around the origin of the 8x8 chunk containing
coord, using the standard RuneScape convention:- 0 – no rotation
- 1 – 90 degrees clockwise
- 2 – 180 degrees
- 3 – 270 degrees clockwise
- Parameters:
coord- the coordinate to rotaterotation- rotation value in the range 0–3- Returns:
- a new
Coordrepresenting the rotated position
-
pack
public static int pack(int x, int y, int floor)Packs a tile coordinate into a 32-bit integer using the standard RuneScape-style coordinate packing format.The layout is:
floor (2 bits) | x (14 bits) | y (14 bits) [28..29] | [14..27] | [0..13]- Parameters:
x- the X tile coordinate (0–16383)y- the Y tile coordinate (0–16383)floor- the floor level (0–3)- Returns:
- a packed 32-bit integer containing x, y, and floor
-
getMatrixId
public int getMatrixId()
- Specified by:
getMatrixIdin interfaceSceneNode
-
getPosition
public Position getPosition()
- Specified by:
getPositionin interfaceSceneNode
-
getCoordFine
public CoordFine getCoordFine()
- Specified by:
getCoordFinein interfaceSceneNode
-
getCoordView
public CoordView getCoordView()
- Specified by:
getCoordViewin interfaceSceneNode
-
getFloorLevel
public int getFloorLevel()
- Specified by:
getFloorLevelin interfaceSceneNode
-
getSource
public Coord getSource()
Returns the underlying world-space coordinate that thisCoordwas derived from during instance or subworld transformation.If this coordinate was produced by
fromFine(RSWorldMatrix, CoordFine)and required instance template translation or subworld-to-root-world matrix adjustment, the returned value corresponds to the original resolved world coordinate.If no transformation occurred, this method simply returns
this.In short:
- Normal world coords: returns
this - Instanced coords → world coords: returns the raw instance coord
- Subworld coords → top-level coords: returns the raw subworld coord
- Returns:
- the world-space source coordinate, or this coordinate if none exists
- Normal world coords: returns
-
getSubX
public float getSubX()
-
getSubY
public float getSubY()
-
getPreciseX
public float getPreciseX()
-
getPreciseY
public float getPreciseY()
-
getRegionId
public int getRegionId()
Returns the region ID for this coordinate.The region ID is computed from the 8x8 regions:
regionX = x >> 6 regionY = y >> 6 regionId = (regionX << 8) | regionY
- Returns:
- the packed region ID
-
translate
public Coord translate(int x, int y)
-
dx
public Coord dx(int x)
-
dy
public Coord dy(int y)
-
-