Files

81 lines
2.4 KiB
Markdown
Raw Permalink Normal View History

2015-12-02 11:47:58 +00:00
# Conversions to 2D Map
### Conversion of world coordinates to a 2D map texture coordinate (in pixels):
2018-10-03 18:24:44 +01:00
```csharp
public static Vector2 GetPixelCoordinates( Vector2 worldXZCoordinates, Vector2 mapOffset, UInt16 mapSizeFactor )
2018-10-03 18:24:44 +01:00
{
return ( worldXZCoordinates + mapOffset ) / 100f * mapSizeFactor + new Vector2( 1024f );
2018-10-03 18:24:44 +01:00
}
```
2022-04-06 03:54:47 -05:00
This assumes using the basic map textures that are 2048x2048. If you're using the small (1024x1024) map textures for some reason, divide the result by two.
2018-10-03 18:24:44 +01:00
### Conversion of map texture pixel coordinates (such as FishingSpot coordinates) to in-game 2D map coordinates:
```csharp
public static Vector2 GetGameMapCoordinates( Vector2 mapPixelCoordinates, UInt16 mapSizeFactor )
{
return mapPixelCoordinates / mapSizeFactor * 2f + Vector2.One;
}
2015-12-02 11:47:58 +00:00
```
### Conversion of world coordinates to in-game 2D map coordinates (using the above functions):
2018-10-03 18:24:44 +01:00
```csharp
public static Vector2 WorldToMapCoordinates( Vector2 worldXZCoordinates, Vector2 mapOffset, UInt16 mapSizeFactor )
2015-12-02 11:47:58 +00:00
{
return GetGameMapCoordinates( GetPixelCoordinates( worldXZCoordinates, mapOffset, mapSizeFactor ), mapSizeFactor );
2015-12-02 11:47:58 +00:00
}
```
The game *truncates* the result of this to the first decimal place.
2015-12-02 11:47:58 +00:00
2018-10-03 18:24:44 +01:00
----
2015-12-02 11:47:58 +00:00
To translate a `levels.exd` position to an in-game X/Y:
2015-12-02 11:48:39 +00:00
```php
2016-01-09 23:25:20 +00:00
//
// This takes the X/Y, scale and tilescale from levels and converts it to
// and in-game X/Y position, I have not found tile scale in the files
// and it's never not been 50 (50px per tile), its not 100% accurate,
// tilescale is actually something like 49.951219... (2048/41)
//
public function mapsTranslateXYZToGame($x, $y, $scale, $tilescale = 50)
2015-12-02 11:47:58 +00:00
{
2016-01-09 23:25:20 +00:00
if ($x == 0 || $y == 0 || $scale == 0) {
return false;
}
2015-12-02 11:47:58 +00:00
$map = 2048 / ($scale / 100);
2016-01-09 23:25:20 +00:00
$tilecount = $map / $tilescale;
$x = ceil(round(($x / $tilescale) + ($tilecount / 2),1));
$y = ceil(round(($y / $tilescale) + ($tilecount / 2),1));
2015-12-02 11:47:58 +00:00
return [
'x' => $x,
'y' => $y,
];
}
```
And finally, to translate an in game X/Y to a `levels.exd` position which can then be converted to a 2D or Long/Lat:
2015-12-02 11:48:39 +00:00
```php
2016-01-09 23:25:20 +00:00
//
// Translates a X/Y from in-game to a levels output (which can then be translate dto lat/long
// this is quite accurate, not found it to be off at all. Requires map scale
//
public function mapsTranslateGameToXYZ($x, $y, $scale)
2015-12-02 11:47:58 +00:00
{
2016-01-09 23:25:20 +00:00
$scale = $scale / 100;
$x = ($x*50)-25-(1024 / $scale);
$y = ($y*50)-25-(1024 / $scale);
return [
'x' => $x,
'y' => $y,
];
2015-12-02 11:47:58 +00:00
}
```