正在加载图片...
colorIndexArray->push_back(1);//vertex 1 assigned color array element 1 colorIndexArray->push_back(2)://vertex 2 assigned color array element 2 colorIndexArray->push_back(3);//vertex 3 assigned color array element 3 colorIndexArray->push back(0);/vertex 4 assigned color array element 0 pyramidGeometry->setColorArray(colors): pyramidGeometry->setColorIndices(colorIndexArray); pyramidGeometry->setColorBinding(osg:Geometry:BIND_PER_VERTEX); /Since the mapping from vertices to texture coordinates is 1:1, /we don't need to use an index array to map vertices to texture /coordinates.We can do it directly with the 'setTexCoordArray' /method of the Geometry class. /This method takes a variable that is an array of two dimensional /vectors (osg:Vec2).This variable needs to have the same /number of elements as our Geometry has vertices.Each array element /defines the texture coordinate for the cooresponding vertex in the /vertex array. osg:Vec2Array*texcoords new osg:Vec2Array (5); (*texcoords)[0].set(0.00f,0.0f);/tex coord for vertex 0 (*texcoords)[1].set(0.25f,0.0f);//tex coord for vertex I (*texcoords))[2].set(0.50f,0.0f):/"” (*texcoords)[3].set(0.75f,0.Of);//"" (*texcoords)[4].set(0.50f,1.0f);//"" pyramidGeometry->setTexCoordArray(0,texcoords); return pyramidGeode; 2.3加载纹理,生成状态集合并将他们附加到节点上 渲染基本单位的方法是使用StateSet.。这节代码演示了怎样从文件中加载纹理,产生此纹理起 作用的一个StateSet,.并将这个StateSet附加到场景中的一个节点上。前面开始的代码和上一节 教程中的一样,初始化一个viewer并建立有一个pyramid的场景。 int main() { osgProducer:Viewer viewer; /Declare a group to act as root node of a scene: osg:Group*root new osg:Group(); 66 colorIndexArray->push_back(1); // vertex 1 assigned color array element 1 colorIndexArray->push_back(2); // vertex 2 assigned color array element 2 colorIndexArray->push_back(3); // vertex 3 assigned color array element 3 colorIndexArray->push_back(0); // vertex 4 assigned color array element 0 pyramidGeometry->setColorArray(colors); pyramidGeometry->setColorIndices(colorIndexArray); pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX); // Since the mapping from vertices to texture coordinates is 1:1, // we don't need to use an index array to map vertices to texture // coordinates. We can do it directly with the 'setTexCoordArray' // method of the Geometry class. // This method takes a variable that is an array of two dimensional // vectors (osg::Vec2). This variable needs to have the same // number of elements as our Geometry has vertices. Each array element // defines the texture coordinate for the cooresponding vertex in the // vertex array. osg::Vec2Array* texcoords = new osg::Vec2Array(5); (*texcoords)[0].set(0.00f,0.0f); // tex coord for vertex 0 (*texcoords)[1].set(0.25f,0.0f); // tex coord for vertex 1 (*texcoords)[2].set(0.50f,0.0f); // "" (*texcoords)[3].set(0.75f,0.0f); // "" (*texcoords)[4].set(0.50f,1.0f); // "" pyramidGeometry->setTexCoordArray(0,texcoords); return pyramidGeode; } 2.3 加载纹理,生成状态集合并将他们附加到节点上 渲染基本单位的方法是使用 StateSet。这节代码演示了怎样从文件中加载纹理,产生此纹理起 作用的一个 StateSet,并将这个 StateSet 附加到场景中的一个节点上。前面开始的代码和上一节 教程中的一样,初始化一个 viewer 并建立有一个 pyramid 的场景。 int main() { osgProducer::Viewer viewer; // Declare a group to act as root node of a scene: osg::Group* root = new osg::Group();
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有