root/OpenSceneGraph/trunk/src/osg/ClipPlane.cpp @ 13041

Revision 13041, 2.3 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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#include <osg/ClipPlane>
14#include <osg/StateSet>
15#include <osg/Notify>
16
17using namespace osg;
18
19ClipPlane::ClipPlane()
20{
21    _clipPlane.set(0.0,0.0,0.0,0.0);
22    _clipPlaneNum = 0;
23}
24
25
26ClipPlane::~ClipPlane()
27{
28}
29
30void ClipPlane::setClipPlaneNum(unsigned int num)
31{
32    if (_clipPlaneNum==num) return;
33
34    if (_parents.empty())
35    {
36        _clipPlaneNum = num;
37        return;
38    }
39
40    // take a reference to this clip plane to prevent it from going out of scope
41    // when we remove it temporarily from its parents.
42    osg::ref_ptr<ClipPlane> clipPlaneRef = this;
43
44    // copy the parents as they _parents list will be changed by the subsequent removeAttributes.
45    ParentList parents = _parents;
46
47    // remove this attribute from its parents as its position is being changed
48    // and would no longer be valid.
49    ParentList::iterator itr;
50    for(itr = parents.begin();
51        itr != parents.end();
52        ++itr)
53    {
54        osg::StateSet* stateset = *itr;
55        stateset->removeAttribute(this);
56    }
57
58    // assign the clip plane number
59    _clipPlaneNum = num;
60
61    // add this attribute back into its original parents with its new position
62    for(itr = parents.begin();
63        itr != parents.end();
64        ++itr)
65    {
66        osg::StateSet* stateset = *itr;
67        stateset->setAttribute(this);
68    }
69}
70
71unsigned int ClipPlane::getClipPlaneNum() const
72{
73    return _clipPlaneNum;
74}
75
76void ClipPlane::apply(State&) const
77{
78#if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE) && !defined(OSG_GLES1_AVAILABLE)
79    glClipPlane((GLenum)(GL_CLIP_PLANE0+_clipPlaneNum),_clipPlane.ptr());
80#else
81    OSG_NOTICE<<"Warning: ClipPlane::apply(State&) - not supported."<<std::endl;
82#endif
83}
Note: See TracBrowser for help on using the browser.