int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); // help? if ( arguments.read("--help") ) return usage(argv[0]); osgViewer::Viewer viewer(arguments); EarthManipulator* em = new EarthManipulator(); viewer.setCameraManipulator( em ); // load an earth file, and support all or our example command-line options // and earth file <external> tags osg::Node* earth = MapNodeHelper().load( arguments, &viewer ); MapNode* mapNode = MapNode::get(earth); if (!mapNode) return usage(argv[0]); // load the model file into the local coordinate frame, which will be // +X=east, +Y=north, +Z=up. osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFile("../data/axes.osgt.(1000).scale.osgearth_shadergen"); if (!model.valid()) return usage(argv[0]); osg::Group* root = new osg::Group(); root->addChild( earth ); App app; app.srs = mapNode->getMapSRS(); app.geo = new GeoTransform(); app.pat = new osg::PositionAttitudeTransform(); app.pat->addChild( model.get() ); app.geo->addChild( app.pat ); // Place your GeoTransform under the map node and it will automatically support clamping. // If you don't do this, you must call setTerrain to get terrain clamping. mapNode->addChild( app.geo ); viewer.setSceneData( root ); viewer.getCamera()->setNearFarRatio(0.00002); viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f); ui::ControlCanvas::getOrCreate(&viewer)->addControl( makeUI(app) ); app.apply(); osgEarth::Viewpoint vp; vp.setNode( app.geo ); vp.heading()->set( -45.0, Units::DEGREES ); vp.pitch()->set( -20.0, Units::DEGREES ); vp.range()->set( model->getBound().radius()*10.0, Units::METERS ); em->setViewpoint( vp ); return viewer.run(); }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); // help? if ( arguments.read("--help") ) return usage(argv[0]); // create a viewer: osgViewer::Viewer viewer(arguments); // Whether to test updating material bool update = arguments.read("--update"); // Tell the database pager to not modify the unref settings viewer.getDatabasePager()->setUnrefImageDataAfterApplyPolicy( true, false ); // install our default manipulator (do this before calling load) viewer.setCameraManipulator( new EarthManipulator(arguments) ); // disable the small-feature culling viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f); viewer.setLightingMode(viewer.NO_LIGHT); // load an earth file, and support all or our example command-line options osg::ref_ptr<osg::Node> node = MapNodeHelper().load(arguments, &viewer); if (node.valid()) { MapNode* mapNode = MapNode::get(node.get()); if ( !mapNode ) return -1; // Example of a custom material for the terrain. osg::ref_ptr< osg::Material > material = 0; if (update) { OE_NOTICE << "Custom material" << std::endl; material = new osg::Material; material->setDiffuse(osg::Material::FRONT, osg::Vec4(1,1,1,1)); material->setAmbient(osg::Material::FRONT, osg::Vec4(1,1,1,1)); // Attach our StateAttributeCallback so that uniforms are updated. material->setUpdateCallback(new MaterialCallback()); mapNode->getOrCreateStateSet()->setAttributeAndModes(material); } // Does a Sky already exist (loaded from the earth file)? SkyNode* sky = osgEarth::findTopMostNodeOfType<SkyNode>(node.get()); if (!sky) { // Add phong lighting. PhongLightingEffect* phong = new PhongLightingEffect(); phong->attach(node->getOrCreateStateSet()); } osg::Group* lights = addLights(&viewer, node.get(), sky?1:0); mapNode->addChild(lights); viewer.setSceneData(node.get()); while (!viewer.done()) { if (viewer.getFrameStamp()->getFrameNumber() % 100 == 0) { if (material) { material->setDiffuse(osg::Material::FRONT, randomColor()); } } viewer.frame(); } return 0; } else { return usage(argv[0]); } }