How would you solve this problem (c) in connection with understanding what square the user clicked in a board game?

So, I have this advice to play a board game ... The problem is, how do I know which square the user clicked on? I know the x and y coordinates, but how to automate it without having to track the specific locations of each square. (Also, the board size is variable ... so it can have many squares or very small, but the board always has the same height and width, that is, the same number of squares that go from left to right, like the number of squares going from top to bottom).

Thanks a lot for stack overflow :)

+2
source share
2 answers

The problem you are talking about is called โ€œcollectionโ€, and there are several solutions for this:

  • query-based occlusion selection (quite modern, but I haven't tried it yet - there is some kind of bombastic about this topic here )
  • geometric sampling (mathematics and independent of OpenGL),
  • color selection (a bit old and hacky, but very easy to implement).

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

0
source

All Articles