Added support for cullable state, that uses a polytope to define the extents
of objects that will be influenced by it.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osgUtil/CullVisitor>
|
||||
#include <osgSim/OverlayNode>
|
||||
@@ -116,10 +117,6 @@ void OverlayNode::traverse(osg::NodeVisitor& nv)
|
||||
|
||||
if (bs.valid())
|
||||
{
|
||||
// update the bounding volume for later testing
|
||||
// whether the overlay can be seen or not.
|
||||
_overlaySubgraphBound = bs;
|
||||
|
||||
// see if we are within a coordinate system node.
|
||||
osg::CoordinateSystemNode* csn = 0;
|
||||
osg::NodePath& nodePath = nv.getNodePath();
|
||||
@@ -171,8 +168,10 @@ void OverlayNode::traverse(osg::NodeVisitor& nv)
|
||||
|
||||
// compute the matrix which takes a vertex from local coords into tex coords
|
||||
// will use this later to specify osg::TexGen..
|
||||
osg::Matrix MVPT = _camera->getViewMatrix() *
|
||||
_camera->getProjectionMatrix() *
|
||||
osg::Matrix MVP = _camera->getViewMatrix() *
|
||||
_camera->getProjectionMatrix();
|
||||
|
||||
osg::Matrix MVPT = MVP *
|
||||
osg::Matrix::translate(1.0,1.0,1.0) *
|
||||
osg::Matrix::scale(0.5,0.5,0.5);
|
||||
|
||||
@@ -180,6 +179,11 @@ void OverlayNode::traverse(osg::NodeVisitor& nv)
|
||||
_texgenNode->getTexGen()->setPlanesFromMatrix(MVPT);
|
||||
|
||||
|
||||
_textureFrustum.setToUnitFrustum(false,false);
|
||||
// const osg::Matrix modelView = (cv->getModelViewMatrix());
|
||||
// _textureFrustum.transformProvidingInverse(osg::Matrix::inverse(modelView)*MVP);
|
||||
_textureFrustum.transformProvidingInverse(MVP);
|
||||
|
||||
_camera->accept(*cv);
|
||||
|
||||
_textureObjectValidList[contextID] = 1;
|
||||
@@ -202,14 +206,28 @@ void OverlayNode::traverse(osg::NodeVisitor& nv)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
|
||||
_texgenNode->accept(*cv);
|
||||
|
||||
osg::CullingSet& pcs = cv->getProjectionCullingStack().back();
|
||||
osg::CullingSet& ccs = cv->getCurrentCullingSet();
|
||||
|
||||
const osg::Matrix modelView = (cv->getModelViewMatrix());
|
||||
osg::Polytope viewTextureFrustum;
|
||||
viewTextureFrustum.setAndTransformProvidingInverse(_textureFrustum, osg::Matrix::inverse(modelView));
|
||||
|
||||
pcs.addStateFrustum(_mainSubgraphStateSet.get(), viewTextureFrustum);
|
||||
ccs.addStateFrustum(_mainSubgraphStateSet.get(), _textureFrustum);
|
||||
|
||||
// push the stateset.
|
||||
cv->pushStateSet(_mainSubgraphStateSet.get());
|
||||
// cv->pushStateSet(_mainSubgraphStateSet.get());
|
||||
|
||||
Group::traverse(nv);
|
||||
|
||||
cv->popStateSet();
|
||||
// cv->popStateSet();
|
||||
|
||||
ccs.getStateFrustumList().pop_back();
|
||||
pcs.getStateFrustumList().pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <osg/LineSegment>
|
||||
#include <osg/TriangleFunctor>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osgUtil/CullVisitor>
|
||||
|
||||
@@ -745,14 +746,40 @@ void CullVisitor::apply(Geode& node)
|
||||
if (!updateCalculatedNearFar(matrix,*drawable,false)) continue;
|
||||
}
|
||||
|
||||
// need to track how push/pops there are, so we can unravel the stack correctly.
|
||||
unsigned int numPopStateSetRequired = 0;
|
||||
|
||||
// push the geoset's state on the geostate stack.
|
||||
StateSet* stateset = drawable->getStateSet();
|
||||
if (stateset) pushStateSet(stateset);
|
||||
if (stateset)
|
||||
{
|
||||
++numPopStateSetRequired;
|
||||
pushStateSet(stateset);
|
||||
}
|
||||
|
||||
CullingSet& cs = getCurrentCullingSet();
|
||||
if (!cs.getStateFrustumList().empty())
|
||||
{
|
||||
osg::CullingSet::StateFrustumList& sfl = cs.getStateFrustumList();
|
||||
for(osg::CullingSet::StateFrustumList::iterator itr = sfl.begin();
|
||||
itr != sfl.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->second.contains(bb))
|
||||
{
|
||||
++numPopStateSetRequired;
|
||||
pushStateSet(itr->first.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bb.valid()) addDrawableAndDepth(drawable,&matrix,distance(bb.center(),matrix));
|
||||
else addDrawableAndDepth(drawable,&matrix,0.0f);
|
||||
|
||||
if (stateset) popStateSet();
|
||||
for(unsigned int i=0;i< numPopStateSetRequired; ++i)
|
||||
{
|
||||
popStateSet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user