本节演示使用CCsium库加载cesium的世界地形,使用第四节单击事件的例子,修改点击事件添加地形。
1、ceisum显示地形需要引入CesiumTerrainProvider和CreateWorldTerrain类。与ceisum类似,修改鼠标点击事件,创建地形并添加到ceisum中。
if (aggregator->terrain == NULL) { aggregator->terrain = Cesium::CreateWorldTerrain::createWorldTerrain(); aggregator->viewer->terrainProvider(aggregator->terrain); }
支持地形下载
2、点击运行,左键单击即可看到地形
完整代码
/** * Created by IBM on 2021/3/3. */ #include <iostream> #include <Widgets/Viewer/Viewer.h> #include <Core/CesiumTerrainProvider.h> #include <Core/CreateWorldTerrain.h> class Handler { public: Cesium::Viewer *viewer; Cesium::CesiumTerrainProvider *terrain = NULL; /** * 鼠标抬起事件 * @param type * @param position */ static void mouseUp(void *handler, Cesium::ScreenEvent *event) { Handler *aggregator = (Handler *) handler; if (aggregator->terrain == NULL) { aggregator->terrain = Cesium::CreateWorldTerrain::createWorldTerrain(); aggregator->viewer->terrainProvider(aggregator->terrain); } } }; int main(int argc, char *argv[]) { Handler *handler = new Handler(); Cesium::Viewer viewer = Cesium::Viewer(500, 300); handler->viewer = &viewer; std::string url = "https://dev.virtualearth.net"; std::string key = "AmXdbd8UeUJtaRSn7yVwyXgQlBBUqliLbHpgn2c76DfuHwAXfRrgS5qwfHU6Rhm8"; Cesium::BingMapsImageryProvider *imageryProvider1 = new Cesium::BingMapsImageryProvider(url, key); viewer.imageryLayers()->addImageryProvider(imageryProvider1); //创建事件 Cesium::ScreenSpaceEventHandler *_eventHandler = new Cesium::ScreenSpaceEventHandler(handler); _eventHandler->setInputAction(&Handler::mouseUp, Cesium::ScreenSpaceEventType::LEFT_CLICK);//设置鼠标点击事件 viewer.startAnimating(true);//启动opengl循环 system("pause"); return 0; }
返回目录