root/OpenSceneGraph/trunk/include/osg/Sequence @ 13041

Revision 13041, 7.9 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
22/** Sequence is a Group node which allows automatic, time based
23switching between children.
24*/
25class OSG_EXPORT Sequence : public Group
26{
27    public :
28
29        Sequence();
30
31        /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
32        Sequence(const Sequence&, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
33
34        META_Node(osg, Sequence);
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
57        /** value is which child node is to be displayed */
58        void setValue(int value) { _value = value ; }
59        int getValue() const { return _value; }
60
61        /** Set time in seconds for child. */
62        void setTime(unsigned int frame, double t);
63
64        /** Get time for child. */
65        double getTime(unsigned int frame) const;
66
67        /** Set the time list for children. */
68        void setTimeList(const std::vector<double>& timeList) { _frameTime = timeList; }
69
70        /** Get the time list for children. */
71        const std::vector<double>& getTimeList() const { return _frameTime; }
72
73        /** Set default time in seconds for new child.
74            if t<0, t=0 */
75        void setDefaultTime(double t) {_defaultTime = (t<0.?0.:t);}
76
77        /** Get default time in seconds for new child. */
78        double getDefaultTime(void) const {return _defaultTime;};
79
80        /** Set time of last frame of last loop, in seconds.
81            if t<= 0, then ignored */
82        void setLastFrameTime(double t) {_lastFrameTime = (t<0.?0.:t);}
83
84        /** Get last frame time in seconds */
85        double getLastFrameTime(void) const {return _lastFrameTime;};
86
87        /** Get number of frames */
88        inline unsigned int getNumFrames() const { return _frameTime.size(); }
89
90        /** Interval modes. 'Loop' repeats frames 1-N; 'swing' repeats 1->N, (N-1)->1. */
91        enum LoopMode
92        {
93            LOOP,
94            SWING
95        };
96
97        /** Set sequence mode. */
98        void setLoopMode(LoopMode mode) { _loopMode = mode; _value = -1; }
99
100        /** Get sequence mode. */
101        LoopMode getLoopMode() const { return _loopMode; }
102
103        /** Set interval beginning. */
104        void setBegin(int begin) { _begin = begin; _value = -1; }
105
106        /** Get interval beginning. */
107        int getBegin() const { return _begin; }
108
109        /** Set interval ending. */
110        void setEnd(int end) { _end = end; _value = -1; }
111
112        /** Get interval ending. */
113        int getEnd() const { return _end; }
114
115        /** Set sequence mode & interval (range of children to be displayed). */
116        void setInterval(LoopMode mode, int begin, int end);
117
118        /** Get sequence mode & interval. */
119        inline void getInterval(LoopMode& mode, int& begin, int& end) const
120        {
121            mode = _loopMode;
122            begin = _begin;
123            end = _end;
124        }
125
126        /** Set speed. */
127        void setSpeed(float speed) { _speed = speed; }
128
129        /** Get speed. */
130        float getSpeed() const { return _speed; }
131
132        /** Set number of repeats. */
133        void setNumRepeats(int nreps) { _nreps = (nreps<0?-1:nreps); _nrepsRemain = _nreps; }
134
135        /** Get number of repeats. */
136        int getNumRepeats() const { return _nreps; }
137
138        /** Set duration: speed-up & number of repeats */
139        void setDuration(float speed, int nreps = -1);
140
141        /** Get duration & number of repeats. */
142        inline void getDuration(float& speed, int& nreps) const
143        {
144            speed = _speed;
145            nreps = _nreps;
146        }
147
148        /** Sequence modes. */
149        enum SequenceMode
150        {
151            START,
152            STOP,
153            PAUSE,
154            RESUME
155        };
156
157        /** Set sequence mode. Start/stop & pause/resume. */
158        void setMode(SequenceMode mode);
159
160        /** Get sequence mode. */
161        inline SequenceMode getMode() const { return _mode; }
162
163        /** If false (default), frames will not be sync'd to frameTime.  If
164            true, frames will be sync'd to frameTime. */
165        void setSync(bool sync) { _sync = sync; }
166
167        /** Get sync value */
168        bool getSync() const { return _sync; }
169
170        /** If true, show no child nodes after stopping */
171        void setClearOnStop(bool clearOnStop) { _clearOnStop = clearOnStop; }
172
173        /** Get whether to show no child nodes after stopping */
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
203        bool _resetTotalTime ;
204
205        // store "loop mde", either LOOP or SWING
206        // init to LOOP- set by setInterval
207        LoopMode _loopMode;
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
236        double _saveRealLastFrameTime ;
237        unsigned int _saveRealLastFrameValue ;
238
239        // the current mode
240        SequenceMode _mode;
241
242        // the current sync value
243        bool _sync ;
244
245        // the current clearOnStop value
246        bool _clearOnStop ;
247
248};
249
250}
251
252#endif
Note: See TracBrowser for help on using the browser.