I want to find out which facet is under the mouse cursor in an OpenGL application. Using the selection buffer seems quite inaccurate to me. Are there other solutions?
我想在OpenGL应用程序中找出鼠标光标下的哪个方面。使用选择缓冲区对我来说似乎非常不准确。还有其他解决方案吗?
3 个解决方案
#1
Do it manually, using ray intersection. Use your camera matrix (if not explicit, you can query it from OpenGL), use it to generate a picking ray in world space, and see whether it intersects your particular face or not. Sort intersections on depth (t), and you have the closest face under the cursor.
使用光线交叉手动完成。使用相机矩阵(如果不明确,可以从OpenGL查询),使用它在世界空间中生成拾取光线,并查看它是否与您的特定面相交。在深度(t)上对交点进行排序,您在光标下面具有最近的面。
Depending on your data structure (hierarchy, etc) and size this could be either really slow or really efficient.
根据您的数据结构(层次结构等)和大小,这可能非常慢或非常有效。
#2
A common trick is to paint each facet in a different color (simply 0x000001 to n) render offscreen and get the color under the mouse point.
一个常见的技巧是将每个facet以不同的颜色(简单地为0x000001到n)绘制在屏幕外渲染并获得鼠标点下的颜色。
#1
Do it manually, using ray intersection. Use your camera matrix (if not explicit, you can query it from OpenGL), use it to generate a picking ray in world space, and see whether it intersects your particular face or not. Sort intersections on depth (t), and you have the closest face under the cursor.
使用光线交叉手动完成。使用相机矩阵(如果不明确,可以从OpenGL查询),使用它在世界空间中生成拾取光线,并查看它是否与您的特定面相交。在深度(t)上对交点进行排序,您在光标下面具有最近的面。
Depending on your data structure (hierarchy, etc) and size this could be either really slow or really efficient.
根据您的数据结构(层次结构等)和大小,这可能非常慢或非常有效。
#2
A common trick is to paint each facet in a different color (simply 0x000001 to n) render offscreen and get the color under the mouse point.
一个常见的技巧是将每个facet以不同的颜色(简单地为0x000001到n)绘制在屏幕外渲染并获得鼠标点下的颜色。
#3
Also take a look at this section of the OpenGL FAQ.
另请参阅OpenGL常见问题解答的这一部分。