Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 MarkS   Prime Members   -  Reputation: 882

Like
0Likes
Like

Posted 31 August 2012 - 05:20 AM

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, 31 August 2012 - 05:47 AM.


Sponsor:

#2 LorenzoGatti   Crossbones+   -  Reputation: 2733

Like
0Likes
Like

Posted 31 August 2012 - 09:13 AM

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.
Produci, consuma, crepa

#3 MarkS   Prime Members   -  Reputation: 882

Like
0Likes
Like

Posted 07 September 2012 - 10:34 AM

It is hard to tell from text alone, but it would seem that I have either annoyed you or offended you. Posted Image 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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS