Screen to world transformation breaks down when maximizing window

This topic is 4500 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.

Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5
gaxio
10

• 14
• 30
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631777
• Total Posts
3002308
×