2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
2007-05-09 19:11:19 +08:00
|
|
|
*/
|
2003-01-22 00:45:36 +08:00
|
|
|
|
2002-08-04 02:11:21 +08:00
|
|
|
#include <osg/Sequence>
|
2002-12-11 03:58:03 +08:00
|
|
|
#include <osg/Notify>
|
2002-08-04 02:11:21 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sequence constructor.
|
|
|
|
*/
|
|
|
|
Sequence::Sequence() :
|
2002-12-08 05:18:12 +08:00
|
|
|
Group(),
|
|
|
|
_value(-1),
|
2007-05-09 19:11:19 +08:00
|
|
|
_now(0.0),
|
|
|
|
_start(-1.0),
|
|
|
|
_totalTime(0.),
|
|
|
|
_resetTotalTime(true),
|
2002-08-29 05:40:38 +08:00
|
|
|
_loopMode(LOOP),
|
|
|
|
_begin(0),
|
|
|
|
_end(-1),
|
|
|
|
_speed(0),
|
2007-05-09 19:11:19 +08:00
|
|
|
_nreps(-1),
|
2012-01-03 00:54:05 +08:00
|
|
|
_nrepsRemain(-1),
|
2007-12-24 22:45:31 +08:00
|
|
|
_step(0),
|
2007-05-09 19:11:19 +08:00
|
|
|
_defaultTime(1.),
|
|
|
|
_lastFrameTime(0.),
|
|
|
|
_saveRealLastFrameTime(-1.),
|
|
|
|
_mode(STOP),
|
|
|
|
_sync(false),
|
|
|
|
_clearOnStop(false)
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-04 02:11:21 +08:00
|
|
|
{
|
2002-12-19 23:55:40 +08:00
|
|
|
setNumChildrenRequiringUpdateTraversal(1);
|
2002-08-04 02:11:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Sequence::Sequence(const Sequence& seq, const CopyOp& copyop) :
|
2002-12-08 05:18:12 +08:00
|
|
|
Group(seq, copyop),
|
|
|
|
_value(seq._value),
|
2007-05-09 19:11:19 +08:00
|
|
|
_now(seq._now),
|
|
|
|
_start(seq._start),
|
2004-02-10 18:07:32 +08:00
|
|
|
_frameTime(seq._frameTime),
|
2007-05-09 19:11:19 +08:00
|
|
|
_totalTime(seq._totalTime),
|
|
|
|
_resetTotalTime(seq._resetTotalTime),
|
2002-08-29 05:40:38 +08:00
|
|
|
_loopMode(seq._loopMode),
|
|
|
|
_begin(seq._begin),
|
|
|
|
_end(seq._end),
|
|
|
|
_speed(seq._speed),
|
|
|
|
_nreps(seq._nreps),
|
2007-05-09 19:11:19 +08:00
|
|
|
_nrepsRemain(seq._nrepsRemain),
|
2007-12-24 22:45:31 +08:00
|
|
|
_step(seq._step),
|
2006-11-10 23:25:04 +08:00
|
|
|
_defaultTime(seq._defaultTime),
|
2007-05-09 19:11:19 +08:00
|
|
|
_lastFrameTime(seq._lastFrameTime),
|
|
|
|
_saveRealLastFrameTime(seq._saveRealLastFrameTime),
|
|
|
|
_mode(seq._mode),
|
|
|
|
_sync(seq._sync),
|
|
|
|
_clearOnStop(seq._clearOnStop)
|
2002-08-04 02:11:21 +08:00
|
|
|
{
|
2012-03-22 01:36:20 +08:00
|
|
|
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
2002-08-04 02:11:21 +08:00
|
|
|
}
|
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
bool Sequence::addChild( Node *child)
|
|
|
|
{
|
|
|
|
return Sequence::insertChild( _children.size(), child, _defaultTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sequence::addChild( Node *child, double t)
|
|
|
|
{
|
|
|
|
return Sequence::insertChild( _children.size(), child, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sequence::insertChild( unsigned int index, Node *child)
|
2002-08-04 02:11:21 +08:00
|
|
|
{
|
2007-05-09 19:11:19 +08:00
|
|
|
return Sequence::insertChild(index, child, _defaultTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sequence::insertChild( unsigned int index, Node *child, double t)
|
|
|
|
{
|
|
|
|
if (Group::insertChild(index,child))
|
|
|
|
{
|
|
|
|
if (index>=_frameTime.size())
|
|
|
|
{
|
|
|
|
Sequence::setTime(index, t);
|
|
|
|
}
|
|
|
|
_resetTotalTime = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sequence::removeChild( Node *child )
|
|
|
|
{
|
|
|
|
if (Group::removeChild(child ))
|
|
|
|
{
|
|
|
|
unsigned int pos = getChildIndex(child);
|
|
|
|
if (pos < _children.size())
|
|
|
|
return Sequence::removeChildren(pos,1);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sequence::removeChildren(unsigned int pos,unsigned int numChildrenToRemove)
|
|
|
|
{
|
|
|
|
if (pos<_frameTime.size())
|
2012-03-22 01:36:20 +08:00
|
|
|
_frameTime.erase(_frameTime.begin()+pos,
|
|
|
|
osg::minimum(_frameTime.begin()+(pos+numChildrenToRemove),
|
2007-05-09 19:11:19 +08:00
|
|
|
_frameTime.end()) );
|
|
|
|
_resetTotalTime = true;
|
|
|
|
return Group::removeChildren(pos,numChildrenToRemove);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if frame >= _frameTime.size() then extend _frameTime to have frame-1 items
|
|
|
|
// a time <0 will get set to 0
|
|
|
|
void Sequence::setTime(unsigned int frame, double t)
|
|
|
|
{
|
|
|
|
if (t<0.) t = 0.0;
|
|
|
|
unsigned int sz = _frameTime.size();
|
2002-08-04 02:11:21 +08:00
|
|
|
if (frame < sz)
|
2007-05-09 19:11:19 +08:00
|
|
|
{
|
2002-08-04 02:11:21 +08:00
|
|
|
_frameTime[frame] = t;
|
2007-05-09 19:11:19 +08:00
|
|
|
}
|
2002-08-04 02:11:21 +08:00
|
|
|
else
|
2007-05-09 19:11:19 +08:00
|
|
|
{
|
|
|
|
for (unsigned int i = sz; i <= frame; i++)
|
|
|
|
{
|
2002-08-04 02:11:21 +08:00
|
|
|
_frameTime.push_back(t);
|
|
|
|
}
|
2007-05-09 19:11:19 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-04 02:11:21 +08:00
|
|
|
}
|
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// returns a frame time of -1 if frame is out of range
|
|
|
|
double Sequence::getTime(unsigned int frame) const
|
2002-08-04 02:11:21 +08:00
|
|
|
{
|
2007-05-09 19:11:19 +08:00
|
|
|
if (frame < _frameTime.size())
|
2002-08-04 02:11:21 +08:00
|
|
|
return _frameTime[frame];
|
|
|
|
else
|
|
|
|
return -1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sequence::setInterval(LoopMode mode, int begin, int end)
|
|
|
|
{
|
|
|
|
_loopMode = mode;
|
|
|
|
_end = end;
|
2007-05-09 19:11:19 +08:00
|
|
|
_begin = begin;
|
|
|
|
|
|
|
|
// _value based on _begin & _end
|
|
|
|
_value = -1;
|
2002-08-04 02:11:21 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
_resetTotalTime = true;
|
2002-08-04 02:11:21 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sequence::setDuration(float speed, int nreps)
|
|
|
|
{
|
2007-05-09 19:11:19 +08:00
|
|
|
_speed = speed;
|
|
|
|
// -1 means loop forever
|
|
|
|
_nreps = (nreps < 0 ? -1:nreps);
|
|
|
|
// countdown of laps around the track
|
|
|
|
_nrepsRemain = _nreps;
|
2002-08-04 02:11:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sequence::setMode(SequenceMode mode)
|
|
|
|
{
|
2007-12-24 22:45:31 +08:00
|
|
|
int ubegin, uend;
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
switch (mode)
|
2007-05-09 19:11:19 +08:00
|
|
|
{
|
2002-08-04 02:11:21 +08:00
|
|
|
case START:
|
2007-05-09 19:11:19 +08:00
|
|
|
// restarts sequence from beginning
|
|
|
|
_value = -1;
|
2007-12-24 22:45:31 +08:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2008-11-26 20:50:12 +08:00
|
|
|
_start = -1.0;
|
2002-08-04 02:11:21 +08:00
|
|
|
_mode = mode;
|
2007-05-09 19:11:19 +08:00
|
|
|
if (_saveRealLastFrameTime>=0.)
|
|
|
|
{
|
|
|
|
_frameTime[_saveRealLastFrameValue] = _saveRealLastFrameTime;
|
|
|
|
_saveRealLastFrameTime = -1.;
|
|
|
|
}
|
2002-08-04 02:11:21 +08:00
|
|
|
break;
|
|
|
|
case STOP:
|
|
|
|
_mode = mode;
|
|
|
|
break;
|
|
|
|
case PAUSE:
|
|
|
|
if (_mode == START)
|
|
|
|
_mode = PAUSE;
|
|
|
|
break;
|
|
|
|
case RESUME:
|
|
|
|
if (_mode == PAUSE)
|
|
|
|
_mode = START;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sequence::traverse(NodeVisitor& nv)
|
|
|
|
{
|
2007-05-09 19:11:19 +08:00
|
|
|
if (getNumChildren()==0) return;
|
|
|
|
|
2007-12-21 21:18:13 +08:00
|
|
|
const FrameStamp* framestamp = nv.getFrameStamp();
|
|
|
|
if (framestamp)
|
|
|
|
{
|
|
|
|
_now = framestamp->getSimulationTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
if (nv.getVisitorType()==NodeVisitor::UPDATE_VISITOR &&
|
2007-05-09 19:11:19 +08:00
|
|
|
_mode == START &&
|
|
|
|
!_frameTime.empty() && getNumChildren()!=0)
|
2002-08-12 05:26:58 +08:00
|
|
|
{
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// if begin or end < 0, make it last frame
|
|
|
|
int _ubegin = (_begin < 0 ? (int)_frameTime.size()-1: _begin);
|
|
|
|
int _uend = (_end < 0 ? (int)_frameTime.size()-1: _end);
|
|
|
|
|
|
|
|
int _sbegin = osg::minimum(_ubegin,_uend);
|
|
|
|
int _send = osg::maximum(_ubegin,_uend);
|
|
|
|
|
2002-12-08 05:18:12 +08:00
|
|
|
if (framestamp)
|
|
|
|
{
|
2007-05-09 19:11:19 +08:00
|
|
|
// hack for last frame time
|
|
|
|
if (_lastFrameTime>0. && _nrepsRemain==1 && _saveRealLastFrameTime<0.)
|
2002-12-08 05:18:12 +08:00
|
|
|
{
|
2007-05-09 19:11:19 +08:00
|
|
|
if ( _loopMode == LOOP)
|
|
|
|
{
|
|
|
|
if ((_step>0 && _value!=_send) || (_step<0 && _value!=_sbegin))
|
|
|
|
{
|
|
|
|
_saveRealLastFrameTime=_frameTime[_uend];
|
|
|
|
_saveRealLastFrameValue = _uend;
|
|
|
|
_frameTime[_uend] = _lastFrameTime;
|
|
|
|
_resetTotalTime = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_step>0 && _value!=_sbegin)
|
|
|
|
{
|
|
|
|
_saveRealLastFrameTime=_frameTime[_send];
|
|
|
|
_saveRealLastFrameValue = _send;
|
|
|
|
_frameTime[_send] = _lastFrameTime;
|
|
|
|
_resetTotalTime = true;
|
|
|
|
}
|
|
|
|
else if (_step<0 && _value!=_send)
|
|
|
|
{
|
|
|
|
_saveRealLastFrameTime=_frameTime[_sbegin];
|
|
|
|
_saveRealLastFrameValue = _sbegin;
|
|
|
|
_frameTime[_sbegin] = _lastFrameTime;
|
|
|
|
_resetTotalTime = true;
|
|
|
|
}
|
|
|
|
}
|
2002-12-08 05:18:12 +08:00
|
|
|
}
|
2002-08-04 02:11:21 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// I never know when to stop!
|
|
|
|
// more fun for last frame time
|
|
|
|
if (_nrepsRemain==0)
|
2002-12-08 05:18:12 +08:00
|
|
|
{
|
2007-05-09 19:11:19 +08:00
|
|
|
if (!_clearOnStop)
|
|
|
|
{
|
|
|
|
_mode = STOP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-22 01:36:20 +08:00
|
|
|
if ( (_loopMode == LOOP) &&
|
|
|
|
( (_step>0 && _value!=_send) ||
|
2007-05-09 19:11:19 +08:00
|
|
|
(_step<0 && _value!=_sbegin)))
|
|
|
|
{
|
|
|
|
_mode = STOP;
|
|
|
|
}
|
|
|
|
else if ( (_loopMode == SWING) &&
|
|
|
|
( (_step<0 && _value!=_send) ||
|
|
|
|
(_step>0 && _value!=_sbegin)))
|
|
|
|
{
|
|
|
|
_mode = STOP;
|
|
|
|
}
|
2002-08-04 02:11:21 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// update local variables
|
|
|
|
_update();
|
2002-08-04 02:11:21 +08:00
|
|
|
|
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// now for the heavy lifting! three options
|
|
|
|
// 1) still in the same frame, so have nothing to do
|
|
|
|
// 2) just in the next frame
|
|
|
|
// 3) need to calculate everything based on elapsed time
|
|
|
|
if ((_now - _start) > _frameTime[_value]*osg::absolute(_speed))
|
|
|
|
{ // case 2 or case 3
|
|
|
|
// most of the time it's just the next frame in the sequence
|
|
|
|
int nextValue = _getNextValue();
|
2012-03-22 01:36:20 +08:00
|
|
|
if (!_sync ||
|
2007-05-09 19:11:19 +08:00
|
|
|
((_now - _start) <= (_frameTime[_value]+_frameTime[nextValue])*osg::absolute(_speed)) )
|
|
|
|
{
|
2008-01-04 23:33:21 +08:00
|
|
|
_start += _frameTime[_value]*osg::absolute(_speed);
|
2007-05-09 19:11:19 +08:00
|
|
|
// repeat or change directions?
|
2012-03-22 01:36:20 +08:00
|
|
|
if ( (_step>0 && nextValue==_send) ||
|
2007-05-09 19:11:19 +08:00
|
|
|
(_step<0 && nextValue==_sbegin))
|
|
|
|
{
|
|
|
|
if (_nreps>0)
|
|
|
|
_nrepsRemain--;
|
2002-08-04 02:11:21 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// change direction
|
|
|
|
if (_loopMode == SWING)
|
2002-12-08 05:18:12 +08:00
|
|
|
_step = -_step;
|
2007-05-09 19:11:19 +08:00
|
|
|
|
2002-08-04 02:11:21 +08:00
|
|
|
}
|
2007-05-09 19:11:19 +08:00
|
|
|
_value = nextValue;
|
2002-08-04 02:11:21 +08:00
|
|
|
}
|
2007-05-09 19:11:19 +08:00
|
|
|
else // case 3
|
|
|
|
{
|
|
|
|
// recalculate everything based on elapsed time
|
2002-08-04 02:11:21 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// elapsed time from start of the frame
|
|
|
|
double deltaT = _now - _start;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// factors _speed into account
|
|
|
|
double adjTotalTime = _totalTime*osg::absolute(_speed);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// how many laps?
|
|
|
|
int loops = (int)(deltaT/adjTotalTime);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
|
2015-06-01 21:40:20 +08:00
|
|
|
// adjust reps & quick check to see if done because reps used up
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
if (_nreps>0)
|
|
|
|
{
|
|
|
|
if (_loopMode == LOOP)
|
|
|
|
_nrepsRemain -= loops;
|
|
|
|
else
|
|
|
|
_nrepsRemain -= 2*loops;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
if (_nrepsRemain<=0)
|
|
|
|
{
|
|
|
|
_nrepsRemain = 0;
|
|
|
|
_mode = STOP;
|
2010-05-28 23:47:52 +08:00
|
|
|
OSG_WARN << "stopping because elapsed time greater or equal to time remaining to repeat the sequence\n";
|
2007-05-09 19:11:19 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// deduct off time for laps- _value shouldn't change as it's modulo the total time
|
|
|
|
double jumpStart = ((double)loops * adjTotalTime);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// step through frames one at a time until caught up
|
|
|
|
while (deltaT-jumpStart > _frameTime[_value]*osg::absolute(_speed))
|
|
|
|
{
|
|
|
|
jumpStart += _frameTime[_value]*osg::absolute(_speed );
|
|
|
|
_value = _getNextValue();
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// set start time
|
|
|
|
_start += jumpStart;
|
|
|
|
}
|
2002-12-08 05:18:12 +08:00
|
|
|
}
|
2002-08-04 02:11:21 +08:00
|
|
|
}
|
2002-12-11 03:58:03 +08:00
|
|
|
else
|
2010-05-28 23:47:52 +08:00
|
|
|
OSG_WARN << "osg::Sequence::traverse(NodeVisitor&) requires a valid FrameStamp to function, sequence not updated.\n";
|
2007-05-09 19:11:19 +08:00
|
|
|
|
2002-08-04 02:11:21 +08:00
|
|
|
}
|
2007-05-09 19:11:19 +08:00
|
|
|
|
2002-12-08 05:18:12 +08:00
|
|
|
// now do the traversal
|
|
|
|
if (nv.getTraversalMode()==NodeVisitor::TRAVERSE_ACTIVE_CHILDREN)
|
|
|
|
{
|
2007-05-09 19:11:19 +08:00
|
|
|
if ( !((_mode == STOP) && _clearOnStop) &&
|
|
|
|
(getValue()>=0 && getValue()<(int)_children.size()) )
|
|
|
|
{
|
|
|
|
_children[getValue()]->accept(nv);
|
|
|
|
}
|
2002-12-08 05:18:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Group::traverse(nv);
|
|
|
|
}
|
2007-05-09 19:11:19 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int Sequence::_getNextValue()
|
|
|
|
{
|
|
|
|
if (_frameTime.empty() || getNumChildren()==0) return 0;
|
|
|
|
|
|
|
|
// if begin or end < 0, make it last frame
|
|
|
|
int _ubegin = (_begin < 0 ? (int)_frameTime.size()-1: _begin);
|
|
|
|
int _uend = (_end < 0 ? (int)_frameTime.size()-1: _end);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
int _sbegin = osg::minimum(_ubegin,_uend);
|
|
|
|
int _send = osg::maximum(_ubegin,_uend);
|
|
|
|
|
2014-06-26 19:49:59 +08:00
|
|
|
int v = _value + _step * static_cast<int>(osg::sign(_speed));
|
2007-05-09 19:11:19 +08:00
|
|
|
|
|
|
|
if (_sbegin==_send)
|
|
|
|
{
|
|
|
|
return _sbegin;
|
|
|
|
}
|
|
|
|
else if (v<=_send && v>=_sbegin)
|
|
|
|
{
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int vs = _send - _sbegin + 1;
|
|
|
|
if (_loopMode == LOOP)
|
|
|
|
{
|
|
|
|
v = ((v-_sbegin)%vs) + _sbegin;
|
|
|
|
if (v<_sbegin)
|
|
|
|
{
|
|
|
|
v+=vs;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
else // SWING
|
|
|
|
{
|
|
|
|
if (v>_send)
|
|
|
|
return (2*_send-v);
|
|
|
|
else
|
|
|
|
return (2*_sbegin-v);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sequence::_update()
|
|
|
|
{
|
|
|
|
if (_frameTime.empty()) return;
|
|
|
|
|
|
|
|
// if begin or end < 0, make it last frame
|
|
|
|
int _ubegin = (_begin < 0 ? (int)_frameTime.size()-1: _begin);
|
|
|
|
int _uend = (_end < 0 ? (int)_frameTime.size()-1: _end);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
int _sbegin = osg::minimum(_ubegin,_uend);
|
|
|
|
int _send = osg::maximum(_ubegin,_uend);
|
|
|
|
|
|
|
|
// if _value<0, new or restarted
|
|
|
|
if (_value<0)
|
|
|
|
{
|
|
|
|
_value = (_begin < 0 ? (int)_frameTime.size()-1: _begin);
|
|
|
|
_resetTotalTime = true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// if _start<0, new or restarted
|
|
|
|
if (_start<0)
|
|
|
|
{
|
|
|
|
_start = _now;
|
|
|
|
_resetTotalTime = true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// need to calculate time of a complete sequence?
|
|
|
|
// time is different depending on loop mode
|
|
|
|
if (_resetTotalTime)
|
|
|
|
{
|
|
|
|
if (_loopMode == LOOP)
|
|
|
|
{
|
|
|
|
_totalTime = 0.0;
|
|
|
|
for (int i=_sbegin; i<=_send; i++)
|
|
|
|
{
|
|
|
|
_totalTime += _frameTime[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //SWING
|
|
|
|
{
|
|
|
|
_totalTime = _frameTime[_sbegin];
|
|
|
|
// ones in the middle get counted twice: 0 1 2 3 4 3 2 1 0
|
|
|
|
for (int i=_sbegin+1; i<_send; i++)
|
|
|
|
{
|
|
|
|
_totalTime += 2*_frameTime[i];
|
|
|
|
}
|
|
|
|
if (_sbegin != _send)
|
|
|
|
{
|
|
|
|
_totalTime += _frameTime[_send];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_resetTotalTime = false;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-04 02:11:21 +08:00
|
|
|
}
|