Skip to content

Commit

Permalink
Merge pull request #789 from acornacorn/acorn_stereo2_indigo
Browse files Browse the repository at this point in the history
Improve stereo rendering
  • Loading branch information
wjwwood committed Jul 17, 2014
2 parents 39aa5b8 + 9721c1c commit 8a010bb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/rviz/default_plugin/relative_humidity_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <OGRE/OgreSceneNode.h>
#include <OGRE/OgreSceneManager.h>
#include <OgreSceneNode.h>
#include <OgreSceneManager.h>

#include <ros/time.h>

Expand Down
76 changes: 67 additions & 9 deletions src/rviz/ogre_helpers/qt_ogre_render_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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");
Expand Down
5 changes: 4 additions & 1 deletion src/rviz/ogre_helpers/qt_ogre_render_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_;
};
Expand Down
4 changes: 2 additions & 2 deletions src/rviz/view_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8a010bb

Please sign in to comment.