ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ogearth 示例

2019-08-12 11:37:08  阅读:533  来源: 互联网

标签:map 示例 viewer Util osgEarth new ogearth osgViewer


原文链接:http://blog.sina.com.cn/s/blog_546e0c1f0101egcx.html
//初始化影像、地形
void initImageAndElevation(osgEarth::Map* map)
{
 //影像
 osgEarth::Drivers::TMSOptions imgOption;
 imgOption.url()="D:/CacheData/OUTDATA/JiLinImage/tms.xml";
 //imgOption.url()="http://readymap.org/readymap/tiles/1.0.0/7/";
 map->addImageLayer( new osgEarth::ImageLayer( "image", imgOption ) );
 //高程
 osgEarth::Drivers::TMSOptions elvOption;
 elvOption.url()="D:/CacheData/OUTDATA/JiLinElevation/tms.xml";
 //elvOption.url()="http://readymap.org/readymap/tiles/1.0.0/9/";
 map->addElevationLayer( new osgEarth::ElevationLayer( "elevation", elvOption ) );
}
//初始化省界国界
void initBoundaries(osgEarth::Map* map)
{
 osgEarth::Drivers::FeatureGeomModelOptions worldBoundaries;
 osgEarth::Drivers::OGRFeatureOptions ogrOptions;
 ogrOptions.url()="world.shp";
 worldBoundaries.compilerOptions()=ogrOptions;
 //worldBoundaries.styles().
 map->addModelLayer(new osgEarth::ModelLayer("world", worldBoundaries));
}
//初始化事件处理器
void initEventHandler(osgViewer::Viewer* viewer,osgEarth::MapNode* mapNode)
{
 //鼠标位置信息显示
 osgEarth::Util::Formatter* formatter = new osgEarth::Util::LatLongFormatter();
 osgEarth::Util::LabelControl* readout = new osgEarth::Util::LabelControl();
 osgEarth::Util::ControlCanvas::get( viewer, true )->addControl( readout );
 osgEarth::Util::MouseCoordsTool* tool = new osgEarth::Util::MouseCoordsTool( mapNode );
 tool->addCallback( new osgEarth::Util::MouseCoordsLabelCallback(readout, formatter) );
 viewer->addEventHandler( tool );
 // add the state manipulator
    viewer->addEventHandler( new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet()) );
 // add the thread model handler
    viewer->addEventHandler(new osgViewer::ThreadingHandler);
 // add the window size toggle handler
    viewer->addEventHandler(new osgViewer::WindowSizeHandler);
 // add the stats handler
    viewer->addEventHandler(new osgViewer::StatsHandler);
 // add the record camera path handler
    viewer->addEventHandler(new osgViewer::RecordCameraPathHandler);
 // add the LOD Scale handler
    viewer->addEventHandler(new osgViewer::LODScaleHandler);
 // add the screen capture handler
    viewer->addEventHandler(new osgViewer::ScreenCaptureHandler);
}
//初始化操纵器
void initManipulator(osgViewer::Viewer* viewer,osgEarth::Map* map)
{
 //操纵器
    osgEarth::Util::EarthManipulator* em=new osgEarth::Util::EarthManipulator();
    //赤道半径
    double equatorRadius=map->getSRS()->getEllipsoid()->getRadiusEquator();//6378137.0
 //初始视点正对中国北京
    em->setHomeViewpoint(osgEarth::Util::Viewpoint(116.3,39.9,0,0,-90,equatorRadius*4));
    viewer->setCameraManipulator(em);
 //定位吉林
    em->setViewpoint(osgEarth::Util::Viewpoint(126,43,0,0,-90,5e4), 5);//5s
}
//初始化其他杂项
void initOther(osgViewer::Viewer* viewer,osgEarth::MapNode* mapNode)
{
 //反锯齿
 osg::DisplaySettings::instance()->setNumMultiSamples( 4 );
 //设置最大PagedLOD节点数目
 //viewer->getDatabasePager()->setTargetMaximumNumberOfPageLOD(10);
    //近地面自动裁剪AutoClipPlaneCullCallback
    viewer->getCamera()->addCullCallback( new osgEarth::Util::AutoClipPlaneCullCallback(mapNode) );
 //绘制经纬度网格
 //osgEarth::Util::GeodeticGraticule* gr = new osgEarth::Util::GeodeticGraticule( mapNode );
 //root->addChild(gr);
}

void main(){
 osg::ref_ptr viewer = new osgViewer::Viewer;
 //osgViewer::Viewer* viewer = new osgViewer::Viewer;
 osg::Group* root = new osg::Group();
 osg::Node* tankNode = NULL;
 osg::Vec3 tankPosit; 
 osg::PositionAttitudeTransform* tankXform;
 //缓存
 osgEarth::Drivers::FileSystemCacheOptions cacheOptions;
 cacheOptions.rootPath() = "./cache";
 osgEarth::MapOptions mapOptions;
 mapOptions.cache() = cacheOptions;
 //osgEarth::Map* map = new osgEarth::Map(mapOptions);
 //osgEarth::MapNode* mapNode = new osgEarth::MapNode( map );
 osg::Node* configEarth = osgDB::readNodeFile("config.earth");
 osgEarth::MapNode* mapNode = osgEarth::MapNode::findMapNode( configEarth );
 osgEarth::Map* map = mapNode->getMap();
 //关闭光照
    mapNode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
 viewer->setSceneData( root );
 root->addChild(mapNode);
 //读取模型
 tankNode = osgDB::readNodeFile("Models/t72-tank/t72-tank_des.flt");
 tankXform = new osg::PositionAttitudeTransform();
 root->addChild(tankXform);
 tankXform->addChild(tankNode);
 tankPosit.set(5,0,0);
 tankXform->setPosition( tankPosit ); 
 viewer->setCameraManipulator(new osgGA::TrackballManipulator());

 //地形影像
 //initImageAndElevation(map);

 //矢量
 //initBoundaries(map);

 //操纵器
 initManipulator(viewer, map);

 //事件处理(键盘鼠标)
 initEventHandler(viewer, mapNode);

 //其他
    initOther(viewer, mapNode);

 viewer->realize();

 while( !viewer->done() )
 {
  viewer->frame();
 } 
}

标签:map,示例,viewer,Util,osgEarth,new,ogearth,osgViewer
来源: https://blog.csdn.net/u013693952/article/details/99292956

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有