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

佐手、 提交于 2019-12-11 00:06:06

问题


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 :)


回答1:


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




回答2:


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?



来源:https://stackoverflow.com/questions/4199358/how-would-you-solve-this-opengl-necessity-in-c-involving-knowing-in-which-squa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!