查看: 1153|回复: 1

如何运行osgearth_triton.cpp

[复制链接]
  • TA的每日心情
    开心
    2020-3-20 17:50
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 2019-12-28 16:45:09 | 显示全部楼层 |阅读模式
    osgearth2.8 osg3.4
    代码如下
    #include <osgViewer/Viewer>
    #include <osgDB/FileNameUtils>
    #include <osgEarthUtil/EarthManipulator>
    #include <osgEarthUtil/ExampleResources>
    #include <osgEarthUtil/Controls>
    #include <osgEarthTriton/TritonNode>

    #define LC "[osgearth_sundog] "

    using namespace osgEarth;
    using namespace osgEarth::Util;
    using namespace osgEarth::Triton;
    namespace ui = osgEarth::Util::Controls;

    struct Settings
    {
        TritonNode* triton;
        optional<double> chop;
        optional<double> seaState;
        optional<float> alpha;
       
        void apply(Environment& env, Ocean& ocean)
        {
            if (chop.isSet())
            {
                ocean.SetChoppiness(chop.get());
                chop.clear();
            }

            if (seaState.isSet())
            {
                env.SimulateSeaState(seaState.get(), 0.0);
                seaState.clear();
            }

            if (alpha.isSet())
            {
                triton->setAlpha( alpha.get() );
            }
        }
    };
    Settings s_settings;


    template<typename T> struct Set : public ui::ControlEventHandler
    {
        optional<T>& _var;
        Set(optional<T>& var) : _var(var) { }
        void onValueChanged(ui::Control*, double value) { _var = value; }
    };


    Container* createUI()
    {
        VBox* box = new VBox();
        box->setBackColor(0,0,0,0.5);
        Grid* grid = box->addControl(new Grid());
        int r=0;
        grid->setControl(0, r, new LabelControl("Chop"));
        grid->setControl(1, r, new HSliderControl(0, 3, 0, new Set<double>(s_settings.chop)));
        ++r;
        grid->setControl(0, r, new LabelControl("Sea State"));
        grid->setControl(1, r, new HSliderControl(0, 12, 5, new Set<double>(s_settings.seaState)));
        ++r;  
        grid->setControl(0, r, new LabelControl("Alpha"));
        grid->setControl(1, r, new HSliderControl(0, 1.0, 1.0, new Set<float>(s_settings.alpha)));
        ++r;
        grid->getControl(1, r-1)->setHorizFill(true,200);

        return box;
    }

    class TritonCallback : public osgEarth::Triton::Callback
    {
    public:
        void onInitialize(Environment& env, Ocean& ocean)
        {
            //todo
        }

        void onDrawOcean(Environment& env, Ocean& ocean)
        {
            s_settings.apply(env, ocean);
        }
    };


    int
    usage(const char* name)
    {
        OE_DEBUG
            << "\nUsage: " << name << " file.earth" << std::endl
            << osgEarth::Util::MapNodeHelper().usage() << std::endl;

        return 0;
    }

    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);

        // Tell the database pager to not modify the unref settings
        viewer.getDatabasePager()->setUnrefImageDataAfterApplyPolicy( false, false );

        // install our default manipulator (do this before calling load)
        viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator() );

        // load an earth file, and support all or our example command-line options
        // and earth file <external> tags   
        osg::Group* node = osgEarth::Util::MapNodeHelper().load(arguments, &viewer, createUI());
        if ( node )
        {        
            viewer.getCamera()->setNearFarRatio(0.00002);
            viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);

            viewer.setSceneData( node );

            MapNode* mapNode = MapNode::findMapNode( node );

            // Create TritonNode from TritonOptions
            osgEarth::Triton::TritonOptions tritonOptions;
            tritonOptions.user()        = "my_user_name";
            tritonOptions.licenseCode() = "my_license_code";
            tritonOptions.maxAltitude() = 10000;
  • TA的每日心情
    开心
    2020-3-20 17:50
  • 签到天数: 1 天

    [LV.1]初来乍到

     楼主| 发表于 2019-12-28 16:52:46 | 显示全部楼层
    本帖最后由 liyihongcug 于 2020-4-14 14:13 编辑

    osgearth+triton终于通过在非qt环境下可以看到流畅海图,
    但现在发现在QT环境下 无法正常浏览海图
    1 qt下海图很不正常,经常一晃而过无法稳定留驻在视口上;
    2  卡慢

    上面都不是问题。最麻烦的是集成这个在rttpicker相机下的问题
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    OSG中国官方论坛-有您OSG在中国才更好

    网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

    联系我们

    • 工作时间:09:00--18:00
    • 反馈邮箱:1315785073@qq.com
    快速回复 返回顶部 返回列表