- 路径使用双斜杠
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);
- 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();
}
4151

被折叠的 条评论
为什么被折叠?



