• [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 <osgGAAnimationPathManipulator>
    #include <osgDBReadFile>
    
    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();
    }
  • 相关阅读:
    pinyin4j 实现 中文和拼音之间转化
    关于Exceptionless日志收集框架如何关闭磁盘缓存
    WPF桌面程序在请求接口时如何防止被常用的抓包软件Fiddler抓包
    Docker可视化容器Portainer
    记我第一次玩Docker
    最火热的极速开发框架Spring Boot
    MySQL开发规范
    5分钟入门AWK
    必须掌握的30种SQL语句优化
    支付接口的幂等性设计
  • 原文地址:https://www.cnblogs.com/lyggqm/p/8075277.html
Copyright © 2020-2023  润新知