-
Notifications
You must be signed in to change notification settings - Fork 160
Coordinate Systems
There are three main types of coordinates used in OpenLoco. They are as follows: Point
, Pos2/Pos3
and TilePos2
.
Point
represent screen coordinates and are always therefore 2D. You can scale the coordinates from the screen to within a viewport using the ScreenToViewport::applyTransform
. This function will perform a ScreenToViewport::uiOffsetTransform
followed by a ScreenToViewport::scaleTransform
followed by a ScreenToViewport::viewOffsetTransform
. The inverse can be performed with ViewportToScreen
. All graphics functions are within the screen coordinates space and therefore take Point
. Care must be taken to know if the coordinates are pre or post viewport transforms.
Pos3
represent game coordinates and are therefore 3D. You can transform from game coordinates to Screen coordinates using gameToScreen
. To do the reverse there are a number of alternative methods depending on if only the surface is to be selected or if all tile data needs to be considered. Coordinates can be rotated using the Vector::Math::rotate
function. There are 4 rotations within the game. Each tile comprises of 32 units. When at zoom == 0 a unit is equal to a pixel. Often functions take a Pos2
when the height is not expected to matter.
TilePos2
represent coordinates of in game tiles and are Pos2 / 32
.