# Screen to world transformation breaks down when maximizing window

This topic is 4314 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I hastily put together a formula for transalting screen coordinates to world coordinates using orthographic projection. The formula is not mathemaitcally exact, but it works in most cases. It stems from visually estimating the width and height ratio with world coordinates that are ASSUMED to be aligned with the edges of the window. I zoom in, I translate, I change the window size, and it all works fine. Unless I MAXIMIZE the window! I mean, it's just a change in size, all sizes work, even manually extending the window borders to the edges of the screen works, but specifically the act of getting a new size after a maximize window operation makes the coordinate translation procedure show it's rough edges, and the error is maximized. Here's a diagram of how the procedure works.

// Convert window coordinates into camera coordinatesfloat CameraX, CameraY;CameraX = ((float)mouse.x / window.Width()) * Viewport.Width + Viewport.Left;CameraY = ((float)mouse.y / window.Height()) * Viewport.Height + Viewport.Bottom;// Convert camera coordinates into world coordinatesfloat WorldX, WorldY;WorldX = CameraX + Camera.Position.X;WorldY = CameraY + Camera.Position.Y;