From 56b384d880d0f66d2836ff0e369e095a164c003c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 26 Jan 2010 15:08:25 +0000 Subject: [PATCH] From Jan Peciva, "I am sending one more improvement (separately from Inventor plugin). I found very useful to have a control whether osgView::setCameraManipulator does or does not reset camera to home position. I extended method signature as follows: void setCameraManipulator(osgGA::MatrixManipulator* manipulator, bool resetPosition = true); keeping the current usage intact (default parameter), while enabling user to disable the position reset. That can be useful in the situation when manipulator position was already loaded, for example from a file (user specification), or defined any other way, while we do not want to be reset to home position. Other usability is usage of two manipulators in a modeling program (orbiting around the model, walking on the model) and changing between them while we want to preserve the position of a camera in the change. Games may benefit from it as well when we change from user-defined helicopter manipulator to soldier manipulator because the user escaped the helicopter. The camera will change manipulator but the position is expected to be kept in the transition (provided that user makes the state transition between the two manipulators himself). " --- include/osgViewer/View | 5 +++-- src/osgViewer/View.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/osgViewer/View b/include/osgViewer/View index e9b41b2c2..24eff3e35 100644 --- a/include/osgViewer/View +++ b/include/osgViewer/View @@ -98,8 +98,9 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /* Get the const View's EventQueue.*/ const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); } - /** Set the CameraManipulator that moves the View's master Camera position in response to events.*/ - void setCameraManipulator(osgGA::MatrixManipulator* manipulator); + /** Set the CameraManipulator that moves the View's master Camera position in response to events. + * The parameter resetPosition determines whether manipulator is set to its home position.*/ + void setCameraManipulator(osgGA::MatrixManipulator* manipulator, bool resetPosition = true); /** Get the View's CameraManipulator.*/ osgGA::MatrixManipulator* getCameraManipulator() { return _cameraManipulator.get(); } diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index a547e232f..bdc0ded7b 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -338,7 +338,7 @@ const osgDB::ImagePager* View::getImagePager() const } -void View::setCameraManipulator(osgGA::MatrixManipulator* manipulator) +void View::setCameraManipulator(osgGA::MatrixManipulator* manipulator, bool resetPosition) { _cameraManipulator = manipulator; @@ -348,9 +348,11 @@ void View::setCameraManipulator(osgGA::MatrixManipulator* manipulator) if (getSceneData()) _cameraManipulator->setNode(getSceneData()); - osg::ref_ptr dummyEvent = _eventQueue->createEvent(); - - _cameraManipulator->home(*dummyEvent, *this); + if (resetPosition) + { + osg::ref_ptr dummyEvent = _eventQueue->createEvent(); + _cameraManipulator->home(*dummyEvent, *this); + } } }