mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Fix ViewportPosToMapPos using the wrong rotation
This commit is contained in:
@@ -1688,8 +1688,8 @@ void InputScrollViewport(const ScreenCoordsXY& scrollScreenCoords)
|
|||||||
int32_t y = mainWindow->savedViewPos.y + viewport->view_height / 2;
|
int32_t y = mainWindow->savedViewPos.y + viewport->view_height / 2;
|
||||||
int32_t y_dy = mainWindow->savedViewPos.y + viewport->view_height / 2 + dy;
|
int32_t y_dy = mainWindow->savedViewPos.y + viewport->view_height / 2 + dy;
|
||||||
|
|
||||||
auto mapCoord = ViewportPosToMapPos({ x, y }, 0);
|
auto mapCoord = ViewportPosToMapPos({ x, y }, 0, viewport->rotation);
|
||||||
auto mapCoord_dy = ViewportPosToMapPos({ x, y_dy }, 0);
|
auto mapCoord_dy = ViewportPosToMapPos({ x, y_dy }, 0, viewport->rotation);
|
||||||
|
|
||||||
// Check if we're crossing the boundary
|
// Check if we're crossing the boundary
|
||||||
// Clamp to the map minimum value
|
// Clamp to the map minimum value
|
||||||
|
|||||||
@@ -805,7 +805,7 @@ CoordsXY ViewportInteractionGetTileStartAtCursor(const ScreenCoordsXY& screenCoo
|
|||||||
{
|
{
|
||||||
z = TileElementHeight(mapPos);
|
z = TileElementHeight(mapPos);
|
||||||
}
|
}
|
||||||
mapPos = ViewportPosToMapPos(initialVPPos, z);
|
mapPos = ViewportPosToMapPos(initialVPPos, z, viewport->rotation);
|
||||||
mapPos.x = std::clamp(mapPos.x, initialPos.x, initialPos.x + 31);
|
mapPos.x = std::clamp(mapPos.x, initialPos.x, initialPos.x + 31);
|
||||||
mapPos.y = std::clamp(mapPos.y, initialPos.y, initialPos.y + 31);
|
mapPos.y = std::clamp(mapPos.y, initialPos.y, initialPos.y + 31);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ namespace OpenRCT2::Scripting
|
|||||||
if (viewport != nullptr)
|
if (viewport != nullptr)
|
||||||
{
|
{
|
||||||
auto centre = viewport->viewPos + ScreenCoordsXY{ viewport->view_width / 2, viewport->view_height / 2 };
|
auto centre = viewport->viewPos + ScreenCoordsXY{ viewport->view_width / 2, viewport->view_height / 2 };
|
||||||
auto coords = ViewportPosToMapPos(centre, 24);
|
auto coords = ViewportPosToMapPos(centre, 24, viewport->rotation);
|
||||||
|
|
||||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||||
auto obj = duk_push_object(ctx);
|
auto obj = duk_push_object(ctx);
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ CoordsXYZ ViewportAdjustForMapHeight(const ScreenCoordsXY& startCoords, uint8_t
|
|||||||
CoordsXY pos{};
|
CoordsXY pos{};
|
||||||
for (int32_t i = 0; i < 6; i++)
|
for (int32_t i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
pos = ViewportPosToMapPos(startCoords, height);
|
pos = ViewportPosToMapPos(startCoords, height, rotation);
|
||||||
height = TileElementHeight(pos);
|
height = TileElementHeight(pos);
|
||||||
|
|
||||||
// HACK: This is to prevent the x and y values being set to values outside
|
// HACK: This is to prevent the x and y values being set to values outside
|
||||||
@@ -596,7 +596,7 @@ void ViewportUpdatePosition(WindowBase* window)
|
|||||||
auto viewportMidPoint = ScreenCoordsXY{ window->savedViewPos.x + viewport->view_width / 2,
|
auto viewportMidPoint = ScreenCoordsXY{ window->savedViewPos.x + viewport->view_width / 2,
|
||||||
window->savedViewPos.y + viewport->view_height / 2 };
|
window->savedViewPos.y + viewport->view_height / 2 };
|
||||||
|
|
||||||
auto mapCoord = ViewportPosToMapPos(viewportMidPoint, 0);
|
auto mapCoord = ViewportPosToMapPos(viewportMidPoint, 0, viewport->rotation);
|
||||||
|
|
||||||
// Clamp to the map minimum value
|
// Clamp to the map minimum value
|
||||||
int32_t at_map_edge = 0;
|
int32_t at_map_edge = 0;
|
||||||
@@ -1100,11 +1100,11 @@ void Viewport::Invalidate() const
|
|||||||
ViewportInvalidate(this, { viewPos, viewPos + ScreenCoordsXY{ view_width, view_height } });
|
ViewportInvalidate(this, { viewPos, viewPos + ScreenCoordsXY{ view_width, view_height } });
|
||||||
}
|
}
|
||||||
|
|
||||||
CoordsXY ViewportPosToMapPos(const ScreenCoordsXY& coords, int32_t z)
|
CoordsXY ViewportPosToMapPos(const ScreenCoordsXY& coords, int32_t z, uint8_t rotation)
|
||||||
{
|
{
|
||||||
// Reverse of Translate3DTo2DWithZ
|
// Reverse of Translate3DTo2DWithZ
|
||||||
CoordsXY ret = { coords.y - coords.x / 2 + z, coords.y + coords.x / 2 + z };
|
CoordsXY ret = { coords.y - coords.x / 2 + z, coords.y + coords.x / 2 + z };
|
||||||
auto inverseRotation = DirectionFlipXAxis(GetCurrentRotation());
|
auto inverseRotation = DirectionFlipXAxis(rotation);
|
||||||
return ret.Rotate(inverseRotation);
|
return ret.Rotate(inverseRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1953,7 +1953,7 @@ std::optional<CoordsXY> ScreenGetMapXY(const ScreenCoordsXY& screenCoords, Viewp
|
|||||||
for (int32_t i = 0; i < 5; i++)
|
for (int32_t i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
int32_t z = TileElementHeight(cursorMapPos);
|
int32_t z = TileElementHeight(cursorMapPos);
|
||||||
cursorMapPos = ViewportPosToMapPos(start_vp_pos, z);
|
cursorMapPos = ViewportPosToMapPos(start_vp_pos, z, myViewport->rotation);
|
||||||
cursorMapPos.x = std::clamp(cursorMapPos.x, info.Loc.x, info.Loc.x + 31);
|
cursorMapPos.x = std::clamp(cursorMapPos.x, info.Loc.x, info.Loc.x + 31);
|
||||||
cursorMapPos.y = std::clamp(cursorMapPos.y, info.Loc.y, info.Loc.y + 31);
|
cursorMapPos.y = std::clamp(cursorMapPos.y, info.Loc.y, info.Loc.y + 31);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ void ViewportRender(DrawPixelInfo& dpi, const Viewport* viewport, const ScreenRe
|
|||||||
|
|
||||||
CoordsXYZ ViewportAdjustForMapHeight(const ScreenCoordsXY& startCoords, uint8_t rotation);
|
CoordsXYZ ViewportAdjustForMapHeight(const ScreenCoordsXY& startCoords, uint8_t rotation);
|
||||||
|
|
||||||
CoordsXY ViewportPosToMapPos(const ScreenCoordsXY& coords, int32_t z);
|
CoordsXY ViewportPosToMapPos(const ScreenCoordsXY& coords, int32_t z, uint8_t rotation);
|
||||||
std::optional<CoordsXY> ScreenPosToMapPos(const ScreenCoordsXY& screenCoords, int32_t* direction);
|
std::optional<CoordsXY> ScreenPosToMapPos(const ScreenCoordsXY& screenCoords, int32_t* direction);
|
||||||
|
|
||||||
void ShowGridlines();
|
void ShowGridlines();
|
||||||
|
|||||||
@@ -958,7 +958,7 @@ void WindowViewportGetMapCoordsByCursor(
|
|||||||
// Compute map coordinate by mouse position.
|
// Compute map coordinate by mouse position.
|
||||||
auto viewportPos = w.viewport->ScreenToViewportCoord(mouseCoords);
|
auto viewportPos = w.viewport->ScreenToViewportCoord(mouseCoords);
|
||||||
auto coordsXYZ = ViewportAdjustForMapHeight(viewportPos, w.viewport->rotation);
|
auto coordsXYZ = ViewportAdjustForMapHeight(viewportPos, w.viewport->rotation);
|
||||||
auto mapCoords = ViewportPosToMapPos(viewportPos, coordsXYZ.z);
|
auto mapCoords = ViewportPosToMapPos(viewportPos, coordsXYZ.z, w.viewport->rotation);
|
||||||
*map_x = mapCoords.x;
|
*map_x = mapCoords.x;
|
||||||
*map_y = mapCoords.y;
|
*map_y = mapCoords.y;
|
||||||
|
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ CoordsXY FootpathGetCoordinatesFromPos(const ScreenCoordsXY& screenCoords, int32
|
|||||||
{
|
{
|
||||||
z = TileElementHeight(position);
|
z = TileElementHeight(position);
|
||||||
}
|
}
|
||||||
position = ViewportPosToMapPos(start_vp_pos, z);
|
position = ViewportPosToMapPos(start_vp_pos, z, viewport->rotation);
|
||||||
position.x = std::clamp(position.x, minPosition.x, maxPosition.x);
|
position.x = std::clamp(position.x, minPosition.x, maxPosition.x);
|
||||||
position.y = std::clamp(position.y, minPosition.y, maxPosition.y);
|
position.y = std::clamp(position.y, minPosition.y, maxPosition.y);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user