Currently, after leaving the track_visual mode, the camera keeps its orientation determined by Ogre setAutoTracking method. With this pull request, the camera orientation is set to zero after leaving the track_visual mode to make sure that it can still be easily manipulated by the user.
@ocrave Thanks for the PR! It feels jarring to exit follow mode and have the view reset. Is there a way to fix the bug and keep the camera at its current position/direction?
For others, steps to make camera get stuck rolled on gazebo default without this patch
enter follow mode on a stationary object
changing the pitch of the camera so that it is looking down at the object
exit follow mode
Bring the camera down to its previous pitch
The camera has now rolled, and cannot be unrolled.
the problem is that with auto tracking enabled, the orientation of the ogre camera object itself will change (as opposed to its parent scene node). Typically, the ogre camera orientation remains fixed at the orientation when it's first created. Later pose operations are done to its parent scene node. I believe the solution for exiting the follow mode will involve resetting the ogre camera's orientation to the initial state and correcting its parent scenenode's orientation to keep the camera facing the current direction.
This pull request has been modified to implement your solution. A call to Camera::SetWorldPose is mandatory to reinitialize the view controller in UserCamera. I also removed some calls to deprecated Ogre methods but calls to deprecated Ogre::Camera::yaw and Ogre::Camera::roll still remain and must be canceled out before entering track_visual mode. Ideally, we should remove calls to Ogre::Camera::yaw and Ogre::Camera::roll, but in order to do that, we may have to add another Ogre::SceneNode in-between Camera::sceneNode and Camera::camera.
great thanks, the camera pose stays the same now after leaving the follow mode.
I noticed however that while in the camera follow mode, the orbit view controller wasn't moving the camera correctly, maybe because camera auto tracking was fighting with the pose changes made by the view controller. I tested adding an intermediate scene node like you mentioned and it seems to work well now. Here's a snippet showing a diff on top of your changes:
I still have not figured out why but your snippet does not fix the original issue anymore: The derived camera's rotation is OK after leaving the auto tracking mode but, as soon as you rotate the camera with your mouse, the camera jumps to another orientation. I tried to modify your code by setting the auto tracking on the sceneNode instead of on the cameraNode but it still does not work. The only thing that works for me is the latest commit without cameraNode.
I'll try to get the PR merged soon.
I am trying to reproduce the problem described below after merging with default and applying my patch
as soon as you rotate the camera with your mouse, the camera jumps to another orientation.
Here’s what I’m doing
Insert box into empty world
Right click on box, and select Follow
Orbit the camera with right click (e.g. pitch the camera so it’s looking at the box from above)
Press ESC to exit Follow mode → Camera orientation stays the way it was before leaving Follow mode so all good
Right click on the box and orbit the camera again → camera orbit behavior seems fine and no jumps.
Maybe I’m missing some steps?
After merging with the default branch, I could not reproduce the issue anymore with your patch. So, I pushed a new version that contains your changes. It seems to be working now. Thanks!