1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-23 14:54:30 +01:00

Related to #12160: Refactor viewport_coord_to_map_coord using Rotate (#12247)

This commit is contained in:
frutiemax
2020-07-16 01:55:48 -04:00
committed by GitHub
parent a961d9784f
commit 31efe32ade

View File

@@ -1073,27 +1073,12 @@ ScreenCoordsXY screen_coord_to_viewport_coord(rct_viewport* viewport, const Scre
CoordsXY viewport_coord_to_map_coord(const ScreenCoordsXY& coords, int32_t z)
{
CoordsXY ret{};
switch (get_current_rotation())
{
case 0:
ret.x = -coords.x / 2 + coords.y + z;
ret.y = coords.x / 2 + coords.y + z;
break;
case 1:
ret.x = -coords.x / 2 - coords.y - z;
ret.y = -coords.x / 2 + coords.y + z;
break;
case 2:
ret.x = coords.x / 2 - coords.y - z;
ret.y = -coords.x / 2 - coords.y - z;
break;
case 3:
ret.x = coords.x / 2 + coords.y + z;
ret.y = coords.x / 2 - coords.y - z;
break;
}
return ret;
constexpr uint8_t inverseRotationMapping[NumOrthogonalDirections] = { 0, 3, 2, 1 };
// Reverse of translate_3d_to_2d_with_z
CoordsXY ret = { coords.y - coords.x / 2 + z, coords.y + coords.x / 2 + z };
auto inverseRotation = inverseRotationMapping[get_current_rotation()];
return ret.Rotate(inverseRotation);
}
/**