OSG仿真案例(2)

从路径中读取一个运动路径(本代码中,是从程序中直接输入三个点),系统自动计算之间插值,达到连续运动的目的。(控制相机的运动的动画漫游)

int wavaModule()
{
    int argc = 2;

    char* argv[] = { "G:/YCThirdParty/EarthData/demo.earth" ,"--sky" };
    osg::ArgumentParser args1(&argc, argv);

    ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer(args1);
    ref_ptr <Group> root = new osg::Group();
    viewer->setUpViewInWindow(0, 50, 650, 650);
    MapNodeHelper m_MapNodeHelper;
    ref_ptr <Node> node1 = m_MapNodeHelper.load(args1, viewer, 0L, 0L);

    ref_ptr<MapNode> mapNode1 = osgEarth::MapNode::findMapNode(node1);
    if (!mapNode1)
    {
        OE_NOTICE << "Could not find MapNode " << std::endl;
        return 1;
    }
    root->addChild(node1);
    viewer->setSceneData(root);
#if 1//通过改变选择,实现加载指定个点的克制相机运动和加载路径实现相机的视野运动
    //使用动画漫游器
    osgGA::AnimationPathManipulator *animationPathMp = new osgGA::AnimationPathManipulator();
    //给动画漫游器添加关键帧
    osg::AnimationPath* _animationPath = new osg::AnimationPath;

    _animationPath->insert(0.0, osg::AnimationPath::ControlPoint(osg::Vec3d(3.147120e+06, 3.258950e+06, 4660303.37809808), osg::Vec4d(0.140635376916651, 0.348161125478776, 0.85934196362643, 0.347184260898352)));
    _animationPath->insert(3.0, osg::AnimationPath::ControlPoint(osg::Vec3d(3.151752e+06, 3.263747e+06, 4667182.76165385), osg::Vec4d(0.140635376916651, 0.348161125478777, 0.85934196362643, 0.347184260898351)));
    _animationPath->insert(6.0, osg::AnimationPath::ControlPoint(osg::Vec3d(3.156016e+06, 3.268164e+06, 4673515.46890384), osg::Vec4d(0.140635376916651, 0.348161125478776, 0.85934196362643, 0.347184260898352)));
    //设置路径是回摆的
    _animationPath->setLoopMode(osg::AnimationPath::LOOP);
    animationPathMp->setAnimationPath(_animationPath);
    viewer->setCameraManipulator(animationPathMp);
#else 
    viewer->addEventHandler(new PlayCameraPathHandler("time.txt", 50));//从路径中读取带有时间参数的相机姿态信息

#endif // 0

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


    return 1;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rexinx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值