Example #1
0
void
SilverLiningNode::traverse(osg::NodeVisitor& nv)
{
    if ( _SL->ready() )
    {
        if ( nv.getVisitorType() == nv.UPDATE_VISITOR )
        {
            _SL->updateLocation();
            _SL->getAtmosphere()->UpdateSkyAndClouds();
            _SL->updateLight();
            _skyDrawable->dirtyBound();
            _cloudsDrawable->dirtyBound();
        }
        else if ( nv.getVisitorType() == nv.CULL_VISITOR )
        {
            // TODO: make this multi-camera safe
            _SL->setCameraPosition( nv.getEyePoint() );
            osgUtil::CullVisitor* cv = Culling::asCullVisitor(nv);
            _SL->getAtmosphere()->SetCameraMatrix( cv->getModelViewMatrix()->ptr() );
            _SL->getAtmosphere()->SetProjectionMatrix( cv->getProjectionMatrix()->ptr() );
            _SL->getAtmosphere()->CullObjects();
        }
    }
    osgEarth::Util::EnvironmentNode::traverse( nv );
}
void
SilverLiningContextNode::traverse(osg::NodeVisitor& nv)
{
    if ( _SL && _SL->ready() )
    {
        if ( nv.getVisitorType() == nv.UPDATE_VISITOR )
        {
			int frameNumber = nv.getFrameStamp()->getFrameNumber();
            _skyDrawable->dirtyBound();

            if( _cloudsDrawable )
            {
                if ( _lastAltitude <= *_options.cloudsMaxAltitude() )
                {
                    if ( _cloudsDrawable->getNumParents() == 0 )
                        _geode->addDrawable( _cloudsDrawable.get() );

                    _cloudsDrawable->dirtyBound();
                }
                else
                {
                    if ( _cloudsDrawable->getNumParents() > 0 )
                        _geode->removeDrawable( _cloudsDrawable.get() );
                }
            }
        }

        else if ( nv.getVisitorType() == nv.CULL_VISITOR )
        {
			osgUtil::CullVisitor* cv = Culling::asCullVisitor(nv);
			osg::Camera* camera  = cv->getCurrentCamera();
			if ( camera )
			{
#ifndef SL_USE_CULL_MASK
				//Check if this is the target camera for this context
				if(getTargetCamera() == camera)
#endif
     			{
					// TODO: make this multi-camera safe
					_SL->setCameraPosition( nv.getEyePoint() );

					_lastAltitude = _SL->getSRS()->isGeographic() ?
						cv->getEyePoint().length() - _SL->getSRS()->getEllipsoid()->getRadiusEquator() :
					cv->getEyePoint().z();

					_SL->updateLocation();
					_SL->updateLight();
				}
			}
        }
    }

    if ( _geode.valid() )
    {
        _geode->accept(nv);
    }
}
Example #3
0
void TXPNode::updateEye(osg::NodeVisitor &nv)
{
    if (!_pageManager)
    {
        OSG_NOTICE << "TXPNode::updateEye() no pageManager created" << std::endl;
        return;
    }

    trpg2dPoint loc;
    loc.x = nv.getEyePoint().x() - _originX;
    loc.y = nv.getEyePoint().y() - _originY;

    if (_pageManager->SetLocation(loc))
    {
        trpgManagedTile *tile = NULL;

        while ((tile = _pageManager->GetNextUnload()))
        {
            int x, y, lod;
            tile->GetTileLoc(x, y, lod);
            if (lod == 0)
            {
                osg::Node *node = (osg::Node*)(tile->GetLocalData());
                _nodesToRemove.push_back(node);

                // OSG_NOTICE << "Tile unload: " << x << " " << y << " " << lod << std::endl;
            }

            _pageManager->AckUnload();
        }

        while ((tile = _pageManager->GetNextLoad()))
        {
            int x, y, lod;
            tile->GetTileLoc(x, y, lod);
            if (lod == 0)
            {
                osg::Node *node = addPagedLODTile(x, y);
                tile->SetLocalData(node);
                // OSG_NOTICE << "Tile load: " << x << " " << y << " " << lod << std::endl;
            }

            _pageManager->AckLoad();
        }
    }
}
Example #4
0
void Impostor::traverse(osg::NodeVisitor& nv)
{
    if (nv.getVisitorType() != osg::NodeVisitor::CULL_VISITOR)
    {
        LOD::traverse(nv);
        return;
    }

    osgUtil::CullVisitor* cv = nv.asCullVisitor();
    if (!cv)
    {
        LOD::traverse(nv);
        return;
    }


    osg::Vec3 eyeLocal = nv.getEyePoint();
    const BoundingSphere& bs = getBound();

    unsigned int contextID = cv->getState() ? cv->getState()->getContextID() : 0;

    float distance2 = (eyeLocal-bs.center()).length2();
    float LODScale = cv->getLODScale();
    if (!cv->getImpostorsActive() ||
        distance2*LODScale*LODScale<osg::square(getImpostorThreshold()) ||
        distance2<bs.radius2()*2.0f)
    {
        // outwith the impostor distance threshold therefore simple
        // traverse the appropriate child of the LOD.
        LOD::traverse(nv);
    }
    else
    {

        // within the impostor distance threshold therefore attempt
        // to use impostor instead.

        RefMatrix& matrix = *cv->getModelViewMatrix();

        // search for the best fit ImpostorSprite;
        ImpostorSprite* impostorSprite = findBestImpostorSprite(contextID,eyeLocal);

        if (impostorSprite)
        {
            // impostor found, now check to see if it is good enough to use
            float error = impostorSprite->calcPixelError(*(cv->getMVPW()));

            if (error>cv->getImpostorPixelErrorThreshold())
            {
                // chosen impostor sprite pixel error is too great to use
                // from this eye point, therefore invalidate it.
                impostorSprite=NULL;
            }
        }


// need to think about sprite reuse and support for multiple context's.

        if (impostorSprite==NULL)
        {
            // no appropriate sprite has been found therefore need to create
            // one for use

            // create the impostor sprite.
            impostorSprite = createImpostorSprite(cv);

            //if (impostorSprite) impostorSprite->_color.set(0.0f,0.0f,1.0f,1.0f);

        }
        //else impostorSprite->_color.set(1.0f,1.0f,1.0f,1.0f);

        if (impostorSprite)
        {

            // update frame number to show that impostor is in action.
            impostorSprite->setLastFrameUsed(cv->getTraversalNumber());

            if (cv->getComputeNearFarMode()) cv->updateCalculatedNearFar(matrix,*impostorSprite, false);

            StateSet* stateset = impostorSprite->getStateSet();

            if (stateset) cv->pushStateSet(stateset);

            cv->addDrawableAndDepth(impostorSprite, &matrix, distance(getCenter(),matrix));

            if (stateset) cv->popStateSet();


        }
        else
        {
           // no impostor has been selected or created so default to
           // traversing the usual LOD selected child.
            LOD::traverse(nv);
        }

    }
}
Example #5
0
void
SilverLiningNode::traverse(osg::NodeVisitor& nv)
{
    if ( _SL && _SL->ready() )
    {
        if ( nv.getVisitorType() == nv.UPDATE_VISITOR )
        {
			int frameNumber = nv.getFrameStamp()->getFrameNumber();
            _skyDrawable->dirtyBound();

            if( _cloudsDrawable )
            {
                if ( _lastAltitude <= *_options.cloudsMaxAltitude() )
                {
                    if ( _cloudsDrawable->getNumParents() == 0 )
                        _geode->addDrawable( _cloudsDrawable.get() );

                    _cloudsDrawable->dirtyBound();
                }
                else
                {
                    if ( _cloudsDrawable->getNumParents() > 0 )
                        _geode->removeDrawable( _cloudsDrawable.get() );
                }
            }
        }

        else if ( nv.getVisitorType() == nv.CULL_VISITOR )
        {

            // TODO: make this multi-camera safe
            _SL->setCameraPosition( nv.getEyePoint() );
            osgUtil::CullVisitor* cv = Culling::asCullVisitor(nv);
            _SL->getAtmosphere()->SetCameraMatrix( cv->getModelViewMatrix()->ptr() );
            _SL->getAtmosphere()->SetProjectionMatrix( cv->getProjectionMatrix()->ptr() );

			_lastAltitude = _SL->getSRS()->isGeographic() ?
				cv->getEyePoint().length() - _SL->getSRS()->getEllipsoid()->getRadiusEquator() :
				cv->getEyePoint().z();

			//if (_lastAltitude <= *_options.cloudsMaxAltitude() )
			{
                _SL->updateLocation();
                _SL->updateLight();
                _SL->getAtmosphere()->UpdateSkyAndClouds();
				_SL->getAtmosphere()->CullObjects();
			}
        }
    }

    osgEarth::Util::SkyNode::traverse( nv );

    if ( _geode.valid() )
    {
        _geode->accept(nv);
    }

    if ( _lightSource.valid() )
    {
        _lightSource->accept(nv);
    }
}