{"id":1380,"date":"2024-09-19T21:09:25","date_gmt":"2024-09-19T21:09:25","guid":{"rendered":"https:\/\/www.gislxz.com\/?p=1380"},"modified":"2024-09-21T08:41:45","modified_gmt":"2024-09-21T08:41:45","slug":"osgearth%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%ef%bc%882%ef%bc%89%e8%a7%86%e8%a7%92%e4%b8%8e%e5%9f%ba%e6%9c%ac%e6%b8%b2%e6%9f%93","status":"publish","type":"post","link":"https:\/\/www.gislxz.com\/index.php\/2024\/09\/19\/osgearth%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%ef%bc%882%ef%bc%89%e8%a7%86%e8%a7%92%e4%b8%8e%e5%9f%ba%e6%9c%ac%e6%b8%b2%e6%9f%93\/","title":{"rendered":"OSGEarth\u5b66\u4e60\u7b14\u8bb0\uff082\uff09\u89c6\u89d2\u4e0e\u57fa\u672c\u6e32\u67d3"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u6444\u50cf\u673a\u63a7\u5236<\/h2>\n\n\n\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/659703155\" target=\"_blank\"  rel=\"nofollow\" >osgEarth\u5165\u95e813\u5207\u6362\u76f8\u673a\u62cd\u6444\u70b9 - \u77e5\u4e4e (zhihu.com)<\/a><\/p>\n\n\n\n<p>\u770b\u4e86\u4e0bviewpoint\u7684\u6e90\u7801\uff0c\u8fd8\u7b97\u6e05\u6670<\/p>\n\n\n\n<p>\u8bb0\u5f97\u4e00\u5b9a\u5148\u8bbe\u7f6e\u573a\u666f\u6570\u636e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u8bbe\u7f6e\u573a\u666f\u6570\u636e\n    viewer.setSceneData(mapNode);\n\n    Viewpoint vp(\"demo\",\n        0,  \/\/ \u7126\u70b9\u7ecf\u5ea6 \uff0c\u5355\u4f4d\u89d2\u5ea6\u3002\n        0,  \/\/ \u7126\u70b9\u7ef4\u5ea6 \uff0c\u5355\u4f4d\u89d2\u5ea6\u3002\n        0,   \/\/ \u6d77\u62d4\u9ad8\u5ea6 \u5355\u4f4d\u7c73\u3002\n        0,   \/\/ Heading \u76f8\u673a\u6307\u5411\u7126\u70b9\u89d2\u5ea6\uff0c\u5355\u4f4d\u89d2\u5ea6\u3002\n        -90,   \/\/ pitch \u76f8\u673a\u76f8\u5bf9\u7126\u70b9\u4fef\u4ef0\u89d2\u5ea6\uff0c\u5355\u4f4d\u89d2\u5ea6\u3002\n        1E7 \/\/ \u8ddd\u79bb\u7126\u70b9\u8ddd\u79bb\uff0c\u8fd9\u91cc\u8868\u793a\u8ddd\u79bb\u5730\u8868\u7ecf\u7eac\u5ea6\u70b9\u7684\u8ddd\u79bb\uff0c\u5355\u4f4d\u7c73\u3002\n    );\n    earthManipulator->setViewpoint(vp\n        , 0  \/\/ \u76f8\u673a\u79fb\u52a8\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2\u3002\n    );\n    vp.setFocalPoint(GeoPoint(SpatialReference::get(\"wgs84\"),118.87, 37.64, 0.0, ALTMODE_ABSOLUTE));\n    vp.setRange(Distance(1E5, Units::METERS));\n    earthManipulator->setViewpoint(vp\n        , 5  \/\/ \u76f8\u673a\u79fb\u52a8\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2\u3002\n    );\n\n    \/\/ \u8fd0\u884cviewer\n    \/\/return Metrics::run(viewer);\n    return viewer.run();<\/code><\/pre>\n\n\n\n<p>\u7528callback\u673a\u5236\u52a0\u5b9a\u65f6\u5668\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbe\u7f6e\u591a\u6bb5\u89c6\u89d2\u53d8\u5316\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u81ea\u5b9a\u4e49\u56de\u8c03\u7c7b\uff0c\u7528\u4e8e\u987a\u5e8f\u5207\u6362\u591a\u4e2a Viewpoint\nclass MultiViewpointCallback : public osg::NodeCallback\n{\npublic:\n    MultiViewpointCallback(osgEarth::EarthManipulator* manipulator,\n        const std::vector&lt;osgEarth::Viewpoint>&amp; viewpoints,\n        const std::vector&lt;int>&amp; times)\n        : _manipulator(manipulator), _viewpoints(viewpoints), _times(times), _currentIndex(0), _elapsedTime(0.0), _firstViewpointExecuted(false)\n    {\n        _lastUpdateTime = osg::Timer::instance()->tick();\n    }\n\n    \/\/ \u6bcf\u4e00\u5e27\u8c03\u7528\u6b64\u65b9\u6cd5\n    virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) override\n    {\n        \/\/ \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\n        osg::Timer_t now = osg::Timer::instance()->tick();\n        double deltaTime = osg::Timer::instance()->delta_s(_lastUpdateTime, now);\n        _elapsedTime += deltaTime;\n\n        \/\/ \u5982\u679c\u7b2c\u4e00\u4e2a Viewpoint \u672a\u6267\u884c\uff0c\u7acb\u5373\u6267\u884c\n        if (!_firstViewpointExecuted &amp;&amp; _currentIndex == 0)\n        {\n            \/\/ \u4f7f\u7528 _times \u4e2d\u7684\u8fc7\u6e21\u65f6\u95f4\n            _manipulator->setViewpoint(_viewpoints&#91;_currentIndex], _times&#91;_currentIndex]);\n            _firstViewpointExecuted = true;  \/\/ \u6807\u8bb0\u7b2c\u4e00\u4e2a Viewpoint \u5df2\u6267\u884c\n            _elapsedTime = 0.0;  \/\/ \u91cd\u7f6e\u8ba1\u65f6\u5668\n            _currentIndex++;  \/\/ \u51c6\u5907\u6267\u884c\u4e0b\u4e00\u4e2a Viewpoint\n        }\n        \/\/ \u68c0\u67e5\u662f\u5426\u5230\u8fbe\u4e0a\u4e00\u4e2a Viewpoint \u7684\u8fc7\u6e21\u65f6\u95f4\u5e76\u4e14\u8fd8\u6709\u672a\u5207\u6362\u7684\u89c6\u70b9\n        else if (_elapsedTime >= _times&#91;_currentIndex - 1] &amp;&amp; _currentIndex &lt; _viewpoints.size())\n        {\n            \/\/ \u4f7f\u7528 _times \u4e2d\u7684\u8fc7\u6e21\u65f6\u95f4\n            _manipulator->setViewpoint(_viewpoints&#91;_currentIndex], _times&#91;_currentIndex]);\n            _elapsedTime = 0.0;  \/\/ \u91cd\u7f6e\u8ba1\u65f6\u5668\n            _currentIndex++;\n        }\n\n        _lastUpdateTime = now;  \/\/ \u66f4\u65b0\u65f6\u95f4\n        \/\/ \u7ee7\u7eed\u573a\u666f\u56fe\u7684\u904d\u5386\u548c\u66f4\u65b0\n        traverse(node, nv);\n    }\n\nprivate:\n    osgEarth::EarthManipulator* _manipulator;\n    std::vector&lt;osgEarth::Viewpoint> _viewpoints;\n    std::vector&lt;int> _times;  \/\/ \u6bcf\u4e2a Viewpoint \u7684\u8fc7\u6e21\u65f6\u95f4\n    unsigned int _currentIndex;\n    double _elapsedTime;\n    osg::Timer_t _lastUpdateTime;\n    bool _firstViewpointExecuted;  \/\/ \u7528\u4e8e\u6807\u8bb0\u7b2c\u4e00\u4e2a Viewpoint \u662f\u5426\u5df2\u7ecf\u6267\u884c\n};\n\nint main(){\n    ...\n    \/\/ \u8bbe\u7f6e\u573a\u666f\u6570\u636e\n    viewer.setSceneData(mapNode);\n    \n    \/\/\u8bbe\u7f6e\u521d\u59cb\u70b9\n    osgEarth::Viewpoint Viewpoint1(\"Viewpoint1\", 120.0, 30.0, 0.0, 0.0, -90, 2E7);\n    earthManipulator->setViewpoint(Viewpoint1, 0.0);\n    \/\/ \u5b9a\u4e49\u591a\u4e2a Viewpoint\n    std::vector&lt;int> times = { 7, 5 };\n    std::vector&lt;osgEarth::Viewpoint> viewpoints;\n    viewpoints.push_back(osgEarth::Viewpoint(\"Viewpoint1\", 118.87, 37.64, 0.0, 0.0, -90, 9E5));\n    viewpoints.push_back(osgEarth::Viewpoint(\"Viewpoint2\", 118.87, 37.64, 0.0, 0.0, -90, 9E4));\n\n    \/\/ \u521b\u5efa\u81ea\u5b9a\u4e49\u56de\u8c03\n    osg::ref_ptr&lt;MultiViewpointCallback> callback = new MultiViewpointCallback(earthManipulator, viewpoints, times);\n\n    \/\/ \u5c06\u56de\u8c03\u6dfb\u52a0\u5230\u5730\u56fe\u8282\u70b9\u4e0a\n    mapNode->addUpdateCallback(callback);\n\n    \/\/ \u8fd0\u884cviewer\n    return viewer.run();\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">OSGEarth\u7f13\u5b58\u76ee\u5f55 cache<\/h2>\n\n\n\n<p>\u8bd5\u4e86\u4e00\u665a\u4e0a\uff0ccache\u7684\u6e90\u4ee3\u7801\u6211\u662f\u4e00\u70b9\u6ca1\u627e\u5230\u634f\u5988\u7684\u5730\u5740\u8bbe\u7f6e\u5728\u54ea\u3002\u552f\u4e00\u53ef\u884c\u7684\u65b9\u6cd5\u662f\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    _putenv_s(\"OSGEARTH_CACHE_PATH\", \"D:\/coding\/testdata\/cache\");\n    \/\/_putenv_s(\"OSGEARTH_CACHE_ONLY\", \"1\");\/\/\u53ea\u4ece\u7f13\u5b58\u8bfb\u53d6<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6444\u50cf\u673a\u63a7\u5236 osgEarth\u5165\u95e813\u5207\u6362\u76f8\u673a\u62cd\u6444\u70b9 &#8211; \u77e5\u4e4e (zhihu.com) \u770b\u4e86\u4e0bviewpoint\u7684\u6e90\u7801\uff0c\u8fd8\u7b97\u6e05\u6670 \u8bb0 &#823","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1380","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts\/1380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/comments?post=1380"}],"version-history":[{"count":6,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts\/1380\/revisions"}],"predecessor-version":[{"id":1388,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts\/1380\/revisions\/1388"}],"wp:attachment":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/media?parent=1380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/categories?post=1380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/tags?post=1380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}