diff --git a/include/osg/Sequence b/include/osg/Sequence index b50a60f56..0447b5c2b 100644 --- a/include/osg/Sequence +++ b/include/osg/Sequence @@ -185,6 +185,9 @@ class OSG_EXPORT Sequence : public Group // stopping when it gets to zero. init to 0 int _nreps, _nrepsRemain; + // frame step (are we stepping forward or backward?) + int _step; + // default frame time for newly created frames or children- default is 1. // set by setDefaultTime double _defaultTime ; diff --git a/src/osg/Sequence.cpp b/src/osg/Sequence.cpp index dd53c4863..5987064e1 100644 --- a/src/osg/Sequence.cpp +++ b/src/osg/Sequence.cpp @@ -32,6 +32,7 @@ Sequence::Sequence() : _speed(0), _nreps(-1), _nrepsRemain(0), + _step(0), _defaultTime(1.), _lastFrameTime(0.), _saveRealLastFrameTime(-1.), @@ -57,6 +58,7 @@ Sequence::Sequence(const Sequence& seq, const CopyOp& copyop) : _speed(seq._speed), _nreps(seq._nreps), _nrepsRemain(seq._nrepsRemain), + _step(seq._step), _defaultTime(seq._defaultTime), _lastFrameTime(seq._lastFrameTime), _saveRealLastFrameTime(seq._saveRealLastFrameTime), @@ -174,11 +176,19 @@ void Sequence::setDuration(float speed, int nreps) void Sequence::setMode(SequenceMode mode) { + int ubegin, uend; + switch (mode) { case START: // restarts sequence from beginning _value = -1; + + // Figure out which direction to start stepping the sequence + ubegin = (_begin < 0 ? (int)_frameTime.size()-1: _begin); + uend = (_end < 0 ? (int)_frameTime.size()-1: _end); + _step = (ubegin > uend ? -1 : 1); + _start = _now; _mode = mode; if (_saveRealLastFrameTime>=0.) @@ -221,11 +231,6 @@ void Sequence::traverse(NodeVisitor& nv) int _ubegin = (_begin < 0 ? (int)_frameTime.size()-1: _begin); int _uend = (_end < 0 ? (int)_frameTime.size()-1: _end); - // are we stepping forward or backward? - int _step; - _step = (_ubegin < _uend ? 1 : -1); - _step = (_speed <0. ? -_step : _step); - int _sbegin = osg::minimum(_ubegin,_uend); int _send = osg::maximum(_ubegin,_uend); @@ -394,11 +399,6 @@ int Sequence::_getNextValue() int _ubegin = (_begin < 0 ? (int)_frameTime.size()-1: _begin); int _uend = (_end < 0 ? (int)_frameTime.size()-1: _end); - // are we stepping forward or backward? - int _step; - _step = (_ubegin < _uend ? 1 : -1); - _step = (_speed <0. ? -_step : _step); - int _sbegin = osg::minimum(_ubegin,_uend); int _send = osg::maximum(_ubegin,_uend);