Skip to content

Commit

Permalink
Revert #322 and add "reshape" functionality to utility viewer (#331)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bigbike authored Oct 31, 2019
1 parent 8cc26de commit c18f580
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
9 changes: 3 additions & 6 deletions src/esp/gfx/RenderCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RenderCamera::RenderCamera(scene::SceneNode& node)
: Magnum::SceneGraph::AbstractFeature3D{node} {
node.setType(scene::SceneNodeType::CAMERA);
camera_ = new MagnumCamera(node);
camera_->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::NotPreserved);
}

RenderCamera::RenderCamera(scene::SceneNode& node,
Expand All @@ -33,12 +34,8 @@ void RenderCamera::setProjectionMatrix(int width,
float zfar,
float hfov) {
const float aspectRatio = static_cast<float>(width) / height;
// TODO:
// Warning: By dedault, SceneGraph::Camera class can handle aspect ratio
// preservation in the setViewport() call automatically. But here it was
// disabled for some reason. Will revisit.
camera_->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::NotPreserved)
.setProjectionMatrix(
camera_
->setProjectionMatrix(
Matrix4::perspectiveProjection(Deg{hfov}, aspectRatio, znear, zfar))
.setViewport(Magnum::Vector2i(width, height));
}
Expand Down
18 changes: 7 additions & 11 deletions src/utils/viewer/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ class Viewer : public Magnum::Platform::Application {

bool drawObjectBBs = false;

const float hfov_ = 90.0f;
const float znear_ = 0.01f;
const float zfar_ = 1000.0f;

Magnum::Timeline timeline_;
};

Expand Down Expand Up @@ -180,9 +176,13 @@ Viewer::Viewer(const Arguments& arguments)
rgbSensorNode_->translate({0.0f, rgbSensorHeight, 0.0f});
agentBodyNode_->translate({0.0f, 0.0f, 5.0f});

int width = viewportSize[0];
int height = viewportSize[1];
renderCamera_->setProjectionMatrix(width, height, znear_, zfar_, hfov_);
renderCamera_->setProjectionMatrix(viewportSize.x(), // width
viewportSize.y(), // height
0.01f, // znear
1000.0f, // zfar
90.0f); // hfov
renderCamera_->getMagnumCamera().setAspectRatioPolicy(
Magnum::SceneGraph::AspectRatioPolicy::Extend);

// Load navmesh if available
const std::string navmeshFilename = io::changeExtension(file, ".navmesh");
Expand Down Expand Up @@ -360,10 +360,6 @@ void Viewer::drawEvent() {
void Viewer::viewportEvent(ViewportEvent& event) {
GL::defaultFramebuffer.setViewport({{}, framebufferSize()});
renderCamera_->getMagnumCamera().setViewport(event.windowSize());

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

void Viewer::mousePressEvent(MouseEvent& event) {
Expand Down

0 comments on commit c18f580

Please sign in to comment.