diff --git a/Make/makedirdefs b/Make/makedirdefs index e4887a4ec..004c3e1d9 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -144,6 +144,7 @@ EXAMPLE_DIRS = \ osgforest\ osgimpostor\ osgkeyboard\ + osgkeyboardmouse\ osglight\ osglightpoint\ osglogo\ @@ -162,6 +163,7 @@ EXAMPLE_DIRS = \ osgscalarbar\ osgspheresegment\ osgsimulation\ + osgsimple\ osgshaders\ osgshadowtexture\ osgshape\ diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index 000b7ba37..68c1ef910 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -213,6 +213,8 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac /** reimplement CullStack's popProjectionMatrix() adding clamping of the projection matrix to the computed near and far.*/ virtual void popProjectionMatrix(); + + bool clampProjectionMatrix(osg::Matrix& projection, value_type& znear, value_type& zfar) const; void setState(osg::State* state) { _state = state; } osg::State* getState() { return _state.get(); } diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 8871070f6..4f76e0ea6 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -180,27 +180,37 @@ void CullVisitor::popProjectionMatrix() // so it doesn't cull them out. osg::Matrix& projection = *_projectionStack.back(); + clampProjectionMatrix(projection, _computed_znear, _computed_zfar); + } + + CullStack::popProjectionMatrix(); +} + +bool CullVisitor::clampProjectionMatrix(osg::Matrix& projection, value_type& znear, value_type& zfar) const +{ + if (zfar>0.0f) + { + if (projection(0,3)==0.0f && projection(1,3)==0.0f && projection(2,3)==0.0f) { //std::cout << "Orthographic projection "<setTraversalMask(_cullMaskLeft); cullStage(computeLeftEyeProjection(_projectionMatrix),computeLeftEyeView(_viewMatrix),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); + if (_cullVisitor->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) + { + CullVisitor::value_type zNear = _cullVisitor->getCalculatedNearPlane(); + CullVisitor::value_type zFar = _cullVisitor->getCalculatedFarPlane(); + _cullVisitor->clampProjectionMatrix(_projectionMatrix,zNear,zFar); + } + } else if (_displaySettings->getStereoMode()==osg::DisplaySettings::RIGHT_EYE) { // set up the right eye. _cullVisitor->setTraversalMask(_cullMaskRight); cullStage(computeRightEyeProjection(_projectionMatrix),computeRightEyeView(_viewMatrix),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); + + if (_cullVisitor->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) + { + CullVisitor::value_type zNear = _cullVisitor->getCalculatedNearPlane(); + CullVisitor::value_type zFar = _cullVisitor->getCalculatedFarPlane(); + _cullVisitor->clampProjectionMatrix(_projectionMatrix,zNear,zFar); + } + } else { @@ -407,8 +422,6 @@ void SceneView::cull() if (!_rendergraphRight.valid()) _rendergraphRight = dynamic_cast(_rendergraph->cloneType()); if (!_renderStageRight.valid()) _renderStageRight = dynamic_cast(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL)); - - _cullVisitorLeft->setDatabaseRequestHandler(_cullVisitor->getDatabaseRequestHandler()); _cullVisitorLeft->setTraversalMask(_cullMaskLeft); cullStage(computeLeftEyeProjection(_projectionMatrix),computeLeftEyeView(_viewMatrix),_cullVisitorLeft.get(),_rendergraphLeft.get(),_renderStageLeft.get()); @@ -419,6 +432,14 @@ void SceneView::cull() _cullVisitorRight->setTraversalMask(_cullMaskRight); cullStage(computeRightEyeProjection(_projectionMatrix),computeRightEyeView(_viewMatrix),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get()); + if (_cullVisitorLeft->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR && + _cullVisitorRight->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) + { + CullVisitor::value_type zNear = osg::minimum(_cullVisitorLeft->getCalculatedNearPlane(),_cullVisitorRight->getCalculatedNearPlane()); + CullVisitor::value_type zFar = osg::maximum(_cullVisitorLeft->getCalculatedFarPlane(),_cullVisitorRight->getCalculatedFarPlane()); + _cullVisitor->clampProjectionMatrix(_projectionMatrix,zNear,zFar); + } + } } @@ -428,6 +449,12 @@ void SceneView::cull() _cullVisitor->setTraversalMask(_cullMask); cullStage(_projectionMatrix,_viewMatrix,_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); + if (_cullVisitor->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) + { + CullVisitor::value_type zNear = _cullVisitor->getCalculatedNearPlane(); + CullVisitor::value_type zFar = _cullVisitor->getCalculatedFarPlane(); + _cullVisitor->clampProjectionMatrix(_projectionMatrix,zNear,zFar); + } }