码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-12-20 20:23:58      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:transform   char   路径   roo   addchild   模型   run   etl   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();
}

 

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

标签:transform   char   路径   roo   addchild   模型   run   etl   osg   

原文地址:http://www.cnblogs.com/lyggqm/p/8075277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!