OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Sequence.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12  */
13 
14 #ifndef OSG_SEQUENCE
15 #define OSG_SEQUENCE 1
16 
17 #include <osg/Group>
18 
19 namespace osg
20 {
21 
25 class OSG_EXPORT Sequence : public Group
26 {
27  public :
28 
29  Sequence();
30 
32  Sequence(const Sequence&, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
33 
35 
36  virtual void traverse(NodeVisitor& nv);
37 
38  // the relationship between the _frameTime vector and the _children
39  // vector is a bit of a mess. This is how it was in previous versions,
40  // and there's no way out of it if upward compatibility needs to be
41  // maintained. New code should set defaultTime and use addChild, and
42  // not mess with the setTime method
43 
44  virtual bool addChild( Node *child);
45 
46  virtual bool addChild( Node *child, double t);
47 
48  virtual bool insertChild( unsigned int index, Node *child);
49 
50  virtual bool insertChild( unsigned int index, Node *child, double t);
51 
52  virtual bool removeChild( Node *child );
53 
54  virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
55 
56 
58  void setValue(int value) { _value = value ; }
59  int getValue() const { return _value; }
60 
62  void setTime(unsigned int frame, double t);
63 
65  double getTime(unsigned int frame) const;
66 
68  void setTimeList(const std::vector<double>& timeList) { _frameTime = timeList; }
69 
71  const std::vector<double>& getTimeList() const { return _frameTime; }
72 
75  void setDefaultTime(double t) {_defaultTime = (t<0.?0.:t);}
76 
78  double getDefaultTime(void) const {return _defaultTime;};
79 
82  void setLastFrameTime(double t) {_lastFrameTime = (t<0.?0.:t);}
83 
85  double getLastFrameTime(void) const {return _lastFrameTime;};
86 
88  inline unsigned int getNumFrames() const { return _frameTime.size(); }
89 
91  enum LoopMode
92  {
94  SWING
95  };
96 
98  void setLoopMode(LoopMode mode) { _loopMode = mode; _value = -1; }
99 
101  LoopMode getLoopMode() const { return _loopMode; }
102 
104  void setBegin(int begin) { _begin = begin; _value = -1; }
105 
107  int getBegin() const { return _begin; }
108 
110  void setEnd(int end) { _end = end; _value = -1; }
111 
113  int getEnd() const { return _end; }
114 
116  void setInterval(LoopMode mode, int begin, int end);
117 
119  inline void getInterval(LoopMode& mode, int& begin, int& end) const
120  {
121  mode = _loopMode;
122  begin = _begin;
123  end = _end;
124  }
125 
127  void setSpeed(float speed) { _speed = speed; }
128 
130  float getSpeed() const { return _speed; }
131 
133  void setNumRepeats(int nreps) { _nreps = (nreps<0?-1:nreps); _nrepsRemain = _nreps; }
134 
136  int getNumRepeats() const { return _nreps; }
137 
139  void setDuration(float speed, int nreps = -1);
140 
142  inline void getDuration(float& speed, int& nreps) const
143  {
144  speed = _speed;
145  nreps = _nreps;
146  }
147 
150  {
154  RESUME
155  };
156 
158  void setMode(SequenceMode mode);
159 
161  inline SequenceMode getMode() const { return _mode; }
162 
165  void setSync(bool sync) { _sync = sync; }
166 
168  bool getSync() const { return _sync; }
169 
171  void setClearOnStop(bool clearOnStop) { _clearOnStop = clearOnStop; }
172 
174  bool getClearOnStop() const { return _clearOnStop; }
175 
176  protected :
177 
178  virtual ~Sequence() {}
179 
180  // get next _value in sequence
181  int _getNextValue(void) ;
182 
183  // update local variables
184  void _update(void) ;
185 
186  // init to -1 to mean "restart"
187  int _value;
188 
189  // current time, set by traverse
190  double _now ;
191 
192  // time this frame started. init to -1.0f- means get current time
193  double _start;
194 
195  // a vector of frame times, one per value
196  std::vector<double> _frameTime;
197 
198  // the total time for one sequence, from BEGIN to END
199  double _totalTime ;
200 
201  // true if _totalTime needs to be recalculated because setTime or
202  // setInterval was invoked, or a new child was added
204 
205  // store "loop mde", either LOOP or SWING
206  // init to LOOP- set by setInterval
208 
209  // first and last "values" to sequence through
210  // begin inits to 0
211  // end inits to -1- means to init to number of values
212  int _begin, _end;
213 
214  // multiplier of real-time clock- set to N to go N times faster
215  // init to 0- going nowhere
216  float _speed;
217 
218  // _nreps: how many times to repeat- default param is -1, repeat forever
219  // init to 0, no repetitions
220  // _nrepsRemain: set to nreps and counts down every traversal,
221  // stopping when it gets to zero. init to 0
222  int _nreps, _nrepsRemain;
223 
224  // frame step (are we stepping forward or backward?)
225  int _step;
226 
227  // default frame time for newly created frames or children- default is 1.
228  // set by setDefaultTime
229  double _defaultTime ;
230 
231  // special time to display last frame of last loop
232  // <= zero means to not do anything special
233  double _lastFrameTime ;
234 
235  // save the actual time of the last frame, and what value was stored
237  unsigned int _saveRealLastFrameValue ;
238 
239  // the current mode
241 
242  // the current sync value
243  bool _sync ;
244 
245  // the current clearOnStop value
247 
248 };
249 
250 }
251 
252 #endif
#define OSG_EXPORT
Definition: Export.h:43
bool _clearOnStop
Definition: Sequence.h:246
double _totalTime
Definition: Sequence.h:199
void getInterval(LoopMode &mode, int &begin, int &end) const
Definition: Sequence.h:119
void setSync(bool sync)
Definition: Sequence.h:165
double _now
Definition: Sequence.h:190
unsigned int _saveRealLastFrameValue
Definition: Sequence.h:237
void setClearOnStop(bool clearOnStop)
Definition: Sequence.h:171
double _saveRealLastFrameTime
Definition: Sequence.h:236
#define META_Node(library, name)
Definition: Node.h:59
SequenceMode getMode() const
Definition: Sequence.h:161
bool getClearOnStop() const
Definition: Sequence.h:174
void setLastFrameTime(double t)
Definition: Sequence.h:82
std::vector< double > _frameTime
Definition: Sequence.h:196
int getValue() const
Definition: Sequence.h:59
bool getSync() const
Definition: Sequence.h:168
int getNumRepeats() const
Definition: Sequence.h:136
const std::vector< double > & getTimeList() const
Definition: Sequence.h:71
unsigned int getNumFrames() const
Definition: Sequence.h:88
double _lastFrameTime
Definition: Sequence.h:233
float getSpeed() const
Definition: Sequence.h:130
int getBegin() const
Definition: Sequence.h:107
void setLoopMode(LoopMode mode)
Definition: Sequence.h:98
int getEnd() const
Definition: Sequence.h:113
float _speed
Definition: Sequence.h:216
virtual ~Sequence()
Definition: Sequence.h:178
bool _resetTotalTime
Definition: Sequence.h:203
SequenceMode _mode
Definition: Sequence.h:240
void getDuration(float &speed, int &nreps) const
Definition: Sequence.h:142
void setBegin(int begin)
Definition: Sequence.h:104
void setTimeList(const std::vector< double > &timeList)
Definition: Sequence.h:68
double getLastFrameTime(void) const
Definition: Sequence.h:85
void setSpeed(float speed)
Definition: Sequence.h:127
Definition: Node.h:71
Definition: AlphaFunc.h:19
void setNumRepeats(int nreps)
Definition: Sequence.h:133
int _nrepsRemain
Definition: Sequence.h:222
void setValue(int value)
Definition: Sequence.h:58
double _start
Definition: Sequence.h:193
void setDefaultTime(double t)
Definition: Sequence.h:75
double getDefaultTime(void) const
Definition: Sequence.h:78
void setEnd(int end)
Definition: Sequence.h:110
LoopMode _loopMode
Definition: Sequence.h:207
LoopMode getLoopMode() const
Definition: Sequence.h:101
double _defaultTime
Definition: Sequence.h:229