Set perspective camera distance based on bounding box diameter so we no longer get dizzy!!!! #7338
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #3699
Partially resolves #5484
Might help this person, too #3892
Fixes small beds having camera look very zoomed in.
Fixes an issue when a part is scaled too large by accident. When scaled back down, if the camera distance is too large, the GUI flickers.
Perspective camera distance is now constantly set to bounding box radius. It now shrinks smoothly, as well as growing, to accommodate new sizes, to a minimum distance equal to bounding box radius.
This will help a lot with Prusa XL, and other larger printers. Also helps with the mini, SL1S, and smaller printers. Also helps with medium printers. So, all printers.
Basically, no matter the size of the print bed, the camera perfectly scales to behave "the same," relatively. I.e., when a new printer config is loaded, the new bed is framed exactly as the previous one, regardless of size difference. The camera is virtually positioned just outside the edge of the bed, allowing the added sense of perspective. (Rather, a bounding box radius from center of bed, which from the top can be less than expected but still works well.)
The following screenshots were all taken with the default camera orientation. The camera always adapts to new scene sizes:




Notice the difference between perspective and orthographic cameras on the SL1S, patched vs unpatched:




This also allows for when people accidentally scale their models way too big, and need to scale it back down. The camera now recovers distance, and therefore FOV, smoothly with no glitching or flickering, as described in this old code comment from stock PrusaSlicer source:
The reason for newly not including the gizmos in the bounding box is so when rescaling with the gizmo, there is no sudden jumps in camera view when exiting gizmo. (Rather -- not so many. Extreme scales still have weird jumps occasionally, but this is to be expected... try it out. This solution works unreasonably well compared to the previous commented-out method.)
All this said... the original comment called for a new "smarter code" solution. I don't think any of my "code" can be called smart. So I will let you all decide how to proceed.
Side note:
For some reason, when changing camera.cpp sometimes I get this MSVC compiler error on first build. This is fixed by rebuilding all projects, and sometimes just by clicking build again:
If you encounter the above error, please just try building again, and if that doesn't work, nuke the the build directory "RelWithDebInfo" or whatever and build all projects. I promise the code does compile in MSVC, from fresh projects/solution.