Class CoordFine
- java.lang.Object
-
- org.rspeer.game.coord.CoordFine
-
public class CoordFine extends Object
Represents a coordinate in fine space, where each world tile (Coord) is composed of128fine units. Fine space provides sub-tile precision used for movement, interpolation, animation, and rendering.A
CoordFinestores:matrixId– the ID of theRSWorldMatrixdefining the local scene originx– fine-space X coordinate (matrix-relative)y– fine-space Y coordinate (matrix-relative)floorLevel– the plane (0–3)
The coordinate is expressed in matrix-relative fine space. To convert a world
Coordinto fine units, the world matrix base coordinates are subtracted, then multiplied by128, then sub-tile offsets are added.One full world tile equals
128fine units.In the game engine, this is referred to as
CoordFine
-
-
Field Summary
Fields Modifier and Type Field Description static intHALF_SQUARE_UNITSstatic CoordFineNILstatic intUNITS_PER_SQUARE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CoordFinedx(int x, int granularity)Translates this fine coordinate horizontally (along the X axis) by a fractional tile amount determined by the given granularity.CoordFinedy(int y, int granularity)Translates this fine coordinate vertically (along the Y axis) by a fractional tile amount determined by the given granularity.booleanequals(Object obj)static CoordFinefrom(int matrixId, int x, int y)Constructs a new fine coordinate on floor level0, using the given matrix ID as the scene origin.static CoordFinefrom(int matrixId, int x, int y, int floorLevel)Constructs a new fine coordinate at the given matrix-relative fine X/Y values.static CoordFinefromCoord(RSWorldMatrix matrix, Coord coord, int subX, int subY)Converts a world tile coordinate into a fine coordinate *relative to a specificRSWorldMatrix*, using the given sub-tile offsets.static CoordFinefromCoord(Coord coord, int subX, int subY)Converts a world tile coordinate into a fine coordinate *relative to the matrix associated with the givenCoord*, using the specified sub-tile offsets.static CoordFinefromCoordCenter(RSWorldMatrix matrix, Coord coord)Creates a fine coordinate at the center of a world tile, relative to the givenRSWorldMatrix.static CoordFinefromCoordCenter(Coord coord)Creates a fine coordinate at the center of a world tile, relative to the matrix associated with the given coord.static CoordFinefromCoordOrigin(RSWorldMatrix matrix, Coord coord)Creates a fine coordinate at the exact origin (bottom-left corner) of a world tile, relative to the givenRSWorldMatrix.static CoordFinefromCoordOrigin(Coord coord)Creates a fine coordinate at the exact origin (bottom-left corner) of a world tile, relative to the matrix associated with the given coord.CoordViewgetCoordView()intgetFloorLevel()intgetMatrixId()SceneContextgetSceneContext()SceneContextgetSceneContext(int matrixId)intgetSubX()Returns the fine X offset within the current tile.intgetSubY()Returns the fine Y offset within the current tile.intgetX()intgetY()inthashCode()static intprecision(int granularity)Computes the fine-unit step size for a given subdivision precision.static CoordFinetoRootMatrix(RSWorldMatrix matrix, CoordFine fine)StringtoString()CoordFinetranslate(int x, int y)CoordFinetranslate(int x, int y, int granularity)Translates this fine coordinate by a movement expressed in tile units, scaled by a specified granularity.CoordFinetranslate(Direction direction, int granularity)Translates this fine coordinate in the direction specified byDirection, scaled by the given granularity.CoordFinetranslateHalfCoord()
-
-
-
Field Detail
-
NIL
public static final CoordFine NIL
-
UNITS_PER_SQUARE
public static final int UNITS_PER_SQUARE
- See Also:
- Constant Field Values
-
HALF_SQUARE_UNITS
public static final int HALF_SQUARE_UNITS
- See Also:
- Constant Field Values
-
-
Method Detail
-
precision
public static int precision(int granularity)
Computes the fine-unit step size for a given subdivision precision.For example:
precision(1) = 128 // whole tile precision(2) = 64 // half-tile precision(4) = 32 // quarter-tile precision(8) = 16 // eighth-tile
- Parameters:
granularity- number of subdivisions per tile (must divide 128)- Returns:
- the fine-unit size of each subdivided segment
-
from
public static CoordFine from(int matrixId, int x, int y, int floorLevel)
Constructs a new fine coordinate at the given matrix-relative fine X/Y values.The coordinate is associated with a specific world matrix identified by
matrixId. The valuesxandyare interpreted directly in matrix-relative fine space (not world-absolute space).- Parameters:
matrixId- the ID of the world matrix defining the local scene originx- fine-space X coordinate, relative to that matrixy- fine-space Y coordinate, relative to that matrixfloorLevel- the floor/plane (0–3)- Returns:
- a new
CoordFinerepresenting the given matrix-relative fine position
-
from
public static CoordFine from(int matrixId, int x, int y)
Constructs a new fine coordinate on floor level0, using the given matrix ID as the scene origin.- Parameters:
matrixId- the ID of the world matrix defining the local scene originx- fine-space X coordinate, relative to that matrixy- fine-space Y coordinate, relative to that matrix- Returns:
- a new
CoordFineon floor level0
-
toRootMatrix
public static CoordFine toRootMatrix(RSWorldMatrix matrix, CoordFine fine)
-
fromCoord
public static CoordFine fromCoord(RSWorldMatrix matrix, Coord coord, int subX, int subY)
Converts a world tile coordinate into a fine coordinate *relative to a specificRSWorldMatrix*, using the given sub-tile offsets.The world-space
Coordis first transformed into scene-space by subtractingmatrix.getBaseX()andmatrix.getBaseY(). The resulting scene-space tile coordinates are then scaled into fine units (128 per tile), and finallysubXandsubYare added to position the coordinate within the tile.subXandsubYmust be in the range0–127, representing the fine-unit offset inside a tile.- Parameters:
matrix- the world matrix providing the base/scene origincoord- the world-space tile coordinate to convertsubX- fine X offset within the tile (0–127)subY- fine Y offset within the tile (0–127)- Returns:
- a
CoordFinerepresenting the matrix-relative fine location
-
fromCoord
public static CoordFine fromCoord(Coord coord, int subX, int subY)
Converts a world tile coordinate into a fine coordinate *relative to the matrix associated with the givenCoord*, using the specified sub-tile offsets.This is a convenience overload that resolves the appropriate
RSWorldMatrixby callingGame.getMatrixAt(coord), then delegates tofromCoord(RSWorldMatrix, Coord, int, int).- Parameters:
coord- the world-space tile coordinatesubX- fine X offset within the tile (0–127)subY- fine Y offset within the tile (0–127)- Returns:
- a
CoordFinerepresenting the matrix-relative fine location
-
fromCoordOrigin
public static CoordFine fromCoordOrigin(RSWorldMatrix matrix, Coord coord)
Creates a fine coordinate at the exact origin (bottom-left corner) of a world tile, relative to the givenRSWorldMatrix.The world-space
Coordis first converted into scene-space using the provided matrix, then scaled into fine units (128 per tile). The resulting fine coordinate will be at sub-tile offsets(0, 0).- Parameters:
matrix- the world matrix providing the base/scene origincoord- the world-space tile coordinate- Returns:
- a
CoordFinelocated at the tile origin in matrix-relative fine space
-
fromCoordOrigin
public static CoordFine fromCoordOrigin(Coord coord)
Creates a fine coordinate at the exact origin (bottom-left corner) of a world tile, relative to the matrix associated with the given coord.This is a convenience overload that resolves the appropriate
RSWorldMatrixviaGame.getMatrixAt(coord), then delegates tofromCoordOrigin(RSWorldMatrix, Coord).- Parameters:
coord- the world-space tile coordinate- Returns:
- a
CoordFinelocated at the tile origin in matrix-relative fine space
-
fromCoordCenter
public static CoordFine fromCoordCenter(RSWorldMatrix matrix, Coord coord)
Creates a fine coordinate at the center of a world tile, relative to the givenRSWorldMatrix.This uses
precision(2)(which equals64fine units), placing the coordinate at the center of the tile at sub-tile offsets(64, 64).- Parameters:
matrix- the world matrix providing the base/scene origincoord- the world-space tile coordinate- Returns:
- a
CoordFinelocated at the tile center in matrix-relative fine space
-
fromCoordCenter
public static CoordFine fromCoordCenter(Coord coord)
Creates a fine coordinate at the center of a world tile, relative to the matrix associated with the given coord.This is a convenience overload that resolves the appropriate
RSWorldMatrixviaGame.getMatrixAt(coord), then delegates tofromCoordCenter(RSWorldMatrix, Coord).- Parameters:
coord- the world-space tile coordinate- Returns:
- a
CoordFinelocated at the tile center in matrix-relative fine space
-
getCoordView
public CoordView getCoordView()
-
getSceneContext
public SceneContext getSceneContext()
-
getSceneContext
public SceneContext getSceneContext(int matrixId)
-
getMatrixId
public int getMatrixId()
-
getX
public int getX()
-
getY
public int getY()
-
getFloorLevel
public int getFloorLevel()
-
getSubX
public int getSubX()
Returns the fine X offset within the current tile.Equivalent to
x % 128.- Returns:
- sub-tile X offset in the range 0–127
-
getSubY
public int getSubY()
Returns the fine Y offset within the current tile.Equivalent to
y % 128.- Returns:
- sub-tile Y offset in the range 0–127
-
translate
public CoordFine translate(int x, int y, int granularity)
Translates this fine coordinate by a movement expressed in tile units, scaled by a specified granularity.Granularity defines how many sbdivisions a tile is split into:
granularity = 1 -> full tile movement (128 fine units) granularity = 2 -> half-tile movement ( 64 fine units) granularity = 4 -> quarter-tile movement ( 32 fine units) granularity = 8 -> eighth-tile movement ( 16 fine units) ...
- Parameters:
x- the delta along the tile X axis (positive = east, negative = west)y- the delta along the tile Y axis (positive = north, negative = south)granularity- how many equal subdivisions of a tile to move per unit ofx/y- Returns:
- a new
CoordFineoffset by (x,y) at the given granularity
-
translate
public CoordFine translate(int x, int y)
- Parameters:
x- The fine x units to translatey- The fine y units to translate- Returns:
- a new
CoordFineoffset by (x,y)
-
translateHalfCoord
public CoordFine translateHalfCoord()
-
translate
public CoordFine translate(Direction direction, int granularity)
Translates this fine coordinate in the direction specified byDirection, scaled by the given granularity.This is equivalent to:
translate(direction.getXOffset(), direction.getYOffset(), granularity)
- Parameters:
direction- the movement direction (supports 4, 8, or 16 movement directions)granularity- how many subdivisions of a tile to move in the given direction- Returns:
- a new
CoordFinerepresenting the translated position
-
dx
public CoordFine dx(int x, int granularity)
Translates this fine coordinate horizontally (along the X axis) by a fractional tile amount determined by the given granularity.Positive
xmoves east; negative moves west.- Parameters:
x- the tile-based horizontal deltagranularity- how many subdivisions of a tile to move per unit ofx- Returns:
- a new
CoordFinerepresenting the translated position
-
dy
public CoordFine dy(int y, int granularity)
Translates this fine coordinate vertically (along the Y axis) by a fractional tile amount determined by the given granularity.Positive
ymoves north; negative moves south.- Parameters:
y- the tile-based vertical deltagranularity- how many subdivisions of a tile to move per unit ofy- Returns:
- a new
CoordFinerepresenting the translated position
-
-