diff --git a/src/osgViewer/ViewerEventHandlers.cpp b/src/osgViewer/ViewerEventHandlers.cpp index 88054618a..9515e8393 100644 --- a/src/osgViewer/ViewerEventHandlers.cpp +++ b/src/osgViewer/ViewerEventHandlers.cpp @@ -407,8 +407,6 @@ RecordCameraPathHandler::RecordCameraPathHandler(const std::string& filename, fl _animStartTime(0), _lastFrameTime(osg::Timer::instance()->tick()) { - _animPath = new osg::AnimationPath(); - const char* str = getenv("OSG_RECORD_CAMERA_PATH_FPS"); if (str) { @@ -446,7 +444,7 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU // If our internal _delta is finally large enough to warrant a ControlPoint // insertion, do so now. Be sure and reset the internal _delta, so we can start // calculating when the next insert should happen. - if (_currentlyRecording && _delta >= _interval) + if (_animPath.valid() && _currentlyRecording && _delta >= _interval) { const osg::Matrixd& m = view->getCamera()->getInverseViewMatrix(); double animationPathTime = osg::Timer::instance()->delta_s(_animStartTime, time); @@ -479,7 +477,7 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU { _currentlyRecording = true; _animStartTime = osg::Timer::instance()->tick(); - _animPath->clear(); + _animPath = new osg::AnimationPath(); if (!_filename.empty()) { @@ -530,31 +528,41 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU _currentlyRecording = false; _delta = 0.0f; - // In the future this will need to be written continuously, rather - // than all at once. - osgDB::ofstream out(_filename.c_str()); - OSG_NOTICE<<"Writing camera file: "<<_filename<write(out); - out.close(); + if (_animPath.valid() && !_animPath->empty()) + { + // In the future this will need to be written continuously, rather + // than all at once. + osgDB::ofstream out(_filename.c_str()); + OSG_NOTICE<<"Writing camera file: "<<_filename<write(out); + out.close(); + } + else + { + OSG_NOTICE<<"No animation path to write out."<home(ea,aa); + if (_animPath.valid() && !_animPath->empty()) + { + _animPathManipulator = new osgGA::AnimationPathManipulator(_animPath.get()); + _animPathManipulator->home(ea,aa); - // If we successfully found our _filename file, set it and keep a copy - // around of the original CameraManipulator to restore later. - if (_animPathManipulator.valid() && _animPathManipulator->valid()) - { - _oldManipulator = view->getCameraManipulator(); - view->setCameraManipulator(_animPathManipulator.get()); - _currentlyPlaying = true; - } + // If we successfully found our _filename file, set it and keep a copy + // around of the original CameraManipulator to restore later. + if (_animPathManipulator.valid() && _animPathManipulator->valid()) + { + _oldManipulator = view->getCameraManipulator(); + view->setCameraManipulator(_animPathManipulator.get()); + _currentlyPlaying = true; + } + } } - + // The user has requested to STOP playback. else {