OpenGL鼠标选取策略
我正在使用 OpenGL 渲染在给定平面中旋转对称的对象模型,并且我希望用户能够滚动模型(可能在旋转、缩放等之后)并确定世界坐标 < em>在鼠标当前指向的模型上。
我提到对称性的原因是我正在使用各个组件的 VBO 构建模型易于使用。与我正在做的事情的类比是自行车车轮 - 我有一个 VBO 用于辐条,一个用于轮毂,一个用于车轮/轮胎,并且我会多次重复使用辐条 VBO(之后)适当的平移和旋转)。我的第一个问题是,这种安排是否有利于我想要做的挑选?例如,我希望生成的模型中的每个个体都是“可挑选的”。 我是否需要为网格中的每个四边形/三角形使用单独的 VBO 来进行我想要做的选择?我真的希望情况并非如此...
另外,会是什么使用的最佳挑选算法?我只听到过关于 OpenGL 内置选择模式的负面评价。提前致谢!
I am using OpenGL to render a model of an object that is rotationally-symmetric in a given plane, and I want the user to be able to scroll over the model (possibly after rotations, zooms, etc.) and determine what world coordinate on the model the mouse is currently pointing to.
The reason I mentioned the symmetry is that I'm building the model using VBOs of individual components for ease of use. An analogy to what I'm doing would be a bicycle wheel - I'd have one VBO for a spoke, one for the hub, and one for the wheel/tire and I'd resuse the spoke VBO a number of times (after suitable translations and rotations). My first question is, is this arrangement conducive to the kind of picking that I'm trying to do? I want each individual spoke in the resulting model to be "pickable", for example. Do I need a seperate VBO for each quad/triangle in the mesh to do the kind of selection that I'm trying to do? I really hope that's not the case...
Also, what would be the best picking algorithm to use? I've heard nothing but negative things about OpenGL's built-in selection mode. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于你关于VBO的问题,拥有少量VBO并重用它们并没有什么问题。事实上,您可以将所有内容都集中在一个 VBO 中,并且只对其进行索引。对于自行车车轮的类比,辐条顶点后面可以是轮胎顶点,并且您可以多次绘制辐条的顶点(甚至可以使用实例,请参阅
glMultiDrawElements
),然后从相同的 VBO,但从不同的索引(轮胎)开始。关于您的选择问题,获取鼠标下模型上的点的世界坐标的一种简单方法是读回深度值(1x1 矩形上的
glReadPixels
,最好使用像素缓冲区对象在最后一帧的数据上,这样就可以隐藏传输延迟)。然后调用 gluUnproject 来获取世界坐标。Regarding your question about VBOs, there is nothing wrong in having few VBOs and reuse them. In fact, you can have everything in one VBO and only index into it. For your bicycle wheel analogy, the spoke vertices could be followed by the tire vertices, and you could draw the vertices of the spokes several times (maybe even using instancing, see
glMultiDrawElements
), followed by drawing from the same VBO but starting at a different index, the tire.Regarding your picking question, one easy way of getting the world coordinate of the point on the model under the mouse would be to read back the depth value (
glReadPixels
on a 1x1 rectangle, preferrably with a pixel buffer object on the last frame's data, that way you hide the transfer latency). Then callgluUnproject
to get world coordinates.