ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Moving camera with librviz does not update view

asked 2019-05-15 08:58:19 -0500

jotwe gravatar image

Hi,

I am on Ubuntu 16.04 with ROS Kinetic and trying to move the camera position in a 3D visualizer widget programmatically using librviz. I basically followed the provided tutorial and came up with

manager_ = new rviz::VisualizationManager( render_panel_ );
render_panel_->initialize( manager_->getSceneManager(), manager_ );
manager_->initialize();
manager_->startUpdate();
controller_ = manager_->getViewManager()->getCurrent();
controller_->getCamera()->moveRelative(Ogre::Vector3(0, 0.1, 0));

Unfortunately, this does not do anything. Also controller_->getCamera()->setPosition(...) does not have any effect.

I can only see a change when I add a controller_->getCamera()->lookAt(...) to the code. This will result in the desired change of the position plus an in general unwanted change in orientation.

It seems like moveRelative(...) and setPosition(...) do not trigger an update of the view?! Is there a solution to make this work without the lookAt(...) or do I miss something important here?

edit retag flag offensive close merge delete

Comments

Maybe, it would be enough to call lookAt(...) with a point that is directly located in front of the camera. Or is there a another option run it without visual impact?

jotwe gravatar image jotwe  ( 2019-05-16 06:42:54 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-17 07:49:25 -0500

Weasfas gravatar image

Hi @jotwe,

I know this is a late response but I was developing a custom rviz plugin and I came up with the very same problem you face in your question.

After some research I discover several things that may help anyone that encounter this problem. So here we go:

When you use the setPosition(...) function of the Ogre::Camera object returned with controller_->getCamera() the position information of the Camera instance does change, however the problem here is that the ViewController of Rviz override this information when calling the update method of ViewController object, that can be found here and must be override for any Child Class implementing a View... like Orbit, FPS etc. So, the explanation is simply that, Ogre::Camera is changed but restore by the ViewController whose View properties remain intact (Distance, Position X, Position Y, etc.).

Thus, in order to programatically change the camera postion and direction there is something you can do: Since most of the update() method takes first the position of the Ogre::Camera with camera_->getCameraPosition() what can be done is just calling the set setPosition(...) method from Ogre::Camera and then the lookAt(...) method from the controller_. Whit that, the update method will get the stablished position changing the camera pose and then the controller will use the lookAt(...) method to change its direction.

Like this:

Extracted from a plugin that heritage from a rviz panel. vis_manager_ is VisualizationManager object.

vis_manager_->getViewManager()->getCurrent()->getCamera()->setPosition(x_pos, y_pos, z_pos);
vis_manager_->getViewManager()->getCurrent()->lookAt(x_look, y_look, z_look);

Hope that helps, Cheers.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-05-15 08:58:19 -0500

Seen: 213 times

Last updated: Jun 17 '21