Hi everyone,

I'm facing a problem in our flight simulation environment, where we want to make the fog camera dependent ( in order to have cameras without fog for simulation control). I tried to follow the 2009 thread "[osg-users] Set fog in the canera StateSet" and succeded to implement a non variyng fog. But in our case we have a statesetcallback for changing the parameter of the fog and one for activating disactivating the fog.

This is how was set the fog before (one fog for all views) :

    /*
     * Fog
     */
    Fog * fog = pe->getFog(); // pe is a osgParticle::PrecipitationEffect
    root->getOrCreateStateSet()->setAttributeAndModes(fog, osg::StateAttribute::ON);
    fog->setUpdateCallback(new vesaFogUpdateCallback);
    root->getOrCreateStateSet()->setUpdateCallback(new vesaFogEnableUpdateCallback);

But, adding the fog to our different views, neither the vesaFogUpdateCallback nor the vesaFogEnableUpdateCallback are accessed anymore... This is the code I tryed to implement :

        BOOST_FOREACH(propTreeNode & v, arbreUtile->getOptionalChildProperties("graphic.windows.views"))
        {
            propTreeHolder pView(&v.second);
            if(pView.empty() || v.first.compare("msgFile")==0 || v.first.compare("activeView")==0)
                continue;

            std::string name = v.first;
            osgViewer::View* view = new osgViewer::View;
            view->setName(name);
            addView(view);
            view->setSceneData(root);
            view->getCamera()->setName(name);
            view->getCamera()->setClearColor(fog->getColor());

            view->getCamera()->setViewport(
                new osg::Viewport(
                    traits->width *     pView.getPropValue<float>("xMin",0.0),
                    traits->height *     pView.getPropValue<float>("yMin",0.0),
                    traits->width *     pView.getPropValue<float>("sizeX",1.0),
                    traits->height *     pView.getPropValue<float>("sizeY",1.0)
                )
            );

            view->getCamera()->setGraphicsContext(gc.get());
            view->getCamera()->setCullSettings(cs);
            if (arbreUtile->getPropValue<bool>("graphic.windows.views."+name+ ".effects.withFog",true))
            {
                osg::ref_ptr<osg::Fog> fog = new osg::Fog();
                float             varNear     = 0.0f;
                float             end         = 0.0f;
                float             density     = 0.0f;
                std::string     tmp         = "";
                osg::Fog::Mode    mode;
                osg::Vec4f         color;
                /*
                 * Get values
                 */
                varNear     = arbreUtile->getPropValue<float>("sim.environement.fog.start", 10000.);
                end         = arbreUtile->getPropValue<float>("sim.environement.fog.end", 20000.);
                density     = arbreUtile->getPropValue<float>("sim.environement.fog.density", 0.00001);
                color         = arbreUtile->getPropValue<osg::Vec4f>("sim.environement.fog.color", osg::Vec4f(0.7,0.7,0.7,1.0));
                if((tmp = arbreUtile->getPropValue<std::string>("sim.environement.fog.mode",std::string("exp2"))) == "linear" )
                    mode = osg::Fog::LINEAR;
                else if(tmp == "exp")
                    mode = osg::Fog::EXP;
                else if(tmp == "exp2")
                    mode = osg::Fog::EXP2;
                else
                    mode = osg::Fog::EXP2;
                fog->setMode(mode);
                fog->setStart(varNear);
                fog->setEnd(end);
                fog->setDensity(density);
                fog->setColor(color);
                view->getCamera()->getOrCreateStateSet()->setAttributeAndModes(fog, osg::StateAttribute::ON);
                fog->setUpdateCallback(new vesaFogUpdateCallback);
                view->getCamera()->getOrCreateStateSet()->setUpdateCallback(new vesaFogEnableUpdateCallback);
            }
        }

The solution I found is to create an UpdateCallback for each camera which implements the code present in both my old Fog callbacks.

Does anyone have an idea of why the UpdateCallBack of the stateset does not work when associated to a camera ? What am I doing wrong ?

Moreover, I initially tried to activate desactivate the osf::Fog, the osg::Light and the osgParticle::PrecipitationEffect using a NodeMask/CullMask logic for each camera. It works for the PrecipitationEffect, but doesn't for the Fog and the Light. Is it a normal behaviour or is there something wrong in my code (in which case I would show you the code).

Thankyou for your help,

SCHULTE Christian
Research  Engineer
in charge of the Simulation Laboratory
System Control and Flight Dynamics Department
Simulation and Flight Testing Unit

ONERA - The French Aerospace Lab
Ecole de l'Air - BA 701
13661 SALON cedex AIR
FRANCE



_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to