-
Notifications
You must be signed in to change notification settings - Fork 285
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
Conversation
Codecov Report
@@ Coverage Diff @@
## release-6.5 #1048 +/- ##
============================================
Coverage 56.58% 56.58%
============================================
Files 314 314
Lines 24312 24312
============================================
Hits 13758 13758
Misses 10554 10554 |
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.
Mostly nitpicks.
dart/gui/osg/Viewer.cpp
Outdated
{ | ||
dtwarn << "[Viewer::getMasterCameraFieldOfView] Attemping to set vertical " | ||
<< "field of view while the camera isn't perspective view. " | ||
<< "Ignoring this request.\n"; |
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.
If we say that we're ignoring the request, shouldn't we return here?
dart/gui/osg/Viewer.hpp
Outdated
/// \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. |
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.
Retruns
--> Returns
dart/gui/osg/Viewer.hpp
Outdated
@@ -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. |
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.
Nitpick: degree
--> degrees
dart/gui/osg/Viewer.hpp
Outdated
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 |
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.
Nitpick: degree
--> degrees
dart/gui/osg/Viewer.cpp
Outdated
double zFar; | ||
|
||
const auto* camera = getCamera(); | ||
assert(camera); |
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.
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.
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.
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.
dart/gui/osg/Viewer.cpp
Outdated
@@ -843,6 +843,53 @@ const ::osg::ref_ptr<::osg::Group>& Viewer::getRootGroup() const | |||
return mRootGroup; | |||
} | |||
|
|||
//============================================================================== | |||
void Viewer::setVerticalFieldOfView(double fov) |
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.
Nitpick: const double
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.
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?
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 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 ... */
}
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.
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.
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.
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. 😄
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.
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).
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.
Thanks for the explanation. That sounds reasonable to me as well. It's Good to know!
Before creating a pull request
clang-format
Before merging a pull request
CHANGELOG.md