How would you solve this opengl necessity (in c) involving knowing in which square in a boardgame did the user click?

StackOverflow https://stackoverflow.com/questions/4199358

Question

So I have this board, to play a boardgame... The problem is, how do I know in which square did the user click on? I know the x and y coordinates, but how do I automate it, without the need to hunt down the specific locations of each square. (Also the size of the board is variable...so it can have lots of squares, or very few, but the board has always the same height and width, that is, the same number of squares running from left to right as the number of squares running from top to bottom).

Thank you so much stack overflow :)

Was it helpful?

Solution

There are a lot of options offered at: http://www.opengl.org/resources/faq/technical/selection.htm

OTHER TIPS

The problem you're talking about is called "picking" and there are several solutions for that:

  • occlusion query-based picking (quite modern, but I haven't tried it yet - there's some rant on that topic here),
  • geometric picking (mathematics, and independent of OpenGL),
  • color-based picking (a bit old and hackish, but very simple to implement).

I have previously described the last approach here:
OpenGL GL_SELECT or manual collision detection?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top