SilverLining for Android 1.0 Skies, 3D clouds, and weather for Android

- Main Page
- Related Pages
- Packages
- Classes
- Files

- File List

mainpage.h

    00001
    00381 #ifdef FIXED_NEAR_FAR
    00382         viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
    00383         double fovy, aspect, zNear, zFar;
    00384         viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspect, zNear, zFar);
    00385         viewer.getCamera()->setProjectionMatrixAsPerspective(fovy, aspect, 10, 100000);
    00386 #endif
    00387  /*
    00388         or, you can use the included projection matrix callback to intercept how OSG computes
    00389         the near and far clip planes and take SilverLining's objects into account, like this:
    00390  */
    00391
    00392 #ifndef FIXED_NEAR_FAR
    00393         SilverLiningProjectionMatrixCallback *cb = new SilverLiningProjectionMatrixCallback(
    00394                 atm, viewer.getCamera());
    00395         viewer.getCamera()->setClampProjectionMatrixCallback(cb);
    00396         cb->setSkyDrawable(skyDrawable);
    00397 #endif
    00398
    00399         AtmosphereReference *ar = new AtmosphereReference;
    00400         ar->atmosphere = atm;
    00401         viewer.getCamera()->setUserData(ar);
    00402
    00403         // Use a RenderBin to enforce that the scene gets drawn first, then the sky, then the clouds
    00404         skyGeode->getOrCreateStateSet()->setRenderBinDetails(98, "RenderBin");
    00405         skyGeode->getOrCreateStateSet()->setAttributeAndModes( new osg::Depth( osg::Depth::LEQUAL, 0.0, 1.0, false ) );
    00406
    00407         // Add the models
    00408         sceneGraphRoot.get()->getOrCreateStateSet()->setRenderBinDetails(1, "RenderBin");
    00409
    00410         // Add the clouds (note, you need this even if you don't want clouds - it calls
    00411         // Atmosphere::DrawObjects() )
    00412         osg::Geode *cloudsGeode = new osg::Geode;
    00413         CloudsDrawable * cloudsDrawable = new CloudsDrawable(&viewer);
    00414         cloudsGeode->addDrawable(cloudsDrawable);
    00415         cloudsGeode->getOrCreateStateSet()->setRenderBinDetails(99, "RenderBin");
    00416         cloudsGeode->setCullingActive(false);
    00417
    00418 #ifndef FIXED_NEAR_FAR
    00419         cb->setCloudsDrawable(cloudsDrawable);
    00420 #endif
    00421
    00422         viewer.getSceneData()->asGroup()->addChild(skyGeode);
    00423         viewer.getSceneData()->asGroup()->addChild(cloudsGeode);
    00424
    00425         osg::notify(osg::ALWAYS)<<"SilverLining integration completed..."<<std::endl;
    00426 }
    00427 \endcode
    00428
    00429 To modify the conditions being simulated, you may modify the SkyDrawable::initializeSilverLining method to meet your own needs:
    00430
    00431 \code
    00432 void SkyDrawable::initializeSilverLining(AtmosphereReference *ar) const
    00433 {
    00434     if (ar && !ar->atmosphereInitialized)
    00435     {
    00436         ar->atmosphereInitialized = true; // only try once.
    00437                 SilverLining::Atmosphere *atmosphere = ar->atmosphere;
    00438
    00439         if (atmosphere)
    00440         {
    00441             srand(1234); // constant random seed to ensure consistent clouds across windows
    00442
    00443 #ifdef ANDROID
    00444             std::string resPath("Resources/");
    00445             int ret = atmosphere->Initialize(SilverLining::Atmosphere::OPENGLES2, resPath.c_str(),
    00446                                              true, 0);
    00447
    00448 #else
    00449             // Update the path below to where you installed SilverLining's resources folder.
    00450             const char *slPath = getenv("SILVERLINING_PATH");
    00451             if (!slPath)
    00452             {
    00453                 printf("Can't find SilverLining; set the SILVERLINING_PATH environment variable ");
    00454                 printf("to point to the directory containing the SDK.\n");
    00455                 exit(0);
    00456             }
    00457
    00458             std::string resPath(slPath);
    00459             resPath += "\\Resources\\";
    00460
    00461             int ret = atmosphere->Initialize(SilverLining::Atmosphere::OPENGL, resPath.c_str(),
    00462                                              true, 0);
    00463 #endif
    00464             if (ret != SilverLining::Atmosphere::E_NOERROR)
    00465             {
    00466                 printf("SilverLining failed to initialize; error code %d.\n", ret);
    00467                 printf("Check that the path to the SilverLining installation directory is set properly ");
    00468                 printf("in SkyDrawable.cpp (in SkyDrawable::initializeSilverLining)\n");
    00469                 exit(0);
    00470             }
    00471
    00472             // Let SilverLining know which way is up. OSG usually has Z going up.
    00473             atmosphere->SetUpVector(0, 0, 1);
    00474             atmosphere->SetRightVector(1, 0, 0);
    00475
    00476             // Set our location (change this to your own latitude and longitude)
    00477             SilverLining::Location loc;
    00478             loc.SetAltitude(0);
    00479             loc.SetLatitude(45);
    00480             loc.SetLongitude(-122);
    00481             atmosphere->GetConditions()->SetLocation(loc);
    00482
    00483             // Set the time to noon in PST
    00484             SilverLining::LocalTime t;
    00485             t.SetFromSystemTime();
    00486                         t.SetHour(12);
    00487                         t.SetTimeZone(PST);
    00488             atmosphere->GetConditions()->SetTime(t);
    00489
    00490             // Center the clouds around the camera's initial position
    00491             osg::Vec3d pos = _view->getCameraManipulator()->getMatrix().getTrans();
    00492
    00493             SilverLining::CloudLayer *cumulusCongestusLayer;
    00494             cumulusCongestusLayer = SilverLining::CloudLayerFactory::Create(CUMULUS_CONGESTUS);
    00495             cumulusCongestusLayer->SetIsInfinite(true);
    00496             cumulusCongestusLayer->SetBaseAltitude(4000);
    00497             cumulusCongestusLayer->SetThickness(500);
    00498             cumulusCongestusLayer->SetBaseLength(40000);
    00499             cumulusCongestusLayer->SetBaseWidth(40000);
    00500             cumulusCongestusLayer->SetDensity(0.3);
    00501
    00502             // Note, we pass in X and -Y since this accepts "east" and "south" coordinates.
    00503             cumulusCongestusLayer->SetLayerPosition(pos.x(), -pos.y());
    00504             cumulusCongestusLayer->SeedClouds(*atmosphere);
    00505             cumulusCongestusLayer->GenerateShadowMaps(false);
    00506
    00507             atmosphere->GetConditions()->AddCloudLayer(cumulusCongestusLayer);
    00508
    00509         }
    00510     }
    00511 }
    00512 \endcode
    00513
    00514 The complete SilverLining C++ API is available to you, as documented in \ref native and at http://www.sundog-soft.com/docs/html/index.html
    00515
    00516         */
    00517