diff --git a/src/rviz/default_plugin/relative_humidity_display.cpp b/src/rviz/default_plugin/relative_humidity_display.cpp index 81fba40c3f..2039e3bd7e 100644 --- a/src/rviz/default_plugin/relative_humidity_display.cpp +++ b/src/rviz/default_plugin/relative_humidity_display.cpp @@ -27,8 +27,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#include +#include #include diff --git a/src/rviz/ogre_helpers/qt_ogre_render_window.cpp b/src/rviz/ogre_helpers/qt_ogre_render_window.cpp index 45155e2103..7a55d97d0a 100644 --- a/src/rviz/ogre_helpers/qt_ogre_render_window.cpp +++ b/src/rviz/ogre_helpers/qt_ogre_render_window.cpp @@ -59,6 +59,7 @@ QtOgreRenderWindow::QtOgreRenderWindow( QWidget* parent ) , background_color_( Ogre::ColourValue::Black ) // matches the default of Ogre::Viewport. , stereo_enabled_( false ) , rendering_stereo_( false ) + , left_camera_( 0 ) , right_camera_( 0 ) , right_viewport_( 0 ) { @@ -126,6 +127,9 @@ void QtOgreRenderWindow::setupStereo() viewport_->setDrawBuffer(Ogre::CBT_BACK); #endif + if (left_camera_) + left_camera_->getSceneManager()->destroyCamera( left_camera_ ); + left_camera_ = NULL; if (right_camera_) right_camera_->getSceneManager()->destroyCamera( right_camera_ ); right_camera_ = NULL; @@ -139,18 +143,68 @@ void QtOgreRenderWindow::preViewportUpdate( { Ogre::Viewport* viewport = evt.source; - if (viewport != right_viewport_) - return; + const Ogre::Vector2& offset = camera_->getFrustumOffset(); + const Ogre::Vector3 pos = camera_->getPosition(); + const Ogre::Vector3 right = camera_->getRight(); + const Ogre::Vector3 up = camera_->getUp(); - if (camera_->getProjectionType() != Ogre::PT_PERSPECTIVE || !right_camera_) + if (viewport == right_viewport_) { - viewport->setCamera( camera_ ); - return; + if (camera_->getProjectionType() != Ogre::PT_PERSPECTIVE || !right_camera_) + { + viewport->setCamera( camera_ ); + return; + } + + Ogre::Vector3 newpos = pos + + right * offset.x + + up * offset.y; + + right_camera_->synchroniseBaseSettingsWith(camera_); + right_camera_->setFrustumOffset(-offset); + right_camera_->setPosition(newpos); + viewport->setCamera(right_camera_); + } + else if (viewport == viewport_) + { + if (camera_->getProjectionType() != Ogre::PT_PERSPECTIVE || !left_camera_) + { + viewport->setCamera( camera_ ); + return; + } + + Ogre::Vector3 newpos = pos + - right * offset.x + - up * offset.y; + + left_camera_->synchroniseBaseSettingsWith(camera_); + left_camera_->setFrustumOffset(offset); + left_camera_->setPosition(newpos); + viewport->setCamera(left_camera_); + } + else + { + ROS_WARN("Begin rendering to unknown viewport."); + } +} + +void QtOgreRenderWindow::postViewportUpdate( + const Ogre::RenderTargetViewportEvent& evt) +{ + Ogre::Viewport* viewport = evt.source; + + if (viewport == right_viewport_) + { + // nothing to do here + } + else if (viewport == viewport_) + { + viewport->setCamera(camera_); + } + else + { + ROS_WARN("End rendering to unknown viewport."); } - - right_camera_->synchroniseBaseSettingsWith(camera_); - right_camera_->setFrustumOffset(-camera_->getFrustumOffset()); - right_viewport_->setCamera(right_camera_); } Ogre::Viewport* QtOgreRenderWindow::getViewport () const @@ -167,6 +221,10 @@ void QtOgreRenderWindow::setCamera( Ogre::Camera* camera ) setCameraAspectRatio(); + if (camera_ && rendering_stereo_ && !left_camera_) + { + left_camera_ = camera_->getSceneManager()->createCamera(camera_->getName() + "-left"); + } if (camera_ && rendering_stereo_ && !right_camera_) { right_camera_ = camera_->getSceneManager()->createCamera(camera_->getName() + "-right"); diff --git a/src/rviz/ogre_helpers/qt_ogre_render_window.h b/src/rviz/ogre_helpers/qt_ogre_render_window.h index 42d4a9c3ec..64dfcfda98 100644 --- a/src/rviz/ogre_helpers/qt_ogre_render_window.h +++ b/src/rviz/ogre_helpers/qt_ogre_render_window.h @@ -119,8 +119,10 @@ class QtOgreRenderWindow : public RenderWidget, public Ogre::RenderTargetListene virtual void paintEvent( QPaintEvent* e ); virtual void resizeEvent( QResizeEvent* event ); - // When stereo is enabled, this is called before rendering each viewport. + // When stereo is enabled, these are called before/after rendering each + // viewport. virtual void preViewportUpdate(const Ogre::RenderTargetViewportEvent& evt); + virtual void postViewportUpdate(const Ogre::RenderTargetViewportEvent& evt); /** * Sets the aspect ratio on the camera @@ -151,6 +153,7 @@ class QtOgreRenderWindow : public RenderWidget, public Ogre::RenderTargetListene // stereo rendering bool stereo_enabled_; // true if we were asked to render stereo bool rendering_stereo_; // true if we are actually rendering stereo + Ogre::Camera* left_camera_; Ogre::Camera* right_camera_; Ogre::Viewport* right_viewport_; }; diff --git a/src/rviz/view_controller.cpp b/src/rviz/view_controller.cpp index 3357fb4ae8..24a4095738 100644 --- a/src/rviz/view_controller.cpp +++ b/src/rviz/view_controller.cpp @@ -260,8 +260,8 @@ void ViewController::updateStereoProperties() { float focal_dist = stereo_focal_distance_->getFloat(); float eye_sep = stereo_eye_swap_->getBool() ? - stereo_eye_separation_->getFloat() : - -stereo_eye_separation_->getFloat(); + -stereo_eye_separation_->getFloat() : + stereo_eye_separation_->getFloat(); camera_->setFrustumOffset(0.5f * eye_sep, 0.0f); camera_->setFocalLength(focal_dist); stereo_eye_swap_->show();