How to find the isometric tile under the mouse?

BlitzMax Forums/BlitzMax Beginners Area/How to find the isometric tile under the mouse?

Bremer(Posted 2010) [#1]
If you look at this picture:



In this example it is a 5x5 grid stored in an array.

How would you find out which tile that the user is clicking on?


Difference(Posted 2010) [#2]
First thing that springs to my mind is:

Make two axis vectors with origin in the middle lowest corner.
Find the points (pointA , pointB) closest to mousexy on both vectors.
Get the distance between the origin and pointA and quantize it to get tilex.
Get the distance between the origin and pointB and quantize it to get tiley.


xlsior(Posted 2010) [#3]
nice picture by the way -- are those graphics from the project you're actually working on?


Czar Flavius(Posted 2010) [#4]
Oh God this brings back terrible, terrible nightmares.


Bremer(Posted 2010) [#5]
are those graphics from the project you're actually working on?


No it was just something random I found using google.

Oh God this brings back terrible, terrible nightmares.


Why, is it overly complex?


Czar Flavius(Posted 2010) [#6]
Let's say each tile is 64x32. Create a 64x32 sprite which is just a blank, flat square ie no depth or height to the tile. The rest is transparent colour. Now have a 1x1 pixel image. Do a collision check between the 1x1 image on your mouse pointer and each tile's position using the flat (invisible) testing sprite.


Bremer(Posted 2010) [#7]
I have been spending some time looking around on the web again today, and I came across this article, which I am not sure why, I did not find yesterday:

http://www.gamedev.net/reference/articles/article747.asp

Using these tiles and a color map tile I managed to come up with something that looks to be working.








This is not code from the game, just something I quickly made to test out the suggestion from that article.

I hope someone else find it useful as well.


Enyaw(Posted 2010) [#8]
I wrote a bit of code that works out the mouse position on a isometric grid - http://www.blitzbasic.com/codearcs/codearcs.php?code=2608 that you might find usefull and easy to work out how it works.


Raph(Posted 2010) [#9]
I do what Czar Flavius said. More, if you do it when you go to draw, you can also do things like highlight the hovered tile, etc.