I am working on a small game that uses a 2D map (made up out of tiles). I would now like to find out what tile is being selected by the user. As the map can move and scale (glTranslate(), glScale(), etc), I’m not entirely sure a direct conversion is possible.
So how do I obtain the “map” coordinates from the mouse coordinates on my screen?
I am working on a small game that uses a 2D map (made up
Share
If the map is drawn in 2D on the screen with no perspective, then it should just be some basic math to determine which tile is selected, based on the tile width and the translation.
For example you could do something like:
However this is specific to your engine.
If it is drawn with perspective, then you can use gluUnProject to get object coordinates out of window coordinates (or you could mimic this function with your own).