MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / GetAspectCorrect2DPosition

Function GetAspectCorrect2DPosition

TombEngine/Specific/trutils.cpp:190–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188 }
189
190 Vector2 GetAspectCorrect2DPosition(const Vector2& pos)
191 {
192 constexpr auto DISPLAY_SPACE_ASPECT = DISPLAY_SPACE_RES.x / DISPLAY_SPACE_RES.y;
193
194 auto screenRes = g_Renderer.GetScreenResolution().ToVector2();
195 float screenResAspect = screenRes.x / screenRes.y;
196 float aspectDelta = screenResAspect - DISPLAY_SPACE_ASPECT;
197
198 auto correctedPos = pos;
199 if (aspectDelta > EPSILON)
200 {
201 correctedPos.x *= 1.0f - (aspectDelta / 2);
202 }
203 else if (aspectDelta < -EPSILON)
204 {
205 correctedPos.y *= 1.0f - (aspectDelta / 2);
206 }
207
208 return correctedPos;
209 }
210
211 Vector2 Convert2DPositionToNDC(const Vector2& pos)
212 {

Callers 1

GetPositionOffsetMethod · 0.85

Calls 2

GetScreenResolutionMethod · 0.80
ToVector2Method · 0.45

Tested by

no test coverage detected