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

Add FOV API to OSG viewer #1048

Merged
merged 7 commits into from
Apr 3, 2018
Merged

Add FOV API to OSG viewer #1048

merged 7 commits into from
Apr 3, 2018

Conversation

jslee02
Copy link
Member

@jslee02 jslee02 commented Apr 1, 2018


Before creating a pull request

  • Document new methods and classes
  • Format new code files using clang-format

Before merging a pull request

  • Set version target by selecting a milestone on the right side
  • Summarize this change in CHANGELOG.md

@jslee02 jslee02 added this to the DART 6.5.0 milestone Apr 1, 2018
@jslee02 jslee02 requested a review from mxgrey April 1, 2018 14:38
@codecov
Copy link

codecov bot commented Apr 2, 2018

Codecov Report

Merging #1048 into release-6.5 will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff              @@
##           release-6.5    #1048   +/-   ##
============================================
  Coverage        56.58%   56.58%           
============================================
  Files              314      314           
  Lines            24312    24312           
============================================
  Hits             13758    13758           
  Misses           10554    10554

Copy link
Member

@mxgrey mxgrey left a comment

Choose a reason for hiding this comment

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

Mostly nitpicks.

{
dtwarn << "[Viewer::getMasterCameraFieldOfView] Attemping to set vertical "
<< "field of view while the camera isn't perspective view. "
<< "Ignoring this request.\n";
Copy link
Member

Choose a reason for hiding this comment

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

If we say that we're ignoring the request, shouldn't we return here?

/// \param[in] fov Vertical field of view in degree.
void setVerticalFieldOfView(double fov);

/// Retruns the vertical field of view of the master camera of the view.
Copy link
Member

Choose a reason for hiding this comment

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

Retruns --> Returns

@@ -293,6 +293,15 @@ class Viewer : public osgViewer::Viewer, public dart::common::Subject
/// Get the root ::osg::Group of this Viewer
const ::osg::ref_ptr<::osg::Group>& getRootGroup() const;

/// Sets the vertical field of view of the master camera of the view.
/// \param[in] fov Vertical field of view in degree.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: degree --> degrees

void setVerticalFieldOfView(double fov);

/// Retruns the vertical field of view of the master camera of the view.
/// \return Vertical field of view in degree if the camera is perspective
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: degree --> degrees

double zFar;

const auto* camera = getCamera();
assert(camera);
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean we always assume the return value of getCamera() should always be non-null? Is it feasible that it will ever be nullptr (e.g. if this Viewer doesn't have any cameras)? I'm not finding anything in the OSG docs that indicate what we should expect.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I also couldn't find related docs from OSG. I think it would be safer we just ignore when getCamera() returns null. Let me change this code so. Let me know what you think.

@@ -843,6 +843,53 @@ const ::osg::ref_ptr<::osg::Group>& Viewer::getRootGroup() const
return mRootGroup;
}

//==============================================================================
void Viewer::setVerticalFieldOfView(double fov)
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: const double

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, I see the reason for this suggestion; I found this SO post says specifying const modifier helps the compiler with optimizations. However, AFAIK, we haven't used const when we pass value parameters in DART codebase. Do you suggest we follow this convention from now on?

Copy link
Member

Choose a reason for hiding this comment

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

I recommend using const for every variable which isn't intentionally mutable. Besides compiler optimizations, it also catches bugs where a variable might get unintentionally modified.

Note that you don't need the const in the declaration of the function. E.g.:

// in foo.hpp
void foo(int value);

// in foo.cpp
void foo(const int value)
{
  /* ... do things ... */
}

works perfectly fine, because the function signature is the same, whether or not a value parameter is const-qualified. On the other hand, function signatures are different between const-references and mutable lvalue references, so this would not work:

// in foo.hpp
void foo(int& value);

// in foo.cpp
void foo(const int& value)
{
  /* ... do things ... */
}

Copy link
Member

Choose a reason for hiding this comment

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

To illustrate a potential bug, we might accidentally type

const bool result = camera->getProjectionMatrixAsPerspective(
      fov, aspectRatio, zNear, zFar);

instead of


const bool result = camera->getProjectionMatrixAsPerspective(
      fovy, aspectRatio, zNear, zFar);

which would accidentally overwrite the value that the caller passed to the function.

Copy link
Member Author

@jslee02 jslee02 Apr 2, 2018

Choose a reason for hiding this comment

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

Thanks for the examples. I see the point of preventing a potential bug, but I have a little concern with that their function signatures are not "exactly" the same. Wouldn't it be more clear to just put const to both of declaration and definition in this case?

Edit: I'm fine with either way; just trying to learn. 😄

Copy link
Member

Choose a reason for hiding this comment

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

Just to be clear, the function signatures, in the technical sense, are exactly the same. A human might see that the text is different between the declaration and the definition, but the compiler/linker does not care, and the ABI signature will be identical.

There's nothing inherently wrong with putting the const in the declaration as well, although it's often discouraged because it's seen as unnecessary noise which a user has no reason to care about (it makes no difference whatsoever to a user whether a value parameter of a function is const-qualified or not, because it has no impact on how they use the function or how the function behaves).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the explanation. That sounds reasonable to me as well. It's Good to know!

@jslee02 jslee02 merged commit 6d7b453 into release-6.5 Apr 3, 2018
@jslee02 jslee02 deleted the enhance/osg_fov branch April 3, 2018 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants