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()intgetFloorLevel()Set<Coord>getInstanced()intgetMatrixId()PositiongetPosition()floatgetPreciseX()floatgetPreciseY()intgetRegionId()Returns the region ID for this coordinate.CoordgetSource()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, getCoordView, 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, typically 128 units per world coord) into aCoord(world-coordinate space), preserving sub-tile precision.The fine X/Y values are divided by
CoordFine.UNITS_PER_SQUAREto recover the precise coords, which are exposed asgetPreciseX())} /getPreciseY().
-
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
-
getFloorLevel
public int getFloorLevel()
- Specified by:
getFloorLevelin interfaceSceneNode
-
getSource
public Coord getSource()
-
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)
-
-