Added continuous recording of the animation path to the RecordAnimationPathHandler
This commit is contained in:
parent
7592e50cde
commit
cac6e2facb
@ -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() {}
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
#include <osgViewer/Viewer>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
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;
|
||||
|
@ -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<<itr->first<<" "<<cp.getPosition()<<" "<<cp.getRotation()<<std::endl;
|
||||
}
|
||||
|
||||
void AnimationPath::write(std::ostream& fout) const
|
||||
{
|
||||
int prec = fout.precision();
|
||||
@ -108,8 +114,7 @@ void AnimationPath::write(std::ostream& fout) const
|
||||
tcpmitr!=tcpm.end();
|
||||
++tcpmitr)
|
||||
{
|
||||
const ControlPoint& cp = tcpmitr->second;
|
||||
fout<<tcpmitr->first<<" "<<cp.getPosition()<<" "<<cp.getRotation()<<std::endl;
|
||||
write(tcpmitr, fout);
|
||||
}
|
||||
|
||||
fout.precision(prec);
|
||||
|
@ -414,8 +414,16 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU
|
||||
if (_currentlyRecording && _delta >= _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;
|
||||
|
||||
@ -438,7 +446,15 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU
|
||||
_animStartTime = osg::Timer::instance()->tick();
|
||||
_animPath->clear();
|
||||
|
||||
osg::notify(osg::NOTICE)<<"Recording camera path."<<std::endl;
|
||||
if (!_filename.empty())
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Recording camera path to file "<<_filename<<std::endl;
|
||||
_fout.open(_filename.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Recording camera path."<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// THe user has requested to STOP recording, write the file!
|
||||
@ -447,12 +463,7 @@ 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.
|
||||
std::ofstream out(_filename.c_str());
|
||||
osg::notify(osg::NOTICE)<<"Writing camera file: "<<_filename<<std::endl;
|
||||
_animPath->write(out);
|
||||
out.close();
|
||||
if (_fout) _fout.close();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user