InsertImpostorsVisitor 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifndef OSGSIM_INSERTIMPOSTORSVISITOR
  14. #define OSGSIM_INSERTIMPOSTORSVISITOR
  15. #include <osg/NodeVisitor>
  16. #include <osgSim/Impostor>
  17. namespace osgSim {
  18. /** Insert impostor nodes into scene graph.
  19. * For example of usage see examples/osgimpostor.
  20. */
  21. class OSGSIM_EXPORT InsertImpostorsVisitor : public osg::NodeVisitor
  22. {
  23. public:
  24. /** Default to traversing all children. */
  25. InsertImpostorsVisitor();
  26. META_NodeVisitor(osgSim, InsertImpostorsVisitor)
  27. void setImpostorThresholdRatio(float ratio) { _impostorThresholdRatio = ratio; }
  28. float getImpostorThresholdRatio() const { return _impostorThresholdRatio; }
  29. void setMaximumNumberOfNestedImpostors(unsigned int num) { _maximumNumNestedImpostors = num; }
  30. unsigned int getMaximumNumberOfNestedImpostors() const { return _maximumNumNestedImpostors; }
  31. /** Empty visitor, make it ready for next traversal. */
  32. void reset();
  33. virtual void apply(osg::Node& node);
  34. virtual void apply(osg::Group& node);
  35. virtual void apply(osg::LOD& node);
  36. /* Insert the required impostors into the scene graph. */
  37. void insertImpostors();
  38. protected:
  39. typedef std::vector< osg::Group* > GroupList;
  40. typedef std::vector< osg::LOD* > LODList;
  41. GroupList _groupList;
  42. LODList _lodList;
  43. float _impostorThresholdRatio;
  44. unsigned int _maximumNumNestedImpostors;
  45. unsigned int _numNestedImpostors;
  46. };
  47. }
  48. #endif