From 927942a0f8dce37a5b37851a3d24c0904c9cca78 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 15 Aug 2008 12:45:20 +0000 Subject: [PATCH] Further work on osg::ImageSequence, improving pause functionality, and introducing new seek(double time) method --- .../osgimagesequence/osgimagesequence.cpp | 1 - include/osg/ImageSequence | 13 +++-- include/osg/ImageStream | 2 + src/osg/ImageSequence.cpp | 53 ++++++++++++++----- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/examples/osgimagesequence/osgimagesequence.cpp b/examples/osgimagesequence/osgimagesequence.cpp index 30cfeef8c..47f0844bd 100644 --- a/examples/osgimagesequence/osgimagesequence.cpp +++ b/examples/osgimagesequence/osgimagesequence.cpp @@ -225,7 +225,6 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction { std::cout<<"Restart"<rewind(); - (*itr)->play(); } return true; } diff --git a/include/osg/ImageSequence b/include/osg/ImageSequence index a76c0416f..31726c0e7 100644 --- a/include/osg/ImageSequence +++ b/include/osg/ImageSequence @@ -51,6 +51,8 @@ class OSG_EXPORT ImageSequence : public ImageStream typedef std::list< osg::ref_ptr > Images; typedef std::list< std::string > FileNames; + virtual void seek(double time); + virtual void play(); virtual void pause(); @@ -112,15 +114,18 @@ class OSG_EXPORT ImageSequence : public ImageStream FileNames::iterator _fileNamesIterator; double _fileNamesIteratorTime; - double _imageHeadTime; Images _images; - Images::iterator _imageIterator; - double _imageIteratorTime; typedef std::pair< std::string, osg::ref_ptr > FileNameImagePair; typedef std::list< FileNameImagePair > FileNameImageList; - FileNameImageList _filesRequested; + + Images::iterator _imageIterator; + double _imageIteratorTime; + + bool _seekTimeSet; + double _seekTime; + }; diff --git a/include/osg/ImageStream b/include/osg/ImageStream index 0b4dd86c1..5c1b543ce 100644 --- a/include/osg/ImageStream +++ b/include/osg/ImageStream @@ -46,6 +46,8 @@ class OSG_EXPORT ImageStream : public Image REWINDING }; + virtual void seek(double /*time*/) {} + virtual void play() { _status=PLAYING; } virtual void pause() { _status=PAUSED; } diff --git a/src/osg/ImageSequence.cpp b/src/osg/ImageSequence.cpp index cac513b77..ce5333f5f 100644 --- a/src/osg/ImageSequence.cpp +++ b/src/osg/ImageSequence.cpp @@ -49,7 +49,10 @@ ImageSequence::ImageSequence() _fileNamesIteratorTime = DBL_MAX; _imageIterator = _images.end(); - _imageIteratorTime = DBL_MAX; + _imageIteratorTime = 0.0; + + _seekTime = 0.0; + _seekTimeSet = false; } ImageSequence::ImageSequence(const ImageSequence& is,const CopyOp& copyop): @@ -63,8 +66,11 @@ ImageSequence::ImageSequence(const ImageSequence& is,const CopyOp& copyop): _fileNamesIterator = _fileNames.end(); _fileNamesIteratorTime = DBL_MAX; - _imageIteratorTime = DBL_MAX; + _imageIteratorTime = 0.0; _imageIterator = _images.end(); + + _seekTime = is._seekTime; + _seekTimeSet = is._seekTimeSet; } int ImageSequence::compare(const Image& rhs) const @@ -72,6 +78,12 @@ int ImageSequence::compare(const Image& rhs) const return ImageStream::compare(rhs); } +void ImageSequence::seek(double time) +{ + _seekTime = time; + _seekTimeSet = true; +} + void ImageSequence::play() { _status=PLAYING; @@ -84,7 +96,7 @@ void ImageSequence::pause() void ImageSequence::rewind() { - _status=REWINDING; + seek(0.0f); } void ImageSequence::setMode(Mode mode) @@ -171,7 +183,7 @@ void ImageSequence::addImage(osg::Image* image) if (data()==0) { _imageIterator = _images.begin(); - _imageIteratorTime = _referenceTime; + _imageIteratorTime = 0.0; setImageToChild(_imageIterator->get()); } } @@ -209,22 +221,29 @@ void ImageSequence::update(osg::NodeVisitor* nv) _fileNamesIteratorTime = _referenceTime; } - if (_imageIteratorTime == DBL_MAX) - { - _imageIteratorTime = _referenceTime; - } - + bool looping = getLoopingMode()==LOOPING; double time = (fs->getSimulationTime() - _referenceTime)*_timeMultiplier; - if (_status==PAUSED || _status==INVALID) time = _imageIteratorTime; + if (_seekTimeSet || _status==PAUSED || _status==INVALID) + { + time = _seekTime; + _referenceTime = fs->getSimulationTime() - time/_timeMultiplier; + } + + if (time>_duration) + { + time -= floor(time/_duration)*_duration; + } + _seekTime = time; + _seekTimeSet = false; + FileNames::iterator previous_fileNamesIterator = _fileNamesIterator; Images::iterator previous_imageIterator = _imageIterator; bool pruneOldImages = false; - bool looping = getLoopingMode()==LOOPING; - + switch(_mode) { case(PRE_LOAD_ALL_IMAGES): @@ -295,11 +314,19 @@ void ImageSequence::update(osg::NodeVisitor* nv) } } + + { - // // Advance imageIterator // + + if (time<_imageIteratorTime) + { + _imageIterator = _images.begin(); + _imageIteratorTime = 0.0; + } + if (_imageIterator!=_images.end()) { // osg::notify(osg::NOTICE)<<" _imageIteratorTime = "<<_imageIteratorTime<