-
Notifications
You must be signed in to change notification settings - Fork 0
Coordinate Systems
There are several different co-ordinate systems which are used throughout CorsixTH. When the terms X and Y appear, it also needs to be known which co-ordinate system they are in. This page describes the co-ordinate systems which they might be in.
Generally, all world co-ordinates refer to a position in the game world. The world is always viewed in an isometric perspective, and is made up of tiles like the following:
It is worth noting that when viewed individually (like above), a tile is 64 pixels wide, and 32 pixels tall. World co-ordinates are also known as tile co-ordinates, though tile co-ordinates are typically integers (whereas world co-ordinates do not have to be integers). When directions are mentioned with respect to world co-ordinates, they should be interpreted as in the following image:
In this co-ordinate system, the origin is (0, 0), the X unit vector (1, 0) represents movement one tile to the east, and the Y unit vector (0, 1) represents movement one tile to the south. To give an example of this, the following image has the C++ world co-ordinates at the intersections of the red lines annotated on it:
C++ code is typically only concerned with tiles, and so tile co-ordinates are usually used (which, as previously mentioned, are integer world co-ordinates). The distinction is subtle but important; the world co-ordinate (3, 4) refers to a tile and a position on that tile - the tile co-ordinate (3, 4) refers to an entire tile. The following image has the C++ tile co-ordinates for each tile annotated on in the centre of each tile:
The most common type of world co-ordinates, at least in Lua code, are Lua world co-ordinates. They are similar to C++ world co-ordinates, except that the Lua world origin is (1, 1) rather than (0, 0). The reason for this is historical, as in Lua, arrays are 1-based rather than 0-based, and the world was originally represented as 2D Lua array. To give an example of this, the following image has the Lua world co-ordinates at the intersections of the red lines annotated on it:
Lua tile co-ordinates are to Lua world co-ordinates as C++ tile co-ordinates are to C++ world co-ordinates. The following image has the Lua tile co-ordinates for each tile annotated on in the centre of each tile:
Generally, all screen co-ordinates are integers which identify a particular pixel on the screen.
Screen co-ordinates which are relative to the world origin are called absolute screen co-ordinates because they do not change as the screen is scrolled. To give an example of this, the following image has the absolute screen co-ordinates at the intersections of the red lines annotated on it:
Relative screen co-ordinates, also called canvas co-ordinates, give a position relative to the top-left hand corner of the (client area of the) window. To give an example of this, the following image has the relative screen co-ordinates at the intersections of the red lines annotated on it:
By comparing the images for C++ world co-ordinates and absolute screen co-ordinates, it should be clear that the origin (0, 0) is the same in both systems, that the vector (1, 0) in world co-ordinates is equivalent to the vector (32, 16) in screen co-ordinates, and that the vector (0, 1) in world co-ordinates is equivalent to the vector (-32, 16) in screen co-ordinates. Thus we can express a transformation from C++ world co-ordinates (Xw, Yw) to absolute screen co-ordinates (Xs, Ys) by the following matrix:
By using some elementary matrix operations, the inverse transformation (from absolute screen co-ordinates to C++ world co-ordinates) can be found:
Converting world co-ordinates to tile co-ordinates is a simple - just discard the fractional part of the world co-ordinates. Mathematically, this is the floor operation.
Back to the Home page