[osg]OSG相机添加动画路径

查看osg坐标系,camare默认姿态:http://www.cnblogs.com/lyggqm/p/8073688.html

首先搞清楚osg的坐标系以及osg::camare的默认姿态

 

下代码面实现了,在场景里放一只牛。相机使用动画漫游器

在动画中添加三个方向来观察牛。具体三方向姿态请参考代码

#include <iostream>
#include <osg/MatrixTransform>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA\AnimationPathManipulator>
#include <osgDB\ReadFile>

int main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc, argv);
    osgViewer::Viewer viewer(arguments);

    viewer.addEventHandler(new osgViewer::StatsHandler());
    viewer.addEventHandler(new osgViewer::WindowSizeHandler());
    osg::Group* root = new osg::Group();
    
    root->addChild(osgDB::readNodeFile("cow.osg"));
    viewer.setSceneData(root);
    
    //使用动画漫游器
    osgGA::AnimationPathManipulator *animationPathMp = new osgGA::AnimationPathManipulator();
    //给动画漫游器添加关键帧
    osg::AnimationPath* _animationPath = new osg::AnimationPath;

    //当出于模型右边,既x方向20处,为了看见模型
    //要使相机沿着Y轴顺时针旋转90度
    osg::Quat q1(osg::DegreesToRadians(90.0), osg::Y_AXIS);
    osg::Quat q2(osg::DegreesToRadians(90.0), osg::X_AXIS);
    q1 *= q2;

    osg::Quat q3(osg::DegreesToRadians(-90.0), osg::X_AXIS);
    osg::Quat q4(osg::DegreesToRadians(180.0), osg::Y_AXIS);
    q3 *= q4;
    
    osg::Quat q5(osg::DegreesToRadians(-90.0), osg::Z_AXIS);
    
    _animationPath->insert(0.0, osg::AnimationPath::ControlPoint(osg::Vec3d(30, 0, 0), q1));
    _animationPath->insert(4.0, osg::AnimationPath::ControlPoint(osg::Vec3d(0, 30, 0), q3));
    _animationPath->insert(8.0, osg::AnimationPath::ControlPoint(osg::Vec3d(0, 0, 30), q5));
    //设置路径是回摆的
    _animationPath->setLoopMode(osg::AnimationPath::SWING);
    animationPathMp->setAnimationPath(_animationPath);
    viewer.setCameraManipulator(animationPathMp);

    return viewer.run();
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值