openscenegraph
Sequence
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
19namespace osg
20{
21
26{
27 public :
28
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
47
48 virtual bool addChild( Node *child);
49
50 virtual bool addChild( Node *child, double t);
51
52 template<class T> bool addChild( const ref_ptr<T>& child, double t) { return addChild(child.get(), t); }
53
54 virtual bool insertChild( unsigned int index, Node *child);
55
56 virtual bool insertChild( unsigned int index, Node *child, double t);
57
58 template<class T> bool insertChild( unsigned int index, const ref_ptr<T>& child, double t) { return insertChild(index, child.get(), t); }
59
60 virtual bool removeChild( Node *child );
61
62 virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
63
64
66 void setValue(int value) { _value = value ; }
67 int getValue() const { return _value; }
68
70 void setTime(unsigned int frame, double t);
71
73 double getTime(unsigned int frame) const;
74
76 void setTimeList(const std::vector<double>& timeList) { _frameTime = timeList; }
77
79 const std::vector<double>& getTimeList() const { return _frameTime; }
80
83 void setDefaultTime(double t) {_defaultTime = (t<0.?0.:t);}
84
86 double getDefaultTime(void) const {return _defaultTime;};
87
90 void setLastFrameTime(double t) {_lastFrameTime = (t<0.?0.:t);}
91
93 double getLastFrameTime(void) const {return _lastFrameTime;};
94
96 inline unsigned int getNumFrames() const { return _frameTime.size(); }
97
100 {
102 SWING
103 };
104
106 void setLoopMode(LoopMode mode) { _loopMode = mode; _value = -1; }
107
109 LoopMode getLoopMode() const { return _loopMode; }
110
112 void setBegin(int begin) { _begin = begin; _value = -1; }
113
115 int getBegin() const { return _begin; }
116
118 void setEnd(int end) { _end = end; _value = -1; }
119
121 int getEnd() const { return _end; }
122
124 void setInterval(LoopMode mode, int begin, int end);
125
127 inline void getInterval(LoopMode& mode, int& begin, int& end) const
128 {
129 mode = _loopMode;
130 begin = _begin;
131 end = _end;
132 }
133
135 void setSpeed(float speed) { _speed = speed; }
136
138 float getSpeed() const { return _speed; }
139
141 void setNumRepeats(int nreps) { _nreps = (nreps<0?-1:nreps); _nrepsRemain = _nreps; }
142
144 int getNumRepeats() const { return _nreps; }
145
147 void setDuration(float speed, int nreps = -1);
148
150 inline void getDuration(float& speed, int& nreps) const
151 {
152 speed = _speed;
153 nreps = _nreps;
154 }
155
158 {
162 RESUME
163 };
164
167
169 inline SequenceMode getMode() const { return _mode; }
170
173 void setSync(bool sync) { _sync = sync; }
174
176 bool getSync() const { return _sync; }
177
179 void setClearOnStop(bool clearOnStop) { _clearOnStop = clearOnStop; }
180
182 bool getClearOnStop() const { return _clearOnStop; }
183
184 protected :
185
186 virtual ~Sequence() {}
187
188 // get next _value in sequence
189 int _getNextValue(void) ;
190
191 // update local variables
192 void _update(void) ;
193
194 // init to -1 to mean "restart"
196
197 // current time, set by traverse
198 double _now ;
199
200 // time this frame started. init to -1.0f- means get current time
201 double _start;
202
203 // a vector of frame times, one per value
204 std::vector<double> _frameTime;
205
206 // the total time for one sequence, from BEGIN to END
207 double _totalTime ;
208
209 // true if _totalTime needs to be recalculated because setTime or
210 // setInterval was invoked, or a new child was added
212
213 // store "loop mde", either LOOP or SWING
214 // init to LOOP- set by setInterval
216
217 // first and last "values" to sequence through
218 // begin inits to 0
219 // end inits to -1- means to init to number of values
220 int _begin, _end;
221
222 // multiplier of real-time clock- set to N to go N times faster
223 // init to 0- going nowhere
224 float _speed;
225
226 // _nreps: how many times to repeat- default param is -1, repeat forever
227 // init to 0, no repetitions
228 // _nrepsRemain: set to nreps and counts down every traversal,
229 // stopping when it gets to zero. init to 0
230 int _nreps, _nrepsRemain;
231
232 // frame step (are we stepping forward or backward?)
233 int _step;
234
235 // default frame time for newly created frames or children- default is 1.
236 // set by setDefaultTime
238
239 // special time to display last frame of last loop
240 // <= zero means to not do anything special
242
243 // save the actual time of the last frame, and what value was stored
246
247 // the current mode
249
250 // the current sync value
251 bool _sync ;
252
253 // the current clearOnStop value
255
256};
257
258}
259
260#endif
Definition CopyOp:41
Definition Group:29
virtual bool insertChild(unsigned int index, Node *child)
virtual bool addChild(Node *child)
virtual bool removeChild(Node *child)
Definition NodeVisitor:82
Definition Node:72
Definition Sequence:26
virtual bool removeChildren(unsigned int pos, unsigned int numChildrenToRemove)
double _defaultTime
Definition Sequence:237
void getDuration(float &speed, int &nreps) const
Definition Sequence:150
int _begin
Definition Sequence:220
void setSpeed(float speed)
Definition Sequence:135
std::vector< double > _frameTime
Definition Sequence:204
bool insertChild(unsigned int index, const ref_ptr< T > &child, double t)
Definition Sequence:58
void setSync(bool sync)
Definition Sequence:173
double getDefaultTime(void) const
Definition Sequence:86
LoopMode getLoopMode() const
Definition Sequence:109
int _value
Definition Sequence:195
virtual void traverse(NodeVisitor &nv)
Sequence(const Sequence &, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
void setTime(unsigned int frame, double t)
bool _resetTotalTime
Definition Sequence:211
void _update(void)
double _start
Definition Sequence:201
virtual bool insertChild(unsigned int index, Node *child)
SequenceMode
Definition Sequence:158
@ PAUSE
Definition Sequence:161
@ STOP
Definition Sequence:160
@ START
Definition Sequence:159
int _nreps
Definition Sequence:230
SequenceMode getMode() const
Definition Sequence:169
void setValue(int value)
Definition Sequence:66
void setLoopMode(LoopMode mode)
Definition Sequence:106
virtual bool addChild(Node *child, double t)
float _speed
Definition Sequence:224
virtual bool addChild(Node *child)
bool addChild(const ref_ptr< T > &child, double t)
Definition Sequence:52
virtual ~Sequence()
Definition Sequence:186
LoopMode _loopMode
Definition Sequence:215
double getLastFrameTime(void) const
Definition Sequence:93
bool getSync() const
Definition Sequence:176
void setDefaultTime(double t)
Definition Sequence:83
void setNumRepeats(int nreps)
Definition Sequence:141
void setLastFrameTime(double t)
Definition Sequence:90
float getSpeed() const
Definition Sequence:138
META_Node(osg, Sequence)
int getNumRepeats() const
Definition Sequence:144
int _getNextValue(void)
void getInterval(LoopMode &mode, int &begin, int &end) const
Definition Sequence:127
bool getClearOnStop() const
Definition Sequence:182
void setClearOnStop(bool clearOnStop)
Definition Sequence:179
bool _clearOnStop
Definition Sequence:254
double _now
Definition Sequence:198
void setDuration(float speed, int nreps=-1)
bool _sync
Definition Sequence:251
unsigned int getNumFrames() const
Definition Sequence:96
const std::vector< double > & getTimeList() const
Definition Sequence:79
double getTime(unsigned int frame) const
virtual bool removeChild(Node *child)
int getEnd() const
Definition Sequence:121
SequenceMode _mode
Definition Sequence:248
int _step
Definition Sequence:233
void setMode(SequenceMode mode)
virtual bool insertChild(unsigned int index, Node *child, double t)
double _totalTime
Definition Sequence:207
void setInterval(LoopMode mode, int begin, int end)
void setEnd(int end)
Definition Sequence:118
double _saveRealLastFrameTime
Definition Sequence:244
unsigned int _saveRealLastFrameValue
Definition Sequence:245
double _lastFrameTime
Definition Sequence:241
void setTimeList(const std::vector< double > &timeList)
Definition Sequence:76
void setBegin(int begin)
Definition Sequence:112
int getBegin() const
Definition Sequence:115
LoopMode
Definition Sequence:100
@ LOOP
Definition Sequence:101
int getValue() const
Definition Sequence:67
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
#define OSG_EXPORT
Definition osg/Export:39