From b2af096479d62037279a420fbae45ea016401535 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Sat, 31 Mar 2018 23:14:33 -0700 Subject: [PATCH 1/7] Add API for field of view of OSG viewer --- dart/gui/osg/Viewer.cpp | 38 ++++++++++++++++++++++++++++++++++++++ dart/gui/osg/Viewer.hpp | 10 ++++++++++ 2 files changed, 48 insertions(+) diff --git a/dart/gui/osg/Viewer.cpp b/dart/gui/osg/Viewer.cpp index aa4c2abcc014c..23f36c89aed77 100644 --- a/dart/gui/osg/Viewer.cpp +++ b/dart/gui/osg/Viewer.cpp @@ -843,6 +843,44 @@ const ::osg::ref_ptr<::osg::Group>& Viewer::getRootGroup() const return mRootGroup; } +//============================================================================== +bool Viewer::setMasterCameraFieldOfView(double fov) +{ + double fovy; + double aspectRatio; + double zNear; + double zFar; + + auto* camera = getCamera(); + assert(camera); + const bool result = camera->getProjectionMatrixAsPerspective( + fovy, aspectRatio, zNear, zFar); + + if (result) + camera->setProjectionMatrixAsPerspective(fov, aspectRatio, zNear, zFar); + + return result; +} + +//============================================================================== +double Viewer::getMasterCameraFieldOfView() const +{ + double fovy; + double aspectRatio; + double zNear; + double zFar; + + const auto* camera = getCamera(); + assert(camera); + const bool result = camera->getProjectionMatrixAsPerspective( + fovy, aspectRatio, zNear, zFar); + + if (result) + return fovy; + + return 0.0; +} + } // namespace osg } // namespace gui } // namespace dart diff --git a/dart/gui/osg/Viewer.hpp b/dart/gui/osg/Viewer.hpp index 817d15272bfd6..ba186cce17671 100644 --- a/dart/gui/osg/Viewer.hpp +++ b/dart/gui/osg/Viewer.hpp @@ -293,6 +293,16 @@ 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 field of view of the master camera of the view. + /// \param[in] fov Field of view in degree. + /// \return True if the camera is perspective view, false otherwise. + bool setMasterCameraFieldOfView(double fov); + + /// Retruns the field of view of the master camera of the view. + /// \return Field of view in degree if the camera is perspective view, 0.0 + /// otherwise. + double getMasterCameraFieldOfView() const; + protected: friend class SaveScreen; From 9d6f74167b87154dfcebf9d347ea3b16dd732429 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Sun, 1 Apr 2018 07:35:33 -0700 Subject: [PATCH 2/7] Update FOV API --- dart/gui/osg/Viewer.cpp | 25 +++++++++++++++++-------- dart/gui/osg/Viewer.hpp | 17 ++++++++--------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/dart/gui/osg/Viewer.cpp b/dart/gui/osg/Viewer.cpp index 23f36c89aed77..6f5cb2b659846 100644 --- a/dart/gui/osg/Viewer.cpp +++ b/dart/gui/osg/Viewer.cpp @@ -844,7 +844,7 @@ const ::osg::ref_ptr<::osg::Group>& Viewer::getRootGroup() const } //============================================================================== -bool Viewer::setMasterCameraFieldOfView(double fov) +void Viewer::setVerticalFieldOfView(double fov) { double fovy; double aspectRatio; @@ -856,14 +856,18 @@ bool Viewer::setMasterCameraFieldOfView(double fov) const bool result = camera->getProjectionMatrixAsPerspective( fovy, aspectRatio, zNear, zFar); - if (result) - camera->setProjectionMatrixAsPerspective(fov, aspectRatio, zNear, zFar); + if (!result) + { + dtwarn << "[Viewer::getMasterCameraFieldOfView] Attemping to set vertical " + << "field of view while the camera isn't perspective view. " + << "Ignoring this request.\n"; + } - return result; + camera->setProjectionMatrixAsPerspective(fov, aspectRatio, zNear, zFar); } //============================================================================== -double Viewer::getMasterCameraFieldOfView() const +double Viewer::getVerticalFieldOfView() const { double fovy; double aspectRatio; @@ -875,10 +879,15 @@ double Viewer::getMasterCameraFieldOfView() const const bool result = camera->getProjectionMatrixAsPerspective( fovy, aspectRatio, zNear, zFar); - if (result) - return fovy; + 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 0.0; + return fovy; } } // namespace osg diff --git a/dart/gui/osg/Viewer.hpp b/dart/gui/osg/Viewer.hpp index ba186cce17671..f4693eba8e937 100644 --- a/dart/gui/osg/Viewer.hpp +++ b/dart/gui/osg/Viewer.hpp @@ -293,15 +293,14 @@ 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 field of view of the master camera of the view. - /// \param[in] fov Field of view in degree. - /// \return True if the camera is perspective view, false otherwise. - bool setMasterCameraFieldOfView(double fov); - - /// Retruns the field of view of the master camera of the view. - /// \return Field of view in degree if the camera is perspective view, 0.0 - /// otherwise. - double getMasterCameraFieldOfView() const; + /// Sets the vertical field of view of the master camera of the view. + /// \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. + /// \return Vertical field of view in degree if the camera is perspective + /// view, 0.0 otherwise. + double getVerticalFieldOfView() const; protected: From 0fc0d21e42b15047b948a47e4a45eec2865207e3 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Mon, 2 Apr 2018 11:32:04 -0700 Subject: [PATCH 3/7] Address @mxgrey's comments --- dart/gui/osg/Viewer.cpp | 21 ++++++++++++++++++--- dart/gui/osg/Viewer.hpp | 6 +++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/dart/gui/osg/Viewer.cpp b/dart/gui/osg/Viewer.cpp index 6f5cb2b659846..a72ed5fd838f8 100644 --- a/dart/gui/osg/Viewer.cpp +++ b/dart/gui/osg/Viewer.cpp @@ -852,7 +852,14 @@ void Viewer::setVerticalFieldOfView(double fov) double zFar; auto* camera = getCamera(); - assert(camera); + + if (!camera) + { + dtwarn << "[Viewer::getMasterCameraFieldOfView] This viewer doesn't have " + << "any cameras. Ignoring this request.\n"; + return; + } + const bool result = camera->getProjectionMatrixAsPerspective( fovy, aspectRatio, zNear, zFar); @@ -861,6 +868,7 @@ void Viewer::setVerticalFieldOfView(double fov) dtwarn << "[Viewer::getMasterCameraFieldOfView] 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); @@ -875,7 +883,14 @@ double Viewer::getVerticalFieldOfView() const double zFar; const auto* camera = getCamera(); - assert(camera); + + 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); @@ -883,7 +898,7 @@ double Viewer::getVerticalFieldOfView() const { dtwarn << "[Viewer::getMasterCameraFieldOfView] Vertical field of view is " << "requested while the camera isn't perspective view. " - << "Returning 0.0\n"; + << "Returning 0.0.\n"; return 0.0; } diff --git a/dart/gui/osg/Viewer.hpp b/dart/gui/osg/Viewer.hpp index f4693eba8e937..47109d99d6c41 100644 --- a/dart/gui/osg/Viewer.hpp +++ b/dart/gui/osg/Viewer.hpp @@ -294,11 +294,11 @@ class Viewer : public osgViewer::Viewer, public dart::common::Subject 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. + /// \param[in] fov Vertical field of view in 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 + /// 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; From 039d4c3bdb7d6fc3d07ab391ace6fc768669a75e Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Mon, 2 Apr 2018 11:33:48 -0700 Subject: [PATCH 4/7] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9af434e33438..8cfca2c89f1f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## DART 6 +### DART 6.4.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 From d3425d4515db1967258400eab0fb1deb5246ddce Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Mon, 2 Apr 2018 11:34:26 -0700 Subject: [PATCH 5/7] Fix typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cfca2c89f1f4..4e5e13a52d29e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## DART 6 -### DART 6.4.0 (201X-XX-XX) +### DART 6.5.0 (201X-XX-XX) * GUI From ed2f98c43e00da24dcb5c4f258408b277c6b01d8 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Mon, 2 Apr 2018 11:36:05 -0700 Subject: [PATCH 6/7] Fix comment reflecting their function names --- dart/gui/osg/Viewer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dart/gui/osg/Viewer.cpp b/dart/gui/osg/Viewer.cpp index a72ed5fd838f8..c7385fbb4eb3d 100644 --- a/dart/gui/osg/Viewer.cpp +++ b/dart/gui/osg/Viewer.cpp @@ -855,7 +855,7 @@ void Viewer::setVerticalFieldOfView(double fov) if (!camera) { - dtwarn << "[Viewer::getMasterCameraFieldOfView] This viewer doesn't have " + dtwarn << "[Viewer::setMasterCameraFieldOfView] This viewer doesn't have " << "any cameras. Ignoring this request.\n"; return; } @@ -865,7 +865,7 @@ void Viewer::setVerticalFieldOfView(double fov) if (!result) { - dtwarn << "[Viewer::getMasterCameraFieldOfView] Attemping to set vertical " + dtwarn << "[Viewer::setMasterCameraFieldOfView] Attemping to set vertical " << "field of view while the camera isn't perspective view. " << "Ignoring this request.\n"; return; From 4d70ca62cfcf29c76cf7f11b43a2801683cfbc27 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Mon, 2 Apr 2018 13:40:56 -0700 Subject: [PATCH 7/7] Add const modifier to prevent possible bug --- dart/gui/osg/Viewer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dart/gui/osg/Viewer.cpp b/dart/gui/osg/Viewer.cpp index c7385fbb4eb3d..3696c6370fc28 100644 --- a/dart/gui/osg/Viewer.cpp +++ b/dart/gui/osg/Viewer.cpp @@ -844,7 +844,7 @@ const ::osg::ref_ptr<::osg::Group>& Viewer::getRootGroup() const } //============================================================================== -void Viewer::setVerticalFieldOfView(double fov) +void Viewer::setVerticalFieldOfView(const double fov) { double fovy; double aspectRatio;