From 1e0af3590094905a59a7a5cf172e375e4a908729 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 15 May 2007 17:04:57 +0000 Subject: [PATCH] Added code to better compute the view frustum that is appropriate for a traversed subgraph. --- include/osgUtil/CullVisitor | 5 +++ src/osgSim/OverlayNode.cpp | 76 +++++++++++++++++++++++++++++++++++-- src/osgUtil/CullVisitor.cpp | 14 +++++-- 3 files changed, 88 insertions(+), 7 deletions(-) diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index a51951d6f..cf1c4eb67 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -188,6 +188,11 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac /** Add an attribute which is positioned relative to the modelview matrix.*/ inline void addPositionedTextureAttribute(unsigned int textureUnit, osg::RefMatrix* matrix,const osg::StateAttribute* attr); + + /** compute near plane based on the polgon intersection of primtives in near plane candidate list of drawables. + * Note, you have to set ComputeNearFarMode to COMPUTE_NEAR_FAR_USING_PRIMITIVES to be able to near plane candidate drawables to be recorded by the cull traversal. */ + void computeNearPlane(); + /** Re-implement CullStack's popProjectionMatrix() adding clamping of the projection matrix to * the computed near and far.*/ virtual void popProjectionMatrix(); diff --git a/src/osgSim/OverlayNode.cpp b/src/osgSim/OverlayNode.cpp index e8990626e..194025310 100644 --- a/src/osgSim/OverlayNode.cpp +++ b/src/osgSim/OverlayNode.cpp @@ -11,6 +11,7 @@ * OpenSceneGraph Public License for more details. */ +#include #include #include #include @@ -337,7 +338,7 @@ void OverlayNode::traverse_OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeV void OverlayNode::traverse_VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeVisitor& nv) { - osg::notify(osg::NOTICE)<<"OverlayNode::traverse() - VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY"<accept(cbbv); + + Group::traverse(nv); - osg::notify(osg::NOTICE)<<" "<<&overlayData<getProjectionMatrix()); + + osgUtil::CullVisitor::value_type znear = cv->getCalculatedNearPlane(); + osgUtil::CullVisitor::value_type zfar = cv->getCalculatedFarPlane(); + + // osg::notify(osg::NOTICE)<<" before znear ="<tick(); + osg::Timer_t start_t = osg::Timer::instance()->tick(); // update near from defferred list of drawables unsigned int numTests = 0; @@ -197,9 +196,16 @@ void CullVisitor::popProjectionMatrix() } } - // osg::Timer_t end_t = osg::Timer::instance()->tick(); + osg::Timer_t end_t = osg::Timer::instance()->tick(); // osg::notify(osg::NOTICE)<<"Took "<delta_m(start_t,end_t)<<"ms to test "<=_computed_znear) {