Veyha
Veyha

Reputation: 87

How to convert screen position to isometric position

How to convert the screen position (X,Y) to an isometric position?

I have code that converts the isometric position to the screen position here: http://jsfiddle.net/CR3JS/

This is the formula axis: http://s15.postimage.org/xyxfukxkp/iso_Axis.jpg

And my question is: How to convert the screen position (X,Y) to an isometric position?

Something like:

screenToIsometric(144, 88) -> X: 10, Y: 0, Z: 1

Upvotes: 2

Views: 723

Answers (1)

Oleg V. Volkov
Oleg V. Volkov

Reputation: 22421

You can't have one single X,Y,Z point, because one 2D screen position will map to several different tiles - one at each different Z levels. If you trying to figure on what object in isometric view user did click, easiest, though somewhat dirty way would be just loop over all Z levels starting from upper to lower, use reverse of formula in your sample function and check if there's anything suitable for click at position, proceeding to lower level if this place is empty.

Upvotes: 1

Related Questions