Ignore:
Timestamp:
Jul 20, 2010, 9:24:42 PM (14 years ago)
Author:
Torben Dannhauer
Message:

sky silverlining vereinfacht.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/src/sky_Silverlining/visual_skySilverLining.cpp

    r64 r70  
    4141void visual_skySilverLining::skyUpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
    4242{
     43        std::cout << "Sky silverlining update callback" << std::endl;
    4344        // Check if atmosphere is initialized.
    4445        if (!sky->isInitialized())
     
    166167        skyDrawable = new skySilverLining_skyDrawable(viewer, sceneRoot);
    167168
     169        if(distortedRoot)       // if distortion used:
     170        {
     171                int rootKids = distortedRoot->getNumChildren();
     172                for (int i = 0; i < rootKids; i++)
     173                {
     174                        osg::Node *n = distortedRoot->getChild(i);
     175                        osg::Camera *cam = dynamic_cast<osg::Camera*>(n);
     176                        if (cam && cam->getRenderOrder() == osg::Camera::PRE_RENDER)
     177                                sceneCamera = cam;
     178                }
     179        }
     180        else    // if no distortion used:
     181                sceneCamera = viewer->getCamera();
     182
    168183        osg::Camera *mainCamera = viewer->getCamera();
    169184        if (!useProjMatrixCallback)
     
    175190                mainCamera->setProjectionMatrixAsPerspective(fovy, aspect, 2, 125000);
    176191        }
    177 
    178     int rootKids = distortedRoot->getNumChildren();
    179     for (int i = 0; i < rootKids; i++)
    180     {
    181         osg::Node *n = distortedRoot->getChild(i);
    182         osg::Camera *cam = dynamic_cast<osg::Camera*>(n);
    183         if (cam)
    184         {
    185             if (cam->getRenderOrder() == osg::Camera::PRE_RENDER)
    186             {
    187                 cam->setClearMask(0);
    188 
    189                 osg::ref_ptr<skySilverLining_atmosphereReference> ar = new skySilverLining_atmosphereReference;
    190                                 ar->atmosphere = atmosphere;
    191                 cam->setUserData(ar);
    192                                 mainCamera->setUserData(ar);
    193                                 sceneCamera = cam;
    194 
    195                                 if (useProjMatrixCallback)
    196                                 {
    197                                         skySilverLining_projectionMatrixCallback *cb = new skySilverLining_projectionMatrixCallback( atmosphere, viewer->getCamera(), sceneRoot);
    198                                         cam->setClampProjectionMatrixCallback(cb);
    199                                         cb->setSkyDrawable(skyDrawable);
    200                                 }
    201             }
    202         }
    203     }
    204 
    205         // Create and install updateCallback (for position etc.)
    206         updateCallback = new skyUpdateCallback( sceneGraphRoot, sceneCamera, this );
    207         this->setUpdateCallback( updateCallback );
    208 
    209     // Use a RenderBin to enforce that the sky gets drawn first, then the scene, then the clouds
    210         skyDrawable->getOrCreateStateSet()->setRenderBinDetails(-1, "RenderBin");
    211 
    212     // Add the models
    213     sceneGraphRoot->getOrCreateStateSet()->setRenderBinDetails(1, "RenderBin");
    214 
    215     // Add the clouds (note, you need this even if you don't want clouds - it calls
    216     // Atmosphere::EndFrame() )
    217         cloudsDrawable = new skySilverLining_cloudsDrawable(viewer);
    218         cloudsDrawable->getOrCreateStateSet()->setRenderBinDetails(99, "RenderBin");
    219 
    220         // Add drawable to this geode to get rendered
    221         this->addDrawable(skyDrawable);
    222         this->addDrawable(cloudsDrawable);
    223 }
    224 
    225 void visual_skySilverLining::init(osg::CoordinateSystemNode *sceneGraphRoot)
    226 {
    227         sceneRoot = sceneGraphRoot;
    228 
    229         // Use projection matrix callback oder fixed Cullsettings?
    230         bool useProjMatrixCallback = true;
    231 
    232         // add Sky to SceneRoot
    233         sceneGraphRoot->addChild( this );
    234 
    235         // Deactivate culling for the sky node (required by the silverlining sky framework)
    236         this->setCullingActive(false);
    237 
    238         // Instantiate an Atmosphere and associate it with this camera. If you have multiple cameras
    239         // in multiple contexts, be sure to instantiate seperate Atmosphere objects for each.
    240     // ***IMPORTANT!**** Check that the path to the resources folder for SilverLining in SkyDrawable.cpp
    241     // SkyDrawable::initializeSilverLining matches with where you installed SilverLining.
    242         atmosphere = new SilverLining::Atmosphere(SILVERLINING_LICENSEE, SILVERLINING_LICENSE);
    243        
    244     // Add the sky (calls Atmosphere::BeginFrame and handles initialization once you're in
    245     // the rendering thread)
    246         skyDrawable = new skySilverLining_skyDrawable(viewer, sceneRoot);
    247  
    248         if (!useProjMatrixCallback)
    249         {
    250                 viewer->getCamera()->setClearMask(0);
    251                 viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
    252                 double fovy, aspect, zNear, zFar;
    253                 viewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar);
    254                 viewer->getCamera()->setProjectionMatrixAsPerspective(fovy, aspect, 2, 125000);
    255         }
    256192        else
    257193        {
    258194                cb = new skySilverLining_projectionMatrixCallback( atmosphere, viewer->getCamera(), sceneRoot);
    259                 viewer->getCamera()->setClampProjectionMatrixCallback(cb);
     195                sceneCamera->setClampProjectionMatrixCallback(cb);
    260196                cb->setSkyDrawable(skyDrawable);
    261197        }
    262198
    263 
    264     viewer->getCamera()->setClearMask(0);
    265 
    266     osg::ref_ptr<skySilverLining_atmosphereReference> ar = new skySilverLining_atmosphereReference;
     199        // append atmosphere pointer to the cameras.
     200        sceneCamera->setClearMask(0);
     201        osg::ref_ptr<skySilverLining_atmosphereReference> ar = new skySilverLining_atmosphereReference;
    267202        ar->atmosphere = atmosphere;
    268     viewer->getCamera()->setUserData(ar);
    269         sceneCamera = viewer->getCamera();
    270 
    271        
     203        sceneCamera->setUserData(ar);
     204        mainCamera->setUserData(ar);
     205
    272206        // Create and install updateCallback (for position etc.)
    273207        updateCallback = new skyUpdateCallback( sceneGraphRoot, sceneCamera, this );
Note: See TracChangeset for help on using the changeset viewer.