blob: 3eaf1438826abfca8d0eff6900cf1313629bcdd9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include "util.h"
#include <cmath>
Point2D ScreenToTile(Point2D source)
{
Point2D result {};
auto fx = (float)source.x;
auto fy = (float)source.y;
float xx = (fx / TileSize + fy / (TileSize / 2.f));
float yy = (fy / (TileSize / 2.f) - (fx / TileSize));
result.x = (int)floorf(xx - 1.5f); // Magic numbers
result.y = (int)floorf(yy - 0.5f);
return result;
}
|