Tile Map question. How to convert a resolution independent tile map to pixel coordinates?

Recommended Posts

MarkS    3502
I'd like to rework a tile engine I have been working on (for what seems like an eternity) to use resolution independent coordinates for the tiles(i.e., 0-1) instead of pixel coordinates. Doing so is rather easy. However, I want to be able to scale the tile map dynamically with the camera and this leads to an issue. If the tile's mip map level 0 is 256x256 pixels, for example, that is the largest I want the tiles to scale. This means that I need to know exactly how large the tiles are being drawn on screen; information that I will not have. If I want the tile map to initially start with 64x64 pixel tiles, I also need a way to set up the camera so that this happens.

How do I do this? The only thing I can think of is to use gluUnproject (or a hand rolled variant) on a random visible tile to get the screen coordinates and calculate from there, but that seems rather brute force and wont help with camera set up. Is there a more elegant way to go about this? Edited by MarkS

Share on other sites
LorenzoGatti    4442
You don't know how large the tiles are on screen? Hard to believe, as even in a 3D engine with an arbitrarily moving and zooming camera you can easily compute the worst case scaling of your tiles: the longest tile edge that can appear in screen coordinates is presumably one that lies on the near clipping plane (as close as possible, with no foreshortening) and is parallel to either side of the screen (depending on vertical and horizontal stretching), measured at the shortest "focal length" of your zoom and at the highest screen resolution.
It's only a little trigonometry, and it has nothing to do with "resolution independent" coordinates.
Apart from changing the camera projection matrix. the only thing that changes with camera movement is the selection of mipmaps, but it is automatic: texture coordinates remain constant.

Share on other sites
MarkS    3502
It is hard to tell from text alone, but it would seem that I have either annoyed you or offended you. [img]http://public.gamedev.net//public/style_emoticons/default/huh.png[/img] I apologize.

When I draw something in OpenGL, I typically do not concern myself with the physical (pixel) size of the object. I just make sure it fits in the viewport. The only time I have concerned myself with the actual size of an object is in my tile engine, in which the quads defining the tiles were expressly defined in pixel coordinates.

Maybe this is something that I should know. However, I do not. I do not even know where to begin. Keep in mind that I am a hobbyist, not a professional. I do this for fun. I use situations like this to learn what I do not know.