diff --git a/CHANGELOG.md b/CHANGELOG.md index a9af434e33438..4e5e13a52d29e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/dart/gui/osg/Viewer.cpp b/dart/gui/osg/Viewer.cpp index aa4c2abcc014c..3696c6370fc28 100644 --- a/dart/gui/osg/Viewer.cpp +++ b/dart/gui/osg/Viewer.cpp @@ -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 diff --git a/dart/gui/osg/Viewer.hpp b/dart/gui/osg/Viewer.hpp index 817d15272bfd6..47109d99d6c41 100644 --- a/dart/gui/osg/Viewer.hpp +++ b/dart/gui/osg/Viewer.hpp @@ -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;