2D Tile Based World Problem

Started by
17 comments, last by Trienco 11 years, 7 months ago
I have a 2D world built of tiles, mapped to their proper coordinates in the world. I've set my viewport and GlOrtho to the size of the screen, and am using glScale to zoom in/out. Only when I do it I'm only seeing the part of the world originally rendered. I believe this to be because my glOrtho is restricting the tiles that are drawn. So do I need to reset my viewport, then my glOrtho and then do my glScale?
Advertisement
If you take a digital camera and hit zoom, do trees and people get bigger? No, the camera just sees less of the world. To scale with ortho you need to change how much it sees. Only the viewport is the size of the screen. Ortho is how far left in the world will hit the left edge of your screen and how far right in the world will map to the right.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

So I leave the viewport set to the resolution of the screen, and use glOrtho to control the left and right mappings of the world. glScale just makes things bigger or smaller, so probably is not the best way to zoom in and out since I'll either be rendering more than I need to, or have to change my ortho because I'm not rendering enough. True?
That did it. The viewport is set to the screen pixel resolution, and then ortho is being used to set what corresponds to the left and right portions of the screen. Now to just get the zoom working. I see two choices... Continue using glScale, which seems easiest, or further adjust the ortho to also reflect the zoom, which is slightly more complex because I have to keep the aspect ratio in mind. I'm off to experiment a bit. Thanks! =D
For orthographic zooming, I typically just scale the modelview matrix:
[source lang="cpp"]glMatrixMode( GL_MODELVIEW );
glScale(1.1f, 1.1f, 1.0f);[/source]
There are other methods, like scaling the projection matrix, but they usually require additional translations to do a proper "in place" zoom, whereas this method "just works" (in my experience).

+---------------------------------------------------------------------+

| Game Dev video tutorials -> http://www.youtube.com/goranmilovano | +---------------------------------------------------------------------+
Alright... so what I need to do is to make the default rendering view be a fully zoomed out view, and then use glScale to zoom in. My problem at the moment is that the zoom level that I render at is somewhere in the middle of the zoom levels I want to make available. I'll rework it a bit and it should work great. I wonder if there's a way I could also move the clipping plane when I zoom so the unseen geometry isn't being rendered as well....

I wonder if there's a way I could also move the clipping plane when I zoom so the unseen geometry isn't being rendered as well....


...?

By definition, "unseen" geometry is not rendered.

+---------------------------------------------------------------------+

| Game Dev video tutorials -> http://www.youtube.com/goranmilovano | +---------------------------------------------------------------------+
If you want to zoom, zoom. Don't scale, don't move closer to the object or any of the other misguided attempts to make stuff "look bigger" that will eventually result in clipping if you move to close or scale too much.

Imagine you zoom in on a house, but a branch from a tree in front of you is covering half of it. Does it make any sense for a zoom to magically have the branch disappear, because it got clipped or you moved past it?

As dpadam450 already said, zoom by adjusting the projection matrix like a "real camera" and you won't get any unexpected effects.

Why would you care about the aspect ratio? It doesn't change if you multiply ALL sides by the same factor (as in: the two dimensions that matter).

Get in the habit of setting your ortho projection at the beginning of each frame, multiply your dimensions with your current zoom factor and be done with it. It works best if your projection is symmetric (from -x to +x instead of from 0 to +x) or you will need to also shift the values to avoid drifting closer to one corner.

Zoom in: zoom factor / 1.2, zoom out: zoom factor * 1.2. (or whatever numbers works for you)
f@dzhttp://festini.device-zero.de

[quote name='Lance42' timestamp='1346691463' post='4976106']
I wonder if there's a way I could also move the clipping plane when I zoom so the unseen geometry isn't being rendered as well....


...?

By definition, "unseen" geometry is not rendered.
[/quote]

If you render a triangle and then use glScale to zoom as is suggested by some, OpenGL is still rendering the triangle, even though you can't see it. Or so I'm told.

If you want to zoom, zoom. Don't scale, don't move closer to the object or any of the other misguided attempts to make stuff "look bigger" that will eventually result in clipping if you move to close or scale too much.

Imagine you zoom in on a house, but a branch from a tree in front of you is covering half of it. Does it make any sense for a zoom to magically have the branch disappear, because it got clipped or you moved past it?

As dpadam450 already said, zoom by adjusting the projection matrix like a "real camera" and you won't get any unexpected effects.

Why would you care about the aspect ratio? It doesn't change if you multiply ALL sides by the same factor (as in: the two dimensions that matter).

Get in the habit of setting your ortho projection at the beginning of each frame, multiply your dimensions with your current zoom factor and be done with it. It works best if your projection is symmetric (from -x to +x instead of from 0 to +x) or you will need to also shift the values to avoid drifting closer to one corner.

Zoom in: zoom factor / 1.2, zoom out: zoom factor * 1.2. (or whatever numbers works for you)


I will do this and report back.

This topic is closed to new replies.

Advertisement