openscenegraph
Animation
Go to the documentation of this file.
1/* -*-c++-*-
2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
3 *
4 * This library is open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version. The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * OpenSceneGraph Public License for more details.
13*/
14
15#ifndef OSGANIMATION_ANIMATION
16#define OSGANIMATION_ANIMATION 1
17
18#include <osg/Object>
19#include <osgAnimation/Export>
20#include <osgAnimation/Channel>
21#include <osg/ref_ptr>
22#include <vector>
23#include <map>
24
25namespace osgAnimation
26{
27
28 class OSGANIMATION_EXPORT Animation : public osg::Object
29 {
30 public:
31 META_Object(osgAnimation, Animation)
32
33 Animation() :
34 _duration(0.0), _originalDuration(0.0),
35 _weight(0), _startTime(0), _playmode(LOOP) {}
36
37 Animation(const osgAnimation::Animation&, const osg::CopyOp&);
38
39 enum PlayMode
40 {
41 ONCE,
42 STAY,
43 LOOP,
44 PPONG
45 };
46
47 // addChannel insert the channel and call the computeDuration function
48 void addChannel (Channel* pChannel);
49
50 // removeChannel remove the channel from channels list and call the computeDuration function
51 void removeChannel (Channel* pChannel);
52
53 /** Those accessors let you add and remove channels
54 * if you modify something that can change the duration
55 * you are supposed to call computeDuration or setDuration
56 */
57 ChannelList& getChannels();
58 const ChannelList& getChannels() const;
59
60 /** Change the duration of animation
61 * then evaluate the animation in the range 0-duration
62 * it stretch the animation in time.
63 * see computeDuration too
64 */
65 void setDuration(double duration);
66
67 /** Compute duration from channel and keyframes
68 * if the duration is not specified you should
69 * call this method before using it
70 */
71 void computeDuration();
72 double getDuration() const;
73 double computeDurationFromChannels() const;
74
75 void setWeight (float weight);
76 float getWeight() const;
77
78 bool update (double time, int priority = 0);
79 void resetTargets();
80
81 void setPlayMode (PlayMode mode) { _playmode = mode; }
82 PlayMode getPlayMode() const { return _playmode; }
83
84 void setStartTime(double time) { _startTime = time;}
85 double getStartTime() const { return _startTime;}
86
87 protected:
88
89 ~Animation() {}
90
91 double _duration;
92 double _originalDuration;
93 float _weight;
94 double _startTime;
95 PlayMode _playmode;
96 ChannelList _channels;
97
98 };
99
100 typedef std::vector<osg::ref_ptr<osgAnimation::Animation> > AnimationList;
101 typedef std::map<std::string, osg::ref_ptr<osgAnimation::Animation> > AnimationMap;
102
103
104}
105
106#endif