SELECT或手动碰撞检测

SELECT或手动碰撞检测

本文介绍了OpenGL的GL_SELECT或手动碰撞检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

所见的图像中

我画设定轮廓(多边形)GL_LINE_STRIP的。现在,我要选择鼠标下的曲线(多边形)删除,move..etc 3D的。

I draw set of contours (polygons) as GL_LINE_STRIP.Now I want to select curve(polygon) under the mouse to delete,move..etc in 3D .

我想知道使用哪种方法:

I am wondering which method to use:

1,采用OpenGL的采摘和选择。 (glRenderMode(GL_SELECT))

1.use OpenGL picking and selection. ( glRenderMode(GL_SELECT) )

2,使用手册碰撞检测,用挑线,检查线是否每个多边形内部。

2.use manual collision detection , by using a pick-ray and check whether the ray is inside each polygon.

任何建议,

在此先感谢。

推荐答案

我强烈的建议不要GL_SELECT 。这种方法是很旧,没有新的GL版本,你就可能得到问题的现代图形卡。不要指望它由硬件支持 - 可能你会遇到一个软件(驱动程序)回退对许多GPU的这种模式,只要它会在所有的工作。使用您自己的风险:)

I strongly recommend against GL_SELECT. This method is very old and absent in new GL versions, and you're likely to get problems with modern graphics cards. Don't expect it to be supported by hardware - probably you'd encounter a software (driver) fallback for this mode on many GPUs, provided it would work at all. Use at your own risk :)

让我为您提供一种替代方法。

Let me provide you with an alternative.

有关固体,大的对象,有选择的则是古老的,好的方法:

For solid, big objects, there's an old, good approach of selection by:

  • 启用和设置剪刀测试1x1的窗口,在光标位置
  • 在画画面,没有灯光,材质及多重采样,把一个唯一纯色的每一个重要的实体 - 这种颜色将成为对象ID采摘
  • 在调用glReadPixels和检索的颜色,然后将有助于查明拾取对象
  • 清除缓冲器,复位剪刀到正常尺寸和绘制场景通常

这给你一个非常可靠的每个对象的采摘方法。此外,绘画和清除只有1个像素以最小的每个像素的操作也不会真的伤害你的表现,除非你是短期的顶点处理能力(不可能的,我认为),或​​真有大量的对象,并有可能获得CPU-势必对绘制调用次数(但话又说回来,我相信这是可以优化送人到一个绘图调用,如果你可以通过颜色的每像素数据)。

This gives you a very reliable "per-object" picking method. Also, drawing and clearing only 1 pixel with minimal per-pixel operation won't really hurt your performance, unless you are short on vertex processing power (unlikely, I think) or have really a lot of objects and are likely to get CPU-bound on the number of draw calls (but then again, I believe it's possible to optimize this away to a single draw call if you could pass the colour as per-pixel data).

在RGB颜色是3无符号字节,但它应该是可以额外使用framebuffer的alpha通道的最后一个字节,所以你会得到总共4个字节 - 足够的任何32位指针存储对象作为颜色

The colour in RGB is 3 unsigned bytes, but it should be possible to additionally use the alpha channel of the framebuffer for the last byte, so you'd get 4 bytes in total - enough to store any 32-bit pointer to the object as the colour.

另外,您可以创建一个特定的像素格式的专用帧缓冲对象(如 GL_R32UI ,甚至 GL_RG32UI 如果您需要64位)。

Alternatively, you can create a dedicated framebuffer object with a specific pixel format (like GL_R32UI, or even GL_RG32UI if you need 64 bits) for that.

以上是一个很好的和快速的替代性(无论是在可靠性方面和实施时间)为严格的几何方法。

The above is a nice and quick alternative (both in terms of reliability and in implementation time) for the strict geometric approach.

这篇关于OpenGL的GL_SELECT或手动碰撞检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:34