Finding tile x,y from world x,y

Post here your questions about the OpenSpace 2.x or notify bugs and suggestions.

Moderators: Lapo, Bax

Post Reply
EngineThatCould
Posts: 4
Joined: 04 May 2011, 23:17

Finding tile x,y from world x,y

Post by EngineThatCould »

Hi,

I need a mathematical formula that can take a world x,y (meaning x,y that is not local, but rather is on the whole map 'world') and transform it into the tile x,y it is on.

I know there are other ways of finding a tile (like getObjectsUnderPoint for example) but I have my reasons for needing this specifically :)

Anyone know the formula to do this under the openspace environment? (with the way that openspace works, which may differ from other isometric implementations - not all of them work the same, I suppose)

thanks.
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

I suggest you to use the AS3 methods localToGlobal and globalToLocal.
Paolo Bax
The SmartFoxServer Team
EngineThatCould
Posts: 4
Joined: 04 May 2011, 23:17

Post by EngineThatCould »

I don't understand how that can be used to find the Tile X,Y from the Point X,Y.

If I have a global Point and I want to know which Tile it corresponds to, what would doing a globalToLocal do to help?
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

Sorry, I didn't understand your question.
OpenSpace uses, internally, the getObjectsUnderPoint to locate the tile clicked by the user. No other solution is feasible, due to the fact that the tiles can have elevation. Unfortunately this is quite tricky to implement, because the tile structure is quite complex.

If instead you only use plain tiles in your map, then this can be quite easy because it is just a matter of some simple math.
Paolo Bax
The SmartFoxServer Team
EngineThatCould
Posts: 4
Joined: 04 May 2011, 23:17

Post by EngineThatCould »

I see, so assuming that we disregard elevation and (z) etc and consider everything to be a flat, simple grid, what would be the math formula for finding it? (just the x,y without z or elevation)
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

Considering the following example:
Image
read the "Inverse mapping" paragraph of this document:
http://allefant.com/articles/isometricprojection/
Paolo Bax
The SmartFoxServer Team
Post Reply