• Advertisement

• ### Popular Now

• 14
• 12
• 9
• 10
• 13
• Advertisement
• Advertisement
• Advertisement

# Screen to world transformation breaks down when maximizing window

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

If you intended to correct an error in the post then please contact us.

## 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.

#### Share this post

##### Share on other sites
Advertisement
This is the formula I use for screen-to-world conversion:
// 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;

The zoom factor is already taken into account by the camera, which scales the viewport appropriately as the zoom changes. Other than that I'm not sure why you need to estimate anything. Your view frustum should tell you everything you need to know about the world coordinates that are visible.

#### Share this post

##### Share on other sites

• Advertisement