OTRConvertHUDXToScreenX

This commit is contained in:
Sonic Dreamcaster 2024-10-23 11:21:03 -03:00
parent 0900ba71ef
commit 520d49705e

View File

@ -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;
}