2010-01-13 21:30:14 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2004-09-03 02:19:38 +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
|
2004-09-03 02:19:38 +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
|
|
|
*
|
2004-09-03 02:19:38 +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
|
2004-09-03 02:19:38 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
2007-05-09 19:11:19 +08:00
|
|
|
*/
|
2004-09-03 02:19:38 +08:00
|
|
|
|
|
|
|
#ifndef OSG_SEQUENCE
|
|
|
|
#define OSG_SEQUENCE 1
|
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
#include <osg/Group>
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
namespace osg
|
2007-05-09 19:11:19 +08:00
|
|
|
{
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-03 02:19:38 +08:00
|
|
|
/** Sequence is a Group node which allows automatic, time based
|
2007-05-09 19:11:19 +08:00
|
|
|
switching between children.
|
2004-09-03 02:19:38 +08:00
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Sequence : public Group
|
2004-09-03 02:19:38 +08:00
|
|
|
{
|
2007-05-09 19:11:19 +08:00
|
|
|
public :
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
Sequence();
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
Sequence(const Sequence&, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
META_Node(osg, Sequence);
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
virtual void traverse(NodeVisitor& nv);
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// the relationship between the _frameTime vector and the _children
|
|
|
|
// vector is a bit of a mess. This is how it was in previous versions,
|
2007-12-11 01:30:18 +08:00
|
|
|
// and there's no way out of it if upward compatibility needs to be
|
2007-05-09 19:11:19 +08:00
|
|
|
// maintained. New code should set defaultTime and use addChild, and
|
|
|
|
// not mess with the setTime method
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
using osg::Group::addChild;
|
|
|
|
using osg::Group::insertChild;
|
|
|
|
using osg::Group::removeChild;
|
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
virtual bool addChild( Node *child);
|
2006-11-10 23:25:04 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
virtual bool addChild( Node *child, double t);
|
2006-11-10 23:25:04 +08:00
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
template<class T> bool addChild( const ref_ptr<T>& child, double t) { return addChild(child.get(), t); }
|
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
virtual bool insertChild( unsigned int index, Node *child);
|
2005-06-20 18:38:39 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
virtual bool insertChild( unsigned int index, Node *child, double t);
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
template<class T> bool insertChild( unsigned int index, const ref_ptr<T>& child, double t) { return insertChild(index, child.get(), t); }
|
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
virtual bool removeChild( Node *child );
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
|
2004-09-03 02:19:38 +08:00
|
|
|
|
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** value is which child node is to be displayed */
|
|
|
|
void setValue(int value) { _value = value ; }
|
|
|
|
int getValue() const { return _value; }
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Set time in seconds for child. */
|
|
|
|
void setTime(unsigned int frame, double t);
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Get time for child. */
|
|
|
|
double getTime(unsigned int frame) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Set the time list for children. */
|
|
|
|
void setTimeList(const std::vector<double>& timeList) { _frameTime = timeList; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Get the time list for children. */
|
|
|
|
const std::vector<double>& getTimeList() const { return _frameTime; }
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Set default time in seconds for new child.
|
2007-05-09 19:11:19 +08:00
|
|
|
if t<0, t=0 */
|
|
|
|
void setDefaultTime(double t) {_defaultTime = (t<0.?0.:t);}
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Get default time in seconds for new child. */
|
|
|
|
double getDefaultTime(void) const {return _defaultTime;};
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Set time of last frame of last loop, in seconds.
|
2007-05-09 19:11:19 +08:00
|
|
|
if t<= 0, then ignored */
|
|
|
|
void setLastFrameTime(double t) {_lastFrameTime = (t<0.?0.:t);}
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Get last frame time in seconds */
|
|
|
|
double getLastFrameTime(void) const {return _lastFrameTime;};
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Get number of frames */
|
|
|
|
inline unsigned int getNumFrames() const { return _frameTime.size(); }
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Interval modes. 'Loop' repeats frames 1-N; 'swing' repeats 1->N, (N-1)->1. */
|
|
|
|
enum LoopMode
|
|
|
|
{
|
|
|
|
LOOP,
|
|
|
|
SWING
|
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Set sequence mode. */
|
|
|
|
void setLoopMode(LoopMode mode) { _loopMode = mode; _value = -1; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Get sequence mode. */
|
|
|
|
LoopMode getLoopMode() const { return _loopMode; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Set interval beginning. */
|
|
|
|
void setBegin(int begin) { _begin = begin; _value = -1; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Get interval beginning. */
|
|
|
|
int getBegin() const { return _begin; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Set interval ending. */
|
|
|
|
void setEnd(int end) { _end = end; _value = -1; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Get interval ending. */
|
|
|
|
int getEnd() const { return _end; }
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Set sequence mode & interval (range of children to be displayed). */
|
|
|
|
void setInterval(LoopMode mode, int begin, int end);
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Get sequence mode & interval. */
|
|
|
|
inline void getInterval(LoopMode& mode, int& begin, int& end) const
|
|
|
|
{
|
|
|
|
mode = _loopMode;
|
|
|
|
begin = _begin;
|
|
|
|
end = _end;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Set speed. */
|
|
|
|
void setSpeed(float speed) { _speed = speed; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Get speed. */
|
|
|
|
float getSpeed() const { return _speed; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Set number of repeats. */
|
|
|
|
void setNumRepeats(int nreps) { _nreps = (nreps<0?-1:nreps); _nrepsRemain = _nreps; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Get number of repeats. */
|
|
|
|
int getNumRepeats() const { return _nreps; }
|
2006-11-10 23:25:04 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
/** Set duration: speed-up & number of repeats */
|
|
|
|
void setDuration(float speed, int nreps = -1);
|
|
|
|
|
|
|
|
/** Get duration & number of repeats. */
|
|
|
|
inline void getDuration(float& speed, int& nreps) const
|
|
|
|
{
|
|
|
|
speed = _speed;
|
|
|
|
nreps = _nreps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sequence modes. */
|
|
|
|
enum SequenceMode
|
|
|
|
{
|
|
|
|
START,
|
|
|
|
STOP,
|
|
|
|
PAUSE,
|
|
|
|
RESUME
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Set sequence mode. Start/stop & pause/resume. */
|
|
|
|
void setMode(SequenceMode mode);
|
|
|
|
|
|
|
|
/** Get sequence mode. */
|
|
|
|
inline SequenceMode getMode() const { return _mode; }
|
|
|
|
|
|
|
|
/** If false (default), frames will not be sync'd to frameTime. If
|
|
|
|
true, frames will be sync'd to frameTime. */
|
2010-01-13 21:30:14 +08:00
|
|
|
void setSync(bool sync) { _sync = sync; }
|
2007-05-09 19:11:19 +08:00
|
|
|
|
|
|
|
/** Get sync value */
|
2010-01-13 21:30:14 +08:00
|
|
|
bool getSync() const { return _sync; }
|
2007-05-09 19:11:19 +08:00
|
|
|
|
|
|
|
/** If true, show no child nodes after stopping */
|
2010-01-13 21:30:14 +08:00
|
|
|
void setClearOnStop(bool clearOnStop) { _clearOnStop = clearOnStop; }
|
2007-05-09 19:11:19 +08:00
|
|
|
|
2010-01-13 21:30:14 +08:00
|
|
|
/** Get whether to show no child nodes after stopping */
|
|
|
|
bool getClearOnStop() const { return _clearOnStop; }
|
2007-05-09 19:11:19 +08:00
|
|
|
|
|
|
|
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;
|
2004-09-03 02:19:38 +08:00
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// 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
|
2012-03-22 01:36:20 +08:00
|
|
|
// _nrepsRemain: set to nreps and counts down every traversal,
|
2007-05-09 19:11:19 +08:00
|
|
|
// stopping when it gets to zero. init to 0
|
|
|
|
int _nreps, _nrepsRemain;
|
|
|
|
|
2007-12-24 22:45:31 +08:00
|
|
|
// frame step (are we stepping forward or backward?)
|
|
|
|
int _step;
|
|
|
|
|
2007-05-09 19:11:19 +08:00
|
|
|
// 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 ;
|
|
|
|
|
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-03 02:19:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|