| 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 | |
|---|
| 25 | namespace osgAnimation |
|---|
| 26 | { |
|---|
| 27 | |
|---|
| 28 | class OSGANIMATION_EXPORT Animation : public osg::Object |
|---|
| 29 | { |
|---|
| 30 | public: |
|---|
| 31 | META_Object(osgAnimation, Animation) |
|---|
| 32 | |
|---|
| 33 | Animation() : _duration(0), _weight(0), _startTime(0), _playmode(LOOP) {} |
|---|
| 34 | Animation(const osgAnimation::Animation&, const osg::CopyOp&); |
|---|
| 35 | |
|---|
| 36 | enum PlayMode |
|---|
| 37 | { |
|---|
| 38 | ONCE, |
|---|
| 39 | STAY, |
|---|
| 40 | LOOP, |
|---|
| 41 | PPONG |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | // addChannel insert the channel and call the computeDuration function |
|---|
| 45 | void addChannel (Channel* pChannel); |
|---|
| 46 | |
|---|
| 47 | /** Those accessors let you add and remove channels |
|---|
| 48 | * if you modify something that can change the duration |
|---|
| 49 | * you are supposed to call computeDuration or setDuration |
|---|
| 50 | */ |
|---|
| 51 | ChannelList& getChannels(); |
|---|
| 52 | const ChannelList& getChannels() const; |
|---|
| 53 | |
|---|
| 54 | /** Change the duration of animation |
|---|
| 55 | * then evaluate the animation in the range 0-duration |
|---|
| 56 | * it stretch the animation in time. |
|---|
| 57 | * see computeDuration too |
|---|
| 58 | */ |
|---|
| 59 | void setDuration(double duration); |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | /** Compute duration from channel and keyframes |
|---|
| 63 | * if the duration is not specified you should |
|---|
| 64 | * call this method before using it |
|---|
| 65 | */ |
|---|
| 66 | void computeDuration(); |
|---|
| 67 | |
|---|
| 68 | double getDuration() const; |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | void setWeight (float weight); |
|---|
| 72 | float getWeight() const; |
|---|
| 73 | |
|---|
| 74 | bool update (double time, int priority = 0); |
|---|
| 75 | void resetTargets(); |
|---|
| 76 | |
|---|
| 77 | void setPlayMode (PlayMode mode) { _playmode = mode; } |
|---|
| 78 | PlayMode getPlayMode() const { return _playmode; } |
|---|
| 79 | |
|---|
| 80 | void setStartTime(double time) { _startTime = time;} |
|---|
| 81 | double getStartTime() const { return _startTime;} |
|---|
| 82 | |
|---|
| 83 | protected: |
|---|
| 84 | |
|---|
| 85 | double computeDurationFromChannels() const; |
|---|
| 86 | |
|---|
| 87 | ~Animation() {} |
|---|
| 88 | |
|---|
| 89 | double _duration; |
|---|
| 90 | double _originalDuration; |
|---|
| 91 | float _weight; |
|---|
| 92 | double _startTime; |
|---|
| 93 | PlayMode _playmode; |
|---|
| 94 | ChannelList _channels; |
|---|
| 95 | |
|---|
| 96 | }; |
|---|
| 97 | |
|---|
| 98 | typedef std::vector<osg::ref_ptr<osgAnimation::Animation> > AnimationList; |
|---|
| 99 | typedef std::map<std::string, osg::ref_ptr<osgAnimation::Animation> > AnimationMap; |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | #endif |
|---|