简体   繁体   English

3d线鼠标采摘

[英]3d line mouse picking

I have 3d scene with thousands lines. 我有3D场景,有数千行。 I want to be able to pick ALL 3d lines in the 10 pixels neighborhood of the mouse cursor (with perspective projection). 我希望能够在鼠标光标的10个像素附近选择所有3d线(带有透视投影)。 I've tried to use unique-color based method. 我尝试使用基于唯一颜色的方法。 But this method is not suitable for me because I can not pick ALL lines - only the closest one. 但是此方法不适合我,因为我无法选择所有行-仅选择最接近的行。 Is there any acceptable solution of my problem ? 我的问题有没有可以接受的解决方案? OpenGL or DirectX - it does not matter. OpenGL或DirectX-没关系。

Why not just compute the distance between those lines and the point in question? 为什么不仅仅计算这些线与所讨论点之间的距离? It's a 2D line-to-point distance computation. 这是2D线到点距离的计算。 You could probably implement it with a Perl script that calls a Python executable that calls a Lua interpeter and still do 100,000 of them in a second. 您可能可以使用Perl脚本来实现它,该脚本调用一个Python可执行文件,该可执行文件调用Lua插入器,并且在一秒钟内仍执行100,000个。

This is one of those tunnel-vision "when all I have is a hammer, every problem looks like a nail" issues. 这就是那些“我只有锤子,每个问题都像钉子一样”的问题。 You don't have to use rendering to do picking. 不必使用渲染做采摘。

In old OpenGL (<= 2.1), you can use Selection Mode to do exactly this. 在旧的OpenGL(<= 2.1)中,可以使用“选择模式”来精确地做到这一点。 Use gluPickMatrix() to select a small region around the cursor position, initialize a selection buffer, slip into selection mode ( glRenderMode(GL_SELECT) ), and redraw the scene. 使用gluPickMatrix()在光标位置附近选择一个小区域,初始化选择缓冲区,滑入选择模式( glRenderMode(GL_SELECT) ),然后重新绘制场景。 Then come back out of selection mode and your selection buffer will be full names (really id numbers) of all the drawn objects that appear in your region of interest. 然后退出选择模式,您的选择缓冲区将是出现在您感兴趣的区域中的所有绘制对象的全名(真正的ID号)。 You'll have to modify your drawing code a little to push/pop names ( glPushName(objIndex) ) around each object that you render as well. 您还需要稍微修改一下绘图代码,以在您渲染的每个对象周围推送/弹出名称( glPushName(objIndex) )。

It's not the most efficient use of modern graphics hardware, but it always works. 这不是现代图形硬件的最有效使用,但它始终有效。

Neither OpenGL nor DirectX will do the job for you, because they only draw things. OpenGL和DirectX都不会为您完成这项工作,因为它们只会画图。 What you must do is projecting all the lines in your scene to the screen and test, if the closest point to the selected position is nearer than your desired max distance. 您必须做的是将场景中的所有线条投影到屏幕上并进行测试,如果到所选位置的最接近点是否比所需的最大距离更近。 You can accelerate this by keeping the lines in some spatial subdivision structure (like a Kd tree or similar) to discard quickly all those lines which definitely don't match your criteria. 您可以通过将线条保留在某种空间细分结构(例如Kd树或类似的对象)中以快速丢弃所有绝对不符合您条件的线条来加速此过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM