Animation 3.1 KB

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