OSG学习心得一

  1. 路径使用双斜杠
osg::Image* klnFace = osgDB::readImageFile("C:\\Users\\jack\\Desktop\\TIM.png");

下面的代码是顶点数组指定颜色数组,在新版本(OSG 3.6.3)中已经不需要了.

osg::TemplateIndexArray

      <unsigned int, osg::Array::UIntArrayType,4,4> *colorIndexArray;

   colorIndexArray = 

      new osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType,4,4>;

   colorIndexArray->push_back(0); // 顶点0对应颜色元素0

   colorIndexArray->push_back(1); // 顶点1对应颜色元素1

   colorIndexArray->push_back(2); // 顶点2对应颜色元素2

   colorIndexArray->push_back(3); // 顶点3对应颜色元素3

   colorIndexArray->push_back(0); // 顶点4对应颜色元素0

   pyramidGeometry->setColorIndices(colorIndexArray);

  1. OSG可以进行模型的平移,缩放,旋转。并且可以同时进行,但需按照RST顺序(旋转,缩放,平移)
    。参见以下代码
 #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("bignathan.osg");

        osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform;
        trans->setMatrix(osg::Matrix::translate(0, 0, 2));
        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, -2));
        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(4, 0, -2));
        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();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值