From c7bf4c99b5f888d2dc200041994ed5c8fe16d3ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Fri, 1 Mar 2024 10:34:27 +0100 Subject: [PATCH] Fix camera display overlay (#1151) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- rviz_common/src/rviz_common/render_panel.cpp | 2 +- rviz_rendering/include/rviz_rendering/render_window.hpp | 4 ++++ .../src/rviz_rendering/ogre_render_window_impl.cpp | 7 +++++++ .../src/rviz_rendering/ogre_render_window_impl.hpp | 2 ++ rviz_rendering/src/rviz_rendering/render_window.cpp | 8 ++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/rviz_common/src/rviz_common/render_panel.cpp b/rviz_common/src/rviz_common/render_panel.cpp index 2e6698a8c..9f0d9d02f 100644 --- a/rviz_common/src/rviz_common/render_panel.cpp +++ b/rviz_common/src/rviz_common/render_panel.cpp @@ -116,7 +116,7 @@ void RenderPanel::initialize(DisplayContext * context, bool use_main_scene) camera_node->attachObject(default_camera); camera_node->setPosition(default_camera_pose_); camera_node->lookAt(Ogre::Vector3(0, 0, 0), Ogre::Node::TS_WORLD); - + rviz_rendering::RenderWindowOgreAdapter::setSceneNodeCamera(render_window_, camera_node); rviz_rendering::RenderWindowOgreAdapter::setOgreCamera(render_window_, default_camera); } // scene_manager_ = scene_manager; diff --git a/rviz_rendering/include/rviz_rendering/render_window.hpp b/rviz_rendering/include/rviz_rendering/render_window.hpp index cdee58b47..56ac6337f 100644 --- a/rviz_rendering/include/rviz_rendering/render_window.hpp +++ b/rviz_rendering/include/rviz_rendering/render_window.hpp @@ -158,6 +158,10 @@ class RVIZ_RENDERING_PUBLIC RenderWindowOgreAdapter void setOgreCamera(RenderWindow * render_window, Ogre::Camera * ogre_camera); + static + void + setSceneNodeCamera(RenderWindow * render_window, Ogre::SceneNode * ogre_camera); + static Ogre::Camera * getOgreCamera(RenderWindow * render_window); diff --git a/rviz_rendering/src/rviz_rendering/ogre_render_window_impl.cpp b/rviz_rendering/src/rviz_rendering/ogre_render_window_impl.cpp index 352b079cb..18643009a 100644 --- a/rviz_rendering/src/rviz_rendering/ogre_render_window_impl.cpp +++ b/rviz_rendering/src/rviz_rendering/ogre_render_window_impl.cpp @@ -304,6 +304,13 @@ void RenderWindowImpl::setCamera(Ogre::Camera * ogre_camera) } } +void RenderWindowImpl::setSceneNodeCamera(Ogre::SceneNode * ogre_camera) +{ + if (ogre_camera) { + ogre_camera_node_ = ogre_camera; + } +} + Ogre::Camera * RenderWindowImpl::getCamera() const { return ogre_camera_; diff --git a/rviz_rendering/src/rviz_rendering/ogre_render_window_impl.hpp b/rviz_rendering/src/rviz_rendering/ogre_render_window_impl.hpp index 5f03bf602..e65b05509 100644 --- a/rviz_rendering/src/rviz_rendering/ogre_render_window_impl.hpp +++ b/rviz_rendering/src/rviz_rendering/ogre_render_window_impl.hpp @@ -107,6 +107,8 @@ class RenderWindowImpl /// Set the camera associated with this render window's viewport. void setCamera(Ogre::Camera * camera); + void setSceneNodeCamera(Ogre::SceneNode * ogre_camera); + /// Get the camera. Ogre::Camera * getCamera() const; diff --git a/rviz_rendering/src/rviz_rendering/render_window.cpp b/rviz_rendering/src/rviz_rendering/render_window.cpp index c9d7d9794..cab2bbd96 100644 --- a/rviz_rendering/src/rviz_rendering/render_window.cpp +++ b/rviz_rendering/src/rviz_rendering/render_window.cpp @@ -200,6 +200,14 @@ RenderWindowOgreAdapter::setOgreCamera(RenderWindow * render_window, Ogre::Camer render_window->impl_->setCamera(ogre_camera); } +void +RenderWindowOgreAdapter::setSceneNodeCamera( + RenderWindow * render_window, + Ogre::SceneNode * ogre_camera) +{ + render_window->impl_->setSceneNodeCamera(ogre_camera); +} + Ogre::Camera * RenderWindowOgreAdapter::getOgreCamera(RenderWindow * render_window) {