[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();
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM