CoordFine¶
Overview¶
A CoordFine represents a 3D world position within the game world, in Fine units, as opposed to the tile position found in CoordGrid, which is in Grid units.
An important distinction is that a CoordFine also includes a vertical Y position, whereas a CoordGrid does not.
Examples¶
-- CoordGrid position
local coordGrid = CoordGrid._0_50_50_32_32
-- CoordFine equivalent; each tile contains 512 Fine units
local pos = Vector3.new( (50 * 64 + 32) * 512, 0.0, (50 * 64 + 32) * 512 )
local coordFine = CoordFine.new(0, pos)
Constructors¶
CoordFine(level, x, z)¶
Constructs a CoordFine from the provided level and X & Z world positions.
Set the Y world position to a default of 0.0.
| Parameter | Type | Description |
|---|---|---|
| level | Integer | The level of the coord (0-3). |
| x | Float | The X world position of the coord, in Fine units. |
| z | Float | The Z world position of the coord, in Fine units. |
Example
local worldX = ((50.0 * 64.0) + 32.0) * 512.0
local worldZ = ((50.0 * 64.0) + 32.0) * 512.0
local coordFine = CoordFine.new(0, worldX, worldZ)
-- Equivalent position vector
local worldVec = Vector3.new(worldX, 0.0, worldZ)
-- coordFine.position == worldVec
-- Equivalent CoordGrid
local coordGrid = CoordGrid._0_50_50_32_32
local coordFine2 = coordGrid.ToCoordFine(false)
-- coordFine == coordFine2
CoordFine(level, x, y, z)¶
Constructs a CoordFine from the provided level and X, Y & Z world positions.
| Parameter | Type | Description |
|---|---|---|
| level | Integer | The level of the coord (0-3). |
| x | Float | The X world position of the coord, in Fine units. |
| y | Float | The Y world position of the coord, in Fine units. |
| z | Float | The Z world position of the coord, in Fine units. |
Example
local worldX = ((50.0 * 64.0) + 32.0) * 512.0
local worldY = 2048.0
local worldZ = ((50.0 * 64.0) + 32.0) * 512.0
local coordFine = CoordFine.new(0, worldX, worldY, worldZ)
-- Equivalent position vector
local worldVec = Vector3.new(worldX, worldY, worldZ)
-- coordFine.position == worldVec
-- Converting to a CoordGrid and back to a CoordFine will lose the Y position
local coordGrid = coordFine:ToCoordGrid()
local coordFine2 = CoordFine.FromCoordGrid(coordGrid, false)
-- coordFine != coordFine2
CoordFine(level, position)¶
Constructs a CoordFine from the provided level and world position vector.
| Parameter | Type | Description |
|---|---|---|
| level | Integer | The level of the coord (0-3). |
| position | Vector3 | The world position of the coord, in Fine units. |
Example
local worldX = ((50.0 * 64.0) + 32.0) * 512.0
local worldY = 2048.0
local worldZ = ((50.0 * 64.0) + 32.0) * 512.0
local worldVec = Vector3.new(worldX, worldY, worldZ)
local coordFine = CoordFine.new(0, worldVec)
-- coordFine.position == worldVec
-- Converting to a CoordGrid and back to a CoordFine will lose the Y position
local coordGrid = coordFine:ToCoordGrid()
local coordFine2 = CoordFine.FromCoordGrid(coordGrid, false)
-- coordFine != coordFine2
CoordFine(coordGrid, fromCentre)¶
Constructs a CoordFine from the provided CoordGrid.
Use fromCentre to indicate whether the resulting CoordFine position is:
- From the bottom-left of the tile, when
fromCentre = false - From the centre of the tile, when
fromCentre = true
Info
The centre of a tile is 256 fine units from the bottom-left corner.
For example:
-- Non-centred
local fineX = ((coordGrid.mapsquareX * 64) + coordGrid.localTileX) * 512
-- Centred
local fineX = (((coordGrid.mapsquareX * 64) + coordGrid.localTileX) * 512) + 256
Also see CoordGrid:ToCoordFine and CoordFine.FromCoordGrid
| Parameter | Type | Description |
|---|---|---|
| coordGrid | CoordGrid | A coord grid position. |
| fromCentre | Boolean | Boolean value which indicates where to centre the constructed CoordFine. |
Example
local coordGrid0 = CoordGrid._0_50_50_32_32
local coordFine1 = CoordFine.new(coordGrid0, false)
local coordFine2 = CoordFine.new(coordGrid0, true)
-- coordFine1.position != coordFine2.position
local coordGrid1 = coordFine1:ToCoordGrid()
local coordGrid2 = coordFine2:ToCoordGrid()
-- coordGrid0 == coordGrid1 == coordGrid2
CoordFine(coordFine)¶
Constructs a CoordFine from the provided CoordFine.
| Parameter | Type | Description |
|---|---|---|
| coordFine | CoordFine | A CoordFine position. |
Example
Functions¶
FromCoordGrid¶
Returns a CoordFine constructed from the provided CoordGrid.
Use fromCentre to indicate whether the resulting CoordFine position is:
- From the bottom-left of the tile, when
fromCentre = false - From the centre of the tile, when
fromCentre = true
Info
The centre of a tile is 256 fine units from the bottom-left corner.
For example:
-- Non-centred
local fineX = ((coordGrid.mapsquareX * 64) + coordGrid.localTileX) * 512
-- Centred
local fineX = (((coordGrid.mapsquareX * 64) + coordGrid.localTileX) * 512) + 256
Also see CoordGrid:ToCoordFine and CoordFine(coordGrid, fromCentre)
| Parameter | Type | Description |
|---|---|---|
| coordGrid | CoordGrid | A CoordGrid position. |
| fromCentre | Boolean | Boolean value which indicates where to centre the output CoordFine. |
| Returns | Description |
|---|---|
| CoordFine | A CoordFine position. |
Example
local coordGrid0 = CoordGrid._0_50_50_32_32
local coordFine1 = CoordFine.FromCoordGrid(coordGrid0, false)
local coordFine2 = CoordFine.FromCoordGrid(coordGrid0, true)
-- coordFine1.position != coordFine2.position
local coordGrid1 = coordFine1:ToCoordGrid()
local coordGrid2 = coordFine2:ToCoordGrid()
-- coordGrid0 == coordGrid1 == coordGrid2
Methods¶
ToCoordGrid¶
Returns a CoordGrid using the current CoordFine as a base.
The value of level is copied directly.
The values of position.x and position.z are converted to Grid Units.
The value of position.y is discarded.
The Fine->Grid unit conversion is as follows:
Also see CoordGrid.FromCoordFine and CoordGrid(coordFine)
| Parameter | Type | Description |
|---|---|---|
| coordFine | CoordFine | A CoordFine position. |
| Returns | Description |
|---|---|
| CoordGrid | A CoordGrid position. |
Example
Properties¶
| Name | Type | Writeable | Description |
|---|---|---|---|
| level | Integer | The level of this CoordFine. Valid range is 0-3. | |
| x | Float | The world position X of this CoordFine, in Fine units. | |
| y | Float | The world position Y of this CoordFine, in Fine units. | |
| z | Float | The world position Z of this CoordFine, in Fine units. | |
| position | Vector3 | The world position of this CoordFine, in Fine units. | |
| mapSquareX | Integer | The mapsquare X of this CoordFine, in Grid units. Valid range is 0-199. | |
| mapSquareZ | Integer | The mapsquare Z of this CoordFine, in Grid units. Valid range is 0-199. | |
| localX | Integer | The local tile X of this CoordFine, in Grid units. Valid range is 0-63. | |
| localZ | Integer | The local tile Z of this CoordFine, in Grid units. Valid range is 0-63. |