AnimationManagerBase 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_MANAGER_BASE
  15. #define OSGANIMATION_ANIMATION_MANAGER_BASE 1
  16. #include <osgAnimation/LinkVisitor>
  17. #include <osgAnimation/Animation>
  18. #include <osgAnimation/Export>
  19. #include <osg/FrameStamp>
  20. #include <osg/Group>
  21. namespace osgAnimation
  22. {
  23. class OSGANIMATION_EXPORT AnimationManagerBase : public osg::NodeCallback
  24. {
  25. public:
  26. typedef std::set<osg::ref_ptr<Target> > TargetSet;
  27. AnimationManagerBase();
  28. AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY);
  29. virtual ~AnimationManagerBase();
  30. virtual void buildTargetReference();
  31. virtual void registerAnimation (Animation*);
  32. virtual void unregisterAnimation (Animation*);
  33. virtual void link(osg::Node* subgraph);
  34. virtual void update(double t) = 0;
  35. virtual bool needToLink() const;
  36. const AnimationList& getAnimationList() const { return _animations;}
  37. AnimationList& getAnimationList() { return _animations;}
  38. //uniformisation of the API
  39. inline Animation * getRegisteredAnimation(unsigned int i) { return _animations[i].get();}
  40. inline unsigned int getNumRegisteredAnimations() const { return _animations.size();}
  41. inline void addRegisteredAnimation(Animation* animation)
  42. {
  43. _needToLink = true;
  44. _animations.push_back(animation);
  45. buildTargetReference();
  46. }
  47. void removeRegisteredAnimation(Animation* animation);
  48. /** Callback method called by the NodeVisitor when visiting a node.*/
  49. virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
  50. /** Reset the value of targets
  51. this Operation must be done each frame */
  52. void clearTargets();
  53. LinkVisitor* getOrCreateLinkVisitor();
  54. void setLinkVisitor(LinkVisitor*);
  55. /// set a flag to define the behaviour
  56. void setAutomaticLink(bool);
  57. bool getAutomaticLink() const;
  58. bool isAutomaticLink() const { return getAutomaticLink(); }
  59. void dirty();
  60. protected:
  61. osg::ref_ptr<LinkVisitor> _linker;
  62. AnimationList _animations;
  63. TargetSet _targets;
  64. bool _needToLink;
  65. bool _automaticLink;
  66. };
  67. }
  68. #endif