OpenGL:缩放自适应网格线 [英] OpenGL: Zoom adaptive grid lines

查看:339
本文介绍了OpenGL:缩放自适应网格线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个视口网格,就像大多数3D建模器中看到的那样,其中缩放可调整网格间距,以使线条不会变得太密或相距太远.例如缩小将间距从1m更改为2m,然后将5m更改为10m,然后将20m等.

I'm trying to make a viewport grid like the ones seen in most 3D Modelers where zooming adjusts the grid spacing so lines don't get too dense or too far apart. For example zooming out changes the spacing from 1m to 2m then 5m then 10m and 20m etc. Any help?

推荐答案

在这里,它通常并不像您最初想象的那样复杂.例如,您可能会注意到,即使从栅格平面到查看器的最近距离可能发生变化,平移和环绕摄影机也不会影响该栅格密度.同样,更改FOV不会影响所选的网格单位大小,即使理想情况下,它应该给出如何显着倾斜和缩小视图的范围.

Here it's usually not as complicated as you might think it would be initially. For example, you might notice that panning and orbiting the camera has no effect on that grid density, even though the nearest distance from grid plane to viewer could be changing. Likewise, changing FOV has no effect on the chosen grid unit size, even though ideally perhaps it should given how it can significantly skew and narrow the view.

因此,相对于对目标的观察,通常只有这种基本的一维类型的zoom distance概念(相机枢轴),并且它不涉及任何花哨的数学运算,只是调整了一个标量,该标量会影响传递给glScale的值或glTranslate,例如

So there's usually just this basic, 1-dimensional kind of notion of zoom distance relative to the look at target (camera pivot), and it involves no fancy math, just adjusting a scalar that affects values passed to glScale or glTranslate, e.g.

随着它的增加,绘制网格(可能会捕捉到它)所使用的单位大小也会增加,这里通常不是一些出色的数学解决方案,而只是从该缩放距离到硬编码单位大小的线性映射例如1mm,2mm,5mm,10mm,20mm,50mm,1cm等.

As it increases, so does the unit size used for drawing the grid (and possibly snapping to it), and here it's often not some brilliant, mathematical solution but just a linear mapping from that zoom distance to hard-coded unit sizes like 1mm, 2mm, 5mm, 10mm, 20mm, 50mm, 1cm, etc.

这些事情通常不是某些算法论文的结果,而只是开发人员/设计人员坐下来并对其进行调整,直到它们看起来/感觉正确为止.如果您要开发3D软件,我建议您不要忽视与用户交互相关的基本解决方案,因为很容易使3D确信所有事情都必须是复杂的,并且需要大量的研究和完善的工作.背后的精确数学解决方案.对于UI部分,您可以摆脱更多非正式的解决方案.

These kinds of things usually aren't the result of some algorithmic paper but just a developer/designer sitting down and tweaking things until they look/feel about right. If you're trying to develop a 3D software, I'd recommend never to overlook this basic solution for things related to user interaction because it's easy to become convinced in 3D that everything has to be complicated and have a lot of research and a perfectly-accurate mathematical solution behind it. For the UI parts, you can get away with far more informal solutions.

有时,针对这些UI视觉/交互的形式化数学解决方案在实践中并不像这些相互混淆的解决方案那样运作良好,正如您可能已经注意到的那样,用户界面来自更学术的领域(通常在数学上更聪明)和算法来处理这些事情,但实际上不那么直观.

Sometimes the formal mathematical solutions for these UI visuals/interactions don't work quite as well in practice as these kludged solutions, as you might have noticed in the user interfaces coming from the more academic realm (which are usually much smarter mathematically and algorithmically for these things, but actually less intuitive).

这篇关于OpenGL:缩放自适应网格线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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