LibGDX How to adjust mouse aim angle calculation when screen is resized

I’m starting with a screen resolution of 1280 x 960 and that is the default resolution where mouse aiming is calculated thus:

angleRad = (float) (Math.atan2(screenX - (screenWidth / 2), screenY - (screenHeight / 2))); angle = (float) Math.toDegrees(angleRad - Math.PI / 2); angle = Math.round(angle) <= 0 ? angle += 360 : angle; if (Math.round(angle) == 360)     angle = 0; 

Which all works fine. But when the game is resized to some resolution with a vastly different ratio to the default, like for example 2560 x 1440 at full screen in my case, the aiming is off. The resize method is like this:

@Override public void resize(int width, int height) {     game.getViewport().update(width, height);     control.screenWidth = width;     control.screenHeight = height; } 

Where control.screenWidth and control.screenHeight are used in the above angle calculation and as the set resolution in other areas. The angle calculation when resized is roughly correct but tends to get further and further off course the further the aim is away from the player.

If the player aims straight up, down, left or right (N, S, W or E basically) then the aim is dead on, but veers off as aiming goes away from the player towards a screen edge – no doubt due to the resolution ratio difference.

We have these ratio differences which no doubt affect the angle calculation:

1280x960 1.33 ratio 2560x1440 1.77 ratio 

But I’m not sure how to take into account these ratios to adjust the angle calculation accordingly in my code?