OpenSceneGraph/src/osg/CollectOccludersVisitor.cpp

127 lines
2.7 KiB
C++
Raw Normal View History

#include <osg/CollectOccludersVisitor>
#include <osg/Transform>
#include <osg/Switch>
#include <osg/LOD>
#include <osg/OccluderNode>
#include <osg/Projection>
using namespace osg;
CollectOccludersVisitor::CollectOccludersVisitor()
{
// overide the default node visitor mode.
setTraversalMode(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
}
CollectOccludersVisitor::~CollectOccludersVisitor()
{
}
void CollectOccludersVisitor::reset()
{
CullStack::reset();
}
void CollectOccludersVisitor::apply(osg::Node& node)
{
if (isCulled(node)) return;
// push the culling mode.
pushCurrentMask();
traverse(node);
// pop the culling mode.
popCurrentMask();
}
void CollectOccludersVisitor::apply(osg::Transform& node)
{
if (isCulled(node)) return;
// push the culling mode.
pushCurrentMask();
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(getModelViewMatrix());
node.getLocalToWorldMatrix(*matrix,this);
pushModelViewMatrix(matrix.get());
traverse(node);
popModelViewMatrix();
// pop the culling mode.
popCurrentMask();
}
void CollectOccludersVisitor::apply(osg::Projection& node)
{
if (isCulled(node)) return;
// push the culling mode.
pushCurrentMask();
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(node.getMatrix());
pushProjectionMatrix(matrix.get());
traverse(node);
popProjectionMatrix();
// pop the culling mode.
popCurrentMask();
}
void CollectOccludersVisitor::apply(osg::Switch& node)
{
apply((Group&)node);
}
void CollectOccludersVisitor::apply(osg::LOD& node)
{
if (isCulled(node)) return;
int eval = node.evaluate(getEyeLocal(),_LODBias);
if (eval<0) return;
// push the culling mode.
pushCurrentMask();
//notify(INFO) << "selecting child "<<eval<< std::endl;
node.getChild(eval)->accept(*this);
// pop the culling mode.
popCurrentMask();
}
void CollectOccludersVisitor::apply(osg::OccluderNode& node)
{
// need to check if occlusion node is in the occluder
// list, if so disable the appropriate ShadowOccluderVolume
disableOccluder(_nodePath);
if (isCulled(node)) return;
2002-06-12 17:22:30 +08:00
std::cout<<"CollectOccludersVisitor:: We have found an Occlusion node in frustum"<<&node<<std::endl;
// push the culling mode.
pushCurrentMask();
2002-06-12 17:22:30 +08:00
if (node.getOccluder()&& !isCulled(node.getOccluder()->getOccluder().getVertexList()))
{
// need to test occluder against view frustum.
std::cout << " adding in Occluder"<<std::endl;
_occluderList.push_back(ShadowVolumeOccluder(_nodePath, *node.getOccluder(), getModelViewMatrix(),getProjectionMatrix()));
2002-06-12 17:22:30 +08:00
}
traverse(node);
// pop the culling mode.
popCurrentMask();
}