0


osg模型的平移、缩放、旋转

加载2个模型,其中一个向上移动28个单位;

加载2个模型,其中一个缩放0.5倍,向下移动22个单位;

加载2个模型,其中一个缩放0.5倍、旋转45度、向右向下移动几个单位;

都是用矩阵实现的;

#include<osgDB\ReadFile>
#include<osgViewer\Viewer>
#include<osg\Node>
#include<osg\MatrixTransform>

void main()
{
    osgViewer::Viewer viewer;
    osg::ref_ptr<osg::Group> root = new osg::Group();

    osg::ref_ptr<osg::Node> bignathan = osgDB::readNodeFile("航天器.3ds");

    osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform;
    trans->setMatrix(osg::Matrix::translate(0, 0, 28));
    trans->addChild(bignathan.get());

    osg::ref_ptr<osg::MatrixTransform> scale = new osg::MatrixTransform;
    scale->setMatrix(osg::Matrix::scale(0.5, 0.5, 0.5)*osg::Matrix::translate(0, 0, -22));
    scale->addChild(bignathan.get());

    osg::ref_ptr<osg::MatrixTransform> rot = new osg::MatrixTransform;
    rot->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(45.0), 1, 0, 0)*osg::Matrix::scale(0.5, 0.5, 0.5)*osg::Matrix::translate(14, 0, -12));
    rot->addChild(bignathan.get());

    root->addChild(bignathan.get());
    //root->addChild(trans.get());
    //root->addChild(scale.get());
    root->addChild(rot.get());

    viewer.setSceneData(root.get());
    viewer.realize();
    viewer.run();
}
标签: osg 矩阵

本文转载自: https://blog.csdn.net/bcbobo21cn/article/details/136063879
版权归原作者 bcbobo21cn 所有, 如有侵权,请联系我们删除。

“osg模型的平移、缩放、旋转”的评论:

还没有评论