From 520d49705e15894f73d6e765587005a3766cc024 Mon Sep 17 00:00:00 2001 From: Sonic Dreamcaster Date: Wed, 23 Oct 2024 11:21:03 -0300 Subject: [PATCH] OTRConvertHUDXToScreenX --- src/port/Engine.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 665dc23b..28a24845 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -349,4 +349,21 @@ extern "C" int16_t OTRGetRectDimensionFromLeftEdge(float v) { extern "C" int16_t OTRGetRectDimensionFromRightEdge(float v) { return ((int)ceilf(OTRGetDimensionFromRightEdge(v))); +} + +extern "C" int32_t OTRConvertHUDXToScreenX(int32_t v) { + float gameAspectRatio = gfx_current_dimensions.aspect_ratio; + int32_t gameHeight = gfx_current_dimensions.height; + int32_t gameWidth = gfx_current_dimensions.width; + float hudAspectRatio = 4.0f / 3.0f; + int32_t hudHeight = gameHeight; + int32_t hudWidth = hudHeight * hudAspectRatio; + float hudScreenRatio = (hudWidth / 320.0f); + float hudCoord = v * hudScreenRatio; + float gameOffset = (gameWidth - hudWidth) / 2; + float gameCoord = hudCoord + gameOffset; + float gameScreenRatio = (320.0f / gameWidth); + float screenScaledCoord = gameCoord * gameScreenRatio; + int32_t screenScaledCoordInt = screenScaledCoord; + return screenScaledCoordInt; } \ No newline at end of file