2002-06-10 21:50:25 +08:00
|
|
|
#include <osg/CollectOccludersVisitor>
|
2002-06-12 03:52:55 +08:00
|
|
|
#include <osg/Transform>
|
|
|
|
#include <osg/Switch>
|
|
|
|
#include <osg/LOD>
|
|
|
|
#include <osg/OccluderNode>
|
|
|
|
#include <osg/Projection>
|
2002-06-10 21:50:25 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
CollectOccludersVisitor::CollectOccludersVisitor()
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
// overide the default node visitor mode.
|
|
|
|
setTraversalMode(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CollectOccludersVisitor::~CollectOccludersVisitor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::reset()
|
|
|
|
{
|
|
|
|
CullStack::reset();
|
|
|
|
}
|
|
|
|
|
2002-06-12 03:52:55 +08:00
|
|
|
void CollectOccludersVisitor::apply(osg::Node& node)
|
2002-06-10 21:50:25 +08:00
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
if (isCulled(node)) return;
|
|
|
|
|
|
|
|
// push the culling mode.
|
|
|
|
pushCurrentMask();
|
|
|
|
|
|
|
|
traverse(node);
|
|
|
|
|
|
|
|
// pop the culling mode.
|
|
|
|
popCurrentMask();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::Transform& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
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();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::Projection& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
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();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::Switch& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
apply((Group&)node);
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::LOD& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
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();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::OccluderNode& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
// 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;
|
|
|
|
|
2002-06-12 03:52:55 +08:00
|
|
|
// 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;
|
2002-06-12 21:54:14 +08:00
|
|
|
_occluderList.push_back(ShadowVolumeOccluder(_nodePath, *node.getOccluder(), getModelViewMatrix(),getProjectionMatrix()));
|
2002-06-12 17:22:30 +08:00
|
|
|
}
|
|
|
|
|
2002-06-12 03:52:55 +08:00
|
|
|
traverse(node);
|
|
|
|
|
|
|
|
// pop the culling mode.
|
|
|
|
popCurrentMask();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|