diff --git a/include/osg/AnimationPath b/include/osg/AnimationPath index 7fbf19b5b..c30fe4cf3 100644 --- a/include/osg/AnimationPath +++ b/include/osg/AnimationPath @@ -116,7 +116,7 @@ class OSG_EXPORT AnimationPath : public virtual osg::Object matrix.preMult(osg::Matrixd::rotate(_rotation.inverse())); matrix.preMult(osg::Matrixd::translate(-_position)); } - + protected: osg::Vec3d _position; @@ -164,6 +164,7 @@ class OSG_EXPORT AnimationPath : public virtual osg::Object /** Given a specific time, return the local ControlPoint frame for a point. */ virtual bool getInterpolatedControlPoint(double time,ControlPoint& controlPoint) const; + /** Insert a control point into the AnimationPath.*/ void insert(double time,const ControlPoint& controlPoint); double getFirstTime() const { if (!_timeControlPointMap.empty()) return _timeControlPointMap.begin()->first; else return 0.0;} @@ -200,6 +201,9 @@ class OSG_EXPORT AnimationPath : public virtual osg::Object /** Write the animation path to a flat ASCII file stream. */ void write(std::ostream& out) const; + /** Write the control point to a flat ASCII file stream. */ + void write(TimeControlPointMap::const_iterator itr, std::ostream& out) const; + protected: virtual ~AnimationPath() {} diff --git a/include/osgViewer/ViewerEventHandlers b/include/osgViewer/ViewerEventHandlers index 34c764809..67ff59262 100644 --- a/include/osgViewer/ViewerEventHandlers +++ b/include/osgViewer/ViewerEventHandlers @@ -22,6 +22,8 @@ #include #include +#include + namespace osgViewer { /** Event handler for adding on screen help to Viewers.*/ @@ -241,6 +243,7 @@ public: protected: std::string _filename; + std::ofstream _fout; int _keyEventToggleRecord; int _keyEventTogglePlayback; diff --git a/src/osg/AnimationPath.cpp b/src/osg/AnimationPath.cpp index 3b02bd61d..2cef14998 100644 --- a/src/osg/AnimationPath.cpp +++ b/src/osg/AnimationPath.cpp @@ -98,6 +98,12 @@ void AnimationPath::read(std::istream& in) } } +void AnimationPath::write(TimeControlPointMap::const_iterator itr, std::ostream& fout) const +{ + const ControlPoint& cp = itr->second; + fout<first<<" "<second; - fout<first<<" "<= _interval) { const osg::Matrixd& m = view->getCamera()->getInverseViewMatrix(); - _animPath->insert(osg::Timer::instance()->delta_s(_animStartTime, time), osg::AnimationPath::ControlPoint(m.getTrans(), m.getRotate())); + double animationPathTime = osg::Timer::instance()->delta_s(_animStartTime, time); + _animPath->insert(animationPathTime, osg::AnimationPath::ControlPoint(m.getTrans(), m.getRotate())); _delta = 0.0f; + + if (_fout) + { + _animPath->write(_animPath->getTimeControlPointMap().find(animationPathTime), _fout); + _fout.flush(); + } + } else _delta += delta; @@ -437,8 +445,16 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU _currentlyRecording = true; _animStartTime = osg::Timer::instance()->tick(); _animPath->clear(); - - osg::notify(osg::NOTICE)<<"Recording camera path."<write(out); - out.close(); + if (_fout) _fout.close(); } return true;