Sequence
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_SEQUENCE
#define OSG_SEQUENCE 1
#include <osg/Group>
namespace osg
{
class OSG_EXPORT Sequence : public Group
{
public :
Sequence();
Sequence(const Sequence&, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, Sequence);
virtual void traverse(NodeVisitor& nv);
// the relationship between the _frameTime vector and the _children
// vector is a bit of a mess. This is how it was in previous versions,
// and there's no way out of it if upward compatibility needs to be
// maintained. New code should set defaultTime and use addChild, and
// not mess with the setTime method
using osg::Group::addChild;
using osg::Group::insertChild;
using osg::Group::removeChild;
virtual bool addChild( Node *child);
virtual bool addChild( Node *child, double t);
template<class T> bool addChild( const ref_ptr<T>& child, double t) { return addChild(child.get(), t); }
virtual bool insertChild( unsigned int index, Node *child);
virtual bool insertChild( unsigned int index, Node *child, double t);
template<class T> bool insertChild( unsigned int index, const ref_ptr<T>& child, double t) { return insertChild(index, child.get(), t); }
virtual bool removeChild( Node *child );
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
void setValue(int value) { _value = value ; }
int getValue() const { return _value; }
void setTime(unsigned int frame, double t);
double getTime(unsigned int frame) const;
void setTimeList(const std::vector<double>& timeList) { _frameTime = timeList; }
const std::vector<double>& getTimeList() const { return _frameTime; }
void setDefaultTime(double t) {_defaultTime = (t<0.?0.:t);}
double getDefaultTime(void) const {return _defaultTime;};
void setLastFrameTime(double t) {_lastFrameTime = (t<0.?0.:t);}
double getLastFrameTime(void) const {return _lastFrameTime;};
inline unsigned int getNumFrames() const { return _frameTime.size(); }
enum LoopMode
{
LOOP,
SWING
};
void setLoopMode(LoopMode mode) { _loopMode = mode; _value = -1; }
LoopMode getLoopMode() const { return _loopMode; }
void setBegin(int begin) { _begin = begin; _value = -1; }
int getBegin() const { return _begin; }
void setEnd(int end) { _end = end; _value = -1; }
int getEnd() const { return _end; }
void setInterval(LoopMode mode, int begin, int end);
inline void getInterval(LoopMode& mode, int& begin, int& end) const
{
mode = _loopMode;
begin = _begin;
end = _end;
}
void setSpeed(float speed) { _speed = speed; }
float getSpeed() const { return _speed; }
void setNumRepeats(int nreps) { _nreps = (nreps<0?-1:nreps); _nrepsRemain = _nreps; }
int getNumRepeats() const { return _nreps; }
void setDuration(float speed, int nreps = -1);
inline void getDuration(float& speed, int& nreps) const
{
speed = _speed;
nreps = _nreps;
}
enum SequenceMode
{
START,
STOP,
PAUSE,
RESUME
};
void setMode(SequenceMode mode);
inline SequenceMode getMode() const { return _mode; }
void setSync(bool sync) { _sync = sync; }
bool getSync() const { return _sync; }
void setClearOnStop(bool clearOnStop) { _clearOnStop = clearOnStop; }
bool getClearOnStop() const { return _clearOnStop; }
protected :
virtual ~Sequence() {}
// get next _value in sequence
int _getNextValue(void) ;
// update local variables
void _update(void) ;
// init to -1 to mean "restart"
int _value;
// current time, set by traverse
double _now ;
// time this frame started. init to -1.0f- means get current time
double _start;
// a vector of frame times, one per value
std::vector<double> _frameTime;
// the total time for one sequence, from BEGIN to END
double _totalTime ;
// true if _totalTime needs to be recalculated because setTime or
// setInterval was invoked, or a new child was added
bool _resetTotalTime ;
// store "loop mde", either LOOP or SWING
// init to LOOP- set by setInterval
LoopMode _loopMode;
// first and last "values" to sequence through
// begin inits to 0
// end inits to -1- means to init to number of values
int _begin, _end;
// multiplier of real-time clock- set to N to go N times faster
// init to 0- going nowhere
float _speed;
// _nreps: how many times to repeat- default param is -1, repeat forever
// init to 0, no repetitions
// _nrepsRemain: set to nreps and counts down every traversal,
// 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 ;
// special time to display last frame of last loop
// <= zero means to not do anything special
double _lastFrameTime ;
// save the actual time of the last frame, and what value was stored
double _saveRealLastFrameTime ;
unsigned int _saveRealLastFrameValue ;
// the current mode
SequenceMode _mode;
// the current sync value
bool _sync ;
// the current clearOnStop value
bool _clearOnStop ;
};
}
#endif
Group
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Group::insertChild
virtual bool insertChild(unsigned int index, Node *child)
osg::Group::addChild
virtual bool addChild(Node *child)
osg::Group::Group
Group()
osg::Group::removeChild
virtual bool removeChild(Node *child)
osg::NodeVisitor
Definition NodeVisitor:82
osg::Node
Definition Node:72
osg::Sequence::removeChildren
virtual bool removeChildren(unsigned int pos, unsigned int numChildrenToRemove)
osg::Sequence::_defaultTime
double _defaultTime
Definition Sequence:237
osg::Sequence::getDuration
void getDuration(float &speed, int &nreps) const
Definition Sequence:150
osg::Sequence::_begin
int _begin
Definition Sequence:220
osg::Sequence::setSpeed
void setSpeed(float speed)
Definition Sequence:135
osg::Sequence::_frameTime
std::vector< double > _frameTime
Definition Sequence:204
osg::Sequence::insertChild
bool insertChild(unsigned int index, const ref_ptr< T > &child, double t)
Definition Sequence:58
osg::Sequence::setSync
void setSync(bool sync)
Definition Sequence:173
osg::Sequence::getDefaultTime
double getDefaultTime(void) const
Definition Sequence:86
osg::Sequence::getLoopMode
LoopMode getLoopMode() const
Definition Sequence:109
osg::Sequence::_value
int _value
Definition Sequence:195
osg::Sequence::traverse
virtual void traverse(NodeVisitor &nv)
osg::Sequence::Sequence
Sequence(const Sequence &, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::Sequence::setTime
void setTime(unsigned int frame, double t)
osg::Sequence::_resetTotalTime
bool _resetTotalTime
Definition Sequence:211
osg::Sequence::_end
int _end
Definition Sequence:220
osg::Sequence::_update
void _update(void)
osg::Sequence::_start
double _start
Definition Sequence:201
osg::Sequence::insertChild
virtual bool insertChild(unsigned int index, Node *child)
osg::Sequence::SequenceMode
SequenceMode
Definition Sequence:158
osg::Sequence::PAUSE
@ PAUSE
Definition Sequence:161
osg::Sequence::STOP
@ STOP
Definition Sequence:160
osg::Sequence::RESUME
@ RESUME
Definition Sequence:162
osg::Sequence::START
@ START
Definition Sequence:159
osg::Sequence::_nreps
int _nreps
Definition Sequence:230
osg::Sequence::getMode
SequenceMode getMode() const
Definition Sequence:169
osg::Sequence::setValue
void setValue(int value)
Definition Sequence:66
osg::Sequence::setLoopMode
void setLoopMode(LoopMode mode)
Definition Sequence:106
osg::Sequence::addChild
virtual bool addChild(Node *child, double t)
osg::Sequence::_speed
float _speed
Definition Sequence:224
osg::Sequence::addChild
virtual bool addChild(Node *child)
osg::Sequence::_nrepsRemain
int _nrepsRemain
Definition Sequence:230
osg::Sequence::addChild
bool addChild(const ref_ptr< T > &child, double t)
Definition Sequence:52
osg::Sequence::~Sequence
virtual ~Sequence()
Definition Sequence:186
osg::Sequence::_loopMode
LoopMode _loopMode
Definition Sequence:215
osg::Sequence::getLastFrameTime
double getLastFrameTime(void) const
Definition Sequence:93
osg::Sequence::getSync
bool getSync() const
Definition Sequence:176
osg::Sequence::setDefaultTime
void setDefaultTime(double t)
Definition Sequence:83
osg::Sequence::setNumRepeats
void setNumRepeats(int nreps)
Definition Sequence:141
osg::Sequence::setLastFrameTime
void setLastFrameTime(double t)
Definition Sequence:90
osg::Sequence::getSpeed
float getSpeed() const
Definition Sequence:138
osg::Sequence::META_Node
META_Node(osg, Sequence)
osg::Sequence::getNumRepeats
int getNumRepeats() const
Definition Sequence:144
osg::Sequence::_getNextValue
int _getNextValue(void)
osg::Sequence::getInterval
void getInterval(LoopMode &mode, int &begin, int &end) const
Definition Sequence:127
osg::Sequence::getClearOnStop
bool getClearOnStop() const
Definition Sequence:182
osg::Sequence::setClearOnStop
void setClearOnStop(bool clearOnStop)
Definition Sequence:179
osg::Sequence::_clearOnStop
bool _clearOnStop
Definition Sequence:254
osg::Sequence::Sequence
Sequence()
osg::Sequence::_now
double _now
Definition Sequence:198
osg::Sequence::setDuration
void setDuration(float speed, int nreps=-1)
osg::Sequence::_sync
bool _sync
Definition Sequence:251
osg::Sequence::getNumFrames
unsigned int getNumFrames() const
Definition Sequence:96
osg::Sequence::getTimeList
const std::vector< double > & getTimeList() const
Definition Sequence:79
osg::Sequence::getTime
double getTime(unsigned int frame) const
osg::Sequence::removeChild
virtual bool removeChild(Node *child)
osg::Sequence::getEnd
int getEnd() const
Definition Sequence:121
osg::Sequence::_mode
SequenceMode _mode
Definition Sequence:248
osg::Sequence::_step
int _step
Definition Sequence:233
osg::Sequence::setMode
void setMode(SequenceMode mode)
osg::Sequence::insertChild
virtual bool insertChild(unsigned int index, Node *child, double t)
osg::Sequence::_totalTime
double _totalTime
Definition Sequence:207
osg::Sequence::setInterval
void setInterval(LoopMode mode, int begin, int end)
osg::Sequence::setEnd
void setEnd(int end)
Definition Sequence:118
osg::Sequence::_saveRealLastFrameTime
double _saveRealLastFrameTime
Definition Sequence:244
osg::Sequence::_saveRealLastFrameValue
unsigned int _saveRealLastFrameValue
Definition Sequence:245
osg::Sequence::_lastFrameTime
double _lastFrameTime
Definition Sequence:241
osg::Sequence::setTimeList
void setTimeList(const std::vector< double > &timeList)
Definition Sequence:76
osg::Sequence::setBegin
void setBegin(int begin)
Definition Sequence:112
osg::Sequence::getBegin
int getBegin() const
Definition Sequence:115
osg::Sequence::LoopMode
LoopMode
Definition Sequence:100
osg::Sequence::SWING
@ SWING
Definition Sequence:102
osg::Sequence::LOOP
@ LOOP
Definition Sequence:101
osg::Sequence::getValue
int getValue() const
Definition Sequence:67
osg::ref_ptr
Definition ref_ptr:32
osg::ref_ptr::get
T * get() const
Definition ref_ptr:117
osg
Definition AlphaFunc:19
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39