ClipNode 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 OSG_CLIPNODE
  14. #define OSG_CLIPNODE 1
  15. #include <osg/Group>
  16. #include <osg/ClipPlane>
  17. namespace osg {
  18. /** Node for defining the position of ClipPlanes in the scene.*/
  19. class OSG_EXPORT ClipNode : public Group
  20. {
  21. public:
  22. typedef std::vector<ref_ptr<ClipPlane> > ClipPlaneList;
  23. ClipNode();
  24. ClipNode(const ClipNode& es, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  25. META_Node(osg, ClipNode);
  26. enum ReferenceFrame
  27. {
  28. RELATIVE_RF,
  29. ABSOLUTE_RF
  30. };
  31. /** Set the ClipNode's ReferenceFrame, either to be relative to its
  32. * parent reference frame, or relative to an absolute coordinate
  33. * frame. RELATIVE_RF is the default.
  34. * Note: setting the ReferenceFrame to be ABSOLUTE_RF will
  35. * also set the CullingActive flag to false on the ClipNode (and
  36. * consequently all of its parents), thereby disabling culling of it and
  37. * all its parents. This is necessary to prevent inappropriate
  38. * culling, but may impact cull times if the absolute ClipNode is
  39. * deep in the scene graph. It is therefore recommended to only use
  40. * absolute ClipNode at the top of the scene.
  41. */
  42. void setReferenceFrame(ReferenceFrame rf);
  43. ReferenceFrame getReferenceFrame() const { return _referenceFrame; }
  44. /** Creates six clip planes corresponding to the given BoundingBox. */
  45. void createClipBox(const BoundingBox& bb,unsigned int clipPlaneNumberBase=0);
  46. /** Adds the clipplane. Returns true on success, and false if the plane
  47. * has already been added, or if clipplane is NULL. */
  48. bool addClipPlane(ClipPlane* clipplane);
  49. /** Removes the clipplane. Returns true on success, false if clipplane
  50. * isn't in this ClipNode.*/
  51. bool removeClipPlane(ClipPlane* clipplane);
  52. /** Remove the ClipPlane with the given index. Returns true on success,
  53. * false if pos is not a valid plane index. */
  54. bool removeClipPlane(unsigned int pos);
  55. /** Returns the number of ClipPlanes. */
  56. inline unsigned int getNumClipPlanes() const { return _planes.size(); }
  57. /** Get ClipPlane at the given index position. */
  58. inline ClipPlane* getClipPlane(unsigned int pos) { return _planes[pos].get(); }
  59. /** Get const ClipPlane at the given index position. */
  60. inline const ClipPlane* getClipPlane(unsigned int pos) const { return _planes[pos].get(); }
  61. /** Set the ClipPlaneList. */
  62. inline void setClipPlaneList(const ClipPlaneList& cpl) { _planes=cpl; }
  63. /** Get the ClipPlaneList. */
  64. inline ClipPlaneList& getClipPlaneList() { return _planes; }
  65. /** Get the const ClipPlaneList. */
  66. inline const ClipPlaneList& getClipPlaneList() const { return _planes; }
  67. /** Set the GLModes for all ClipPlanes, on the StateSet. */
  68. void setStateSetModes(StateSet&,StateAttribute::GLModeValue) const;
  69. /** Set up the local StateSet. */
  70. void setLocalStateSetModes(StateAttribute::GLModeValue=StateAttribute::ON);
  71. virtual BoundingSphere computeBound() const;
  72. protected:
  73. virtual ~ClipNode();
  74. StateAttribute::GLModeValue _value;
  75. ClipPlaneList _planes;
  76. ReferenceFrame _referenceFrame;
  77. };
  78. }
  79. #endif