-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix: add "reshape" functionality to utility viewer #322
Conversation
In the viewport event, we only reset the viewport but do not specify what to do when window size is changed. This PR is to update the projection matrix to handle it.
This PR is ready to be reviewed. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/utils/viewer/viewer.cpp
Outdated
int width = event.windowSize()[0]; | ||
int height = event.windowSize()[1]; | ||
renderCamera_->setProjectionMatrix(width, height, znear_, zfar_, hfov_); | ||
} // namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the // namespace
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is because the "vim" sometimes would automatically add the brackets for the user (totally unnecessarily), and if the user did not pay attention to it, and applied the clang-format, such "wrong" comments would be auto-added.
@@ -359,7 +360,11 @@ void Viewer::drawEvent() { | |||
void Viewer::viewportEvent(ViewportEvent& event) { | |||
GL::defaultFramebuffer.setViewport({{}, framebufferSize()}); | |||
renderCamera_->getMagnumCamera().setViewport(event.windowSize()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SceneGraph::Camera
class can handle aspect ratio preservation in the setViewport()
call automatically -- you only need to call Camera::setAspectRatioPolicy() with a desired value.
Looking at the code, here it's set to NotPreserved
for some reason, which effectively disables such handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Good to know. I do not know the purpose either. Will mark it, and solve it in recent "sensor/camera redesign" project (See slack for more details. Hope you can participate in this project. :-) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I commented here because doing it via setAspectRatioPolicy()
would result in less code overall. Merging this as-is just piled up more unnecessary tech debt in my opinion.
NotPreserved
is the default, and it probably makes sense for rendering headless -- there you have no arbitrary framebuffer resizes anyway. But having that there doesn't prevent the viewer from redefining it to handle this differently when having a GUI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely agree with @mosra . There is no reason to keep the NotPreserved
here and add extra code to implement behavior we could achieve by just changing the flag. Let's have a followup PR to remove the extra code + extra comments, and just switch the flag instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking when @msavva wrote it, he must have some reasons, so I was trying to respect that by not touching it, and leaving it to the future discussion.
But since he also leans towards changing it now, I am happy to write a new PR to roll back this one, and fix the issue in the other way.
-) revert the extra code and comments in #322; -) move setAspectRatioPolicy out of the setProjectionMatrix; -) set the correct policy in the viewer;
…rch#322) * Bug fix: add "reshape" functionality to utility viewer In the viewport event, we only reset the viewport but do not specify what to do when window size is changed. This PR is to update the projection matrix to handle it. * minor * minor
…y viewer (facebookresearch#331) * Revert facebookresearch#322 and add "reshape" functionality to utility viewer -) revert the extra code and comments in facebookresearch#322; -) move setAspectRatioPolicy out of the setProjectionMatrix; -) set the correct policy in the viewer; * minor * minor * minor * minor
In the viewport event, we only reset the viewport but do not specify what to do when window size is changed.
This PR is to update the projection matrix to handle it.
Motivation and Context
As titled.
The OLD version looks like this:
Initial screen:
After window size was changed:
How Has This Been Tested
Local test:
Initial screen:
After window size was changed:
Types of changes
Checklist