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?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- Is GLFW designed to use without LWJGL (in java)?
- thread_local variables initialization
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
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.
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 toglScale
orglTranslate
, e.g.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.
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.
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).