VisibilityGroup 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_VISIBILITYGROUP
  14. #define OSGSIM_VISIBILITYGROUP 1
  15. #include <osg/Node>
  16. #include <osg/Group>
  17. #include <osg/NodeVisitor>
  18. #include <osgSim/Export>
  19. namespace osgSim {
  20. /** VisibilityGroup renders (traverses) it's children only when the camera is inside a specified visibility volume.
  21. * The visibility volume is intersected with a line segment that extends from
  22. * the current camera's eye-point along the view vector for a given segment length.
  23. * If an intersection is detected then the node's children are traversed.
  24. */
  25. class OSGSIM_EXPORT VisibilityGroup : public osg::Group
  26. {
  27. public :
  28. VisibilityGroup();
  29. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  30. VisibilityGroup(const VisibilityGroup&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  31. META_Node(osgSim, VisibilityGroup);
  32. virtual void traverse(osg::NodeVisitor& nv);
  33. /** Set the subgraph that is intersected for the visibility determination.*/
  34. void setVisibilityVolume(osg::Node* node) { _visibilityVolume = node; }
  35. /** Get the subgraph that is intersected for the visibility determination.*/
  36. osg::Node* getVisibilityVolume() { return _visibilityVolume.get(); }
  37. /** Get the const subgraph that is intersected for the visibility determination.*/
  38. const osg::Node* getVisibilityVolume() const { return _visibilityVolume.get(); }
  39. /** Set the traversal mask for the intersection testing.*/
  40. void setVolumeIntersectionMask(osg::Node::NodeMask mask) { _volumeIntersectionMask = mask; }
  41. /** Get the traversal mask for the intersection testing.*/
  42. osg::Node::NodeMask getVolumeIntersectionMask() const { return _volumeIntersectionMask; }
  43. /** Set the length of the intersection segment.
  44. * The segments extends this many database units from the camera eye-point along the look vector.
  45. * If this is left at zero then the diameter of the bounding sphere of the visibility volume is used.*/
  46. void setSegmentLength(float length) { _segmentLength = length; }
  47. /** Get the length of the intersection segment.*/
  48. float getSegmentLength() const { return _segmentLength; }
  49. protected :
  50. virtual ~VisibilityGroup() {}
  51. osg::ref_ptr<osg::Node> _visibilityVolume;
  52. osg::Node::NodeMask _volumeIntersectionMask;
  53. float _segmentLength;
  54. };
  55. }
  56. #endif