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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## DART 6

### DART 6.5.0 (201X-XX-XX)

* GUI

* Added FOV AI to OSG viewer: [#1048](https://github.com/dartsim/dart/pull/1048)

### [DART 6.4.0 (2018-03-26)](https://github.com/dartsim/dart/milestone/39?closed=1)

* Common
Expand Down
62 changes: 62 additions & 0 deletions dart/gui/osg/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,68 @@ const ::osg::ref_ptr<::osg::Group>& Viewer::getRootGroup() const
return mRootGroup;
}

//==============================================================================
void Viewer::setVerticalFieldOfView(const double fov)
{
double fovy;
double aspectRatio;
double zNear;
double zFar;

auto* camera = getCamera();

if (!camera)
{
dtwarn << "[Viewer::setMasterCameraFieldOfView] This viewer doesn't have "
<< "any cameras. Ignoring this request.\n";
return;
}

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

if (!result)
{
dtwarn << "[Viewer::setMasterCameraFieldOfView] Attemping to set vertical "
<< "field of view while the camera isn't perspective view. "
<< "Ignoring this request.\n";
return;
}

camera->setProjectionMatrixAsPerspective(fov, aspectRatio, zNear, zFar);
}

//==============================================================================
double Viewer::getVerticalFieldOfView() const
{
double fovy;
double aspectRatio;
double zNear;
double zFar;

const auto* camera = getCamera();

if (!camera)
{
dtwarn << "[Viewer::getMasterCameraFieldOfView] This viewer doesn't have "
<< "any cameras. Returning 0.0.\n";
return 0.0;
}

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

if (!result)
{
dtwarn << "[Viewer::getMasterCameraFieldOfView] Vertical field of view is "
<< "requested while the camera isn't perspective view. "
<< "Returning 0.0.\n";
return 0.0;
}

return fovy;
}

} // namespace osg
} // namespace gui
} // namespace dart
9 changes: 9 additions & 0 deletions dart/gui/osg/Viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 degrees.
void setVerticalFieldOfView(double fov);

/// Returns the vertical field of view of the master camera of the view.
/// \return Vertical field of view in degrees if the camera is perspective
/// view, 0.0 otherwise.
double getVerticalFieldOfView() const;

protected:

friend class SaveScreen;
Expand Down