OpenGL-拾取(最快方式) [英] OpenGL - Picking (fastest way)

查看:445
本文介绍了OpenGL-拾取(最快方式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现场景选择(用于鼠标单击,移动等).最好,最快的方法是什么?我曾经将glSelectBufferglRenderModeGL_SELECT结合使用,然后再次渲染整个场景(当然是带有增强功能,没有纹理,浓密的着色器等).

I would like to implement scene picking (for mouse clicks, moves, etc.). What is the best, fastest way? I used to use glSelectBuffer and glRenderMode with GL_SELECT and then render whole scene again (of course with boost, without textures, heavy shaders, etc.).

每次鼠标单击,移动和拖动时,递归渲染一个数字(几何ID)的所有节点和几何体的速度太慢.有人知道更好的方法吗?

It's too slow render recursively all nodes and geometries for one number (geometry ID) on every mouse click, move and drag. Does anybody know better way?

读取深度缓冲区的解决方案似乎很麻烦,但是如果我不想选择某些几何形状而它们已经淹没了缓冲该怎么办呢?查找包含点的框可能不精确,因为点可以位于多个框中.

Solution with reading depth buffer seems fain, but what if I don't want to pick some geometries and they are already drown to buffer? Finding box which contains point can be imprecisely, since point can be in multiple boxes.

是否可以在一次绘制中写入两个帧缓冲区,深度缓冲区?然后,我可以通过着色器将几何ID写入一个缓冲区.那速度呢?

Is it possible to write into two frame buffers, depth buffers in one draw? Then I can write geometry id to one buffer through shader. And what about speed?

推荐答案

由于我是新来的,我无法直接回答Joe,所以我将在这里进行. 我从来没有尝试过这样做的方法,所以我不确定它是否对您有用. 希望如果没有的话,我会给你我的版本. 您可以通过多种方式进行操作. 再次渲染整个场景似乎有点过分.

Since I'm new here, I can't answer Joe directly so I'll do it here. I never tried his way of doing this, so I'm not sure if it will work for you. Hopefully it will, if not: I'll give you my version. There are a number of ways you can do it. Rendering the whole scene again seems like an overkill.

我做的方法是OBB-Ray相交测试.您考虑几何周围的面向对象的边界框,并检测它们是否与您单击鼠标所发出的光线碰撞.如果您需要较低的精度,我会说选择AABB甚至Sphere.更精确:凸包.请注意,您要求的精度越低,算法就越快. 可能有些大材小用,但是如果您不想自己实现算法,可以考虑使用物理库进行加速计算,例如Bullet或PhysX. 另一种方法是我以前从未使用过的OpenGL hack.

The way I do it is an OBB-Ray intersection test. You consider Object-Oriented Bounding Boxes around your geometry and detect if they collide with the ray coming from you mouse click. If you need less precision I'd say go for AABB or even Sphere. More precision: convex hull. Just be aware of the fact that the less precision you ask for, the faster the algorithm. It might be an overkill but consider using a physics library for accelerated calculation like Bullet or PhysX if you don't want to implement the algoritms yourself. And another way is an OpenGL hack which I haven't used before.

这里介绍了所有这些方法: http://www.opengl-tutorial.org/miscellaneous/clicking-on-对象/

All these ways to do it are explained here: http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/

这篇关于OpenGL-拾取(最快方式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆