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

Revision 13041, 3.7 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/CullingSet>
14
15using namespace osg;
16
17CullingSet::CullingSet()
18{
19    _mask = ENABLE_ALL_CULLING;
20    _pixelSizeVector.set(0,0,0,1);
21    _smallFeatureCullingPixelSize=2.0f;
22}
23
24CullingSet::~CullingSet()
25{
26}
27
28void CullingSet::disableAndPushOccludersCurrentMask(NodePath& nodePath)
29{
30    for(OccluderList::iterator itr=_occluderList.begin();
31        itr!=_occluderList.end();
32        ++itr)
33    {
34        //std::cout<<"    checking against ";PrintNodePath(itr->getNodePath());std::cout<<std::endl;
35        if (itr->getNodePath()==nodePath)
36        {
37            //std::cout<<"  ++ disabling occluder "<<itr<<std::endl;
38            // we have trapped for the case an occlude potentially occluding itself,
39            // to prevent this we disable the results mask so that no subsequnt
40            // when the next pushCurrentMask calls happens this occluder is switched off.
41            itr->disableResultMasks();
42            itr->pushCurrentMask();
43        }
44    }
45}
46
47
48void CullingSet::popOccludersCurrentMask(NodePath& nodePath)
49{
50    //std::cout<<"  trying to pop occluder ";PrintNodePath(nodePath);std::cout<<std::endl;
51    for(OccluderList::iterator itr=_occluderList.begin();
52        itr!=_occluderList.end();
53        ++itr)
54    {
55        //std::cout<<"    checking against ";PrintNodePath(itr->getNodePath());std::cout<<std::endl;
56        if (itr->getNodePath()==nodePath)
57        {
58            //std::cout<<"  popping occluder "<<itr<<std::endl;
59            // we have trapped for the case an occlude potentially occluding itself,
60            // to prevent this we disable the results mask so that no subsequent
61            // when the next pushCurrentMask calls happens this occluder is switched off.
62            itr->popCurrentMask();
63        }
64    }
65}
66
67osg::Vec4 CullingSet::computePixelSizeVector(const Viewport& W, const Matrix& P, const Matrix& M)
68{
69    // pre adjust P00,P20,P23,P33 by multiplying them by the viewport window matrix.
70    // here we do it in short hand with the knowledge of how the window matrix is formed
71    // note P23,P33 are multiplied by an implicit 1 which would come from the window matrix.
72    // Robert Osfield, June 2002.
73
74    // scaling for horizontal pixels
75    float P00 = P(0,0)*W.width()*0.5f;
76    float P20_00 = P(2,0)*W.width()*0.5f + P(2,3)*W.width()*0.5f;
77    osg::Vec3 scale_00(M(0,0)*P00 + M(0,2)*P20_00,
78                       M(1,0)*P00 + M(1,2)*P20_00,
79                       M(2,0)*P00 + M(2,2)*P20_00);
80
81    // scaling for vertical pixels
82    float P10 = P(1,1)*W.height()*0.5f;
83    float P20_10 = P(2,1)*W.height()*0.5f + P(2,3)*W.height()*0.5f;
84    osg::Vec3 scale_10(M(0,1)*P10 + M(0,2)*P20_10,
85                       M(1,1)*P10 + M(1,2)*P20_10,
86                       M(2,1)*P10 + M(2,2)*P20_10);
87
88    float P23 = P(2,3);
89    float P33 = P(3,3);
90    osg::Vec4 pixelSizeVector(M(0,2)*P23,
91                              M(1,2)*P23,
92                              M(2,2)*P23,
93                              M(3,2)*P23 + M(3,3)*P33);
94
95    float scaleRatio  = 0.7071067811f/sqrtf(scale_00.length2()+scale_10.length2());
96    pixelSizeVector *= scaleRatio;
97
98    return pixelSizeVector;
99}
Note: See TracBrowser for help on using the browser.