osgEarth2.10中用setNode替代setTetherNode设置视点跟踪

30 篇文章 4 订阅
21 篇文章 4 订阅

在以前的版本中,可以很简单的使用setTetherNode进行视点跟踪设置。
以前的方法:

	osg::ref_ptr<osg::Group> mRoot = new osg::Group();	//设置根节点
	osgViewer::Viewer * pViewer = new osgViewer::Viewer();
	osg::MatrixTransform* mtFly = new osg::MatrixTransform;//创建一个模型
	mRoot->addChild(mtFly);//将模型放进根节点
	//初始化一个操作器
	osg::ref_ptr<osgEarth::Util::EarthManipulator> em = new osgEarth::Util::EarthManipulator;
	pViewer->setCameraManipulator(em.get());
	pViewer->setSceneData(mRoot.get());//添加到场景
    pViewer->realize();
    //路径的生成这里不细说了,直接略过了
    mtFly->setUpdateCallback(new osg::AnimationPathCallback(apc,0.0,1.0));
    
	em->setTetherNode(mtFly);

现在的方法:

	osg::ref_ptr<osg::Group> mRoot = new osg::Group();	//设置根节点
	osgViewer::Viewer * pViewer = new osgViewer::Viewer();
	osg::MatrixTransform* mtFly = new osg::MatrixTransform;//创建一个模型
	mRoot->addChild(mtFly);//将模型放进根节点
	//初始化一个操作器
	osg::ref_ptr<osgEarth::Util::EarthManipulator> em = new osgEarth::Util::EarthManipulator;
	pViewer->setCameraManipulator(em.get());
	pViewer->setSceneData(mRoot.get());//添加到场景
    pViewer->realize();
    //路径的生成这里不细说了,直接略过了
    mtFly->setUpdateCallback(new osg::AnimationPathCallback(apc,0.0,1.0));
	
	//下面是区别
    //获取当前操作器的视点,将模型放进这个视角中,然后设置这个视角的一些参数,比如从哪个角度和距离观察模型。然后将这个视点设置为操作器的视点。
    osgEarth::Viewpoint vp = m_em->getViewpoint();
    vp.setNode(mtFly);
    vp.range()->set(250000.0, osgEarth::Units::METERS);//观察的距离
    vp.pitch()->set(-45.0, osgEarth::Units::DEGREES);//观察的角度
    em->setViewpoint(vp, 1.0);

另外,视点必须在viewer执行senScenceData之后才会有效。

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

鱼月半

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

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

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

打赏作者

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

抵扣说明:

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

余额充值