Skip to content
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

Merged
merged 3 commits into from
Oct 31, 2019
Merged

Conversation

bigbike
Copy link
Contributor

@bigbike bigbike commented Oct 29, 2019

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:
image

After window size was changed:
image

How Has This Been Tested

Local test:
Initial screen:
image

After window size was changed:
image

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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.
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Oct 29, 2019
@bigbike
Copy link
Contributor Author

bigbike commented Oct 29, 2019

This PR is ready to be reviewed. Thanks.

Copy link
Contributor

@aclegg3 aclegg3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

int width = event.windowSize()[0];
int height = event.windowSize()[1];
renderCamera_->setProjectionMatrix(width, height, znear_, zfar_, hfov_);
} // namespace
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the // namespace?

Copy link
Contributor Author

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());
Copy link
Collaborator

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.

Copy link
Contributor Author

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. :-) )

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@bigbike bigbike merged commit 3673f44 into master Oct 31, 2019
@bigbike bigbike deleted the reshape branch October 31, 2019 01:38
bigbike added a commit that referenced this pull request Oct 31, 2019
-) revert the extra code and comments in #322;
-) move setAspectRatioPolicy out of the setProjectionMatrix;
-) set the correct policy in the viewer;
bigbike added a commit that referenced this pull request Oct 31, 2019
* Revert #322 and add "reshape" functionality to utility viewer

-) revert the extra code and comments in #322;
-) move setAspectRatioPolicy out of the setProjectionMatrix;
-) set the correct policy in the viewer;

* minor

* minor

* minor

* minor
@bigbike bigbike mentioned this pull request Aug 28, 2020
11 tasks
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
…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
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants