From 31efe32ade161d2493c77a2df54a2ea8c75d51d2 Mon Sep 17 00:00:00 2001 From: frutiemax Date: Thu, 16 Jul 2020 01:55:48 -0400 Subject: [PATCH] Related to #12160: Refactor viewport_coord_to_map_coord using Rotate (#12247) --- src/openrct2/interface/Viewport.cpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 17e89a2e2d..09e3d84355 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -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); } /**