正在加载图片...
pyramidFaceThree->push back(4); pyramidGeometry->addPrimitiveSet(pyramidFaceThree); osg:DrawElementsUInt*pyramidFaceFour new osg:DrawElementsUInt(osg:PrimitiveSet:TRIANGLES,0); pyramidFaceFour->push_back(3); pyramidFaceFour->push_back(0); pyramidFaceFour->push_back(4); pyramidGeometry->addPrimitiveSet(pyramidFaceFour) 声明并加载一个vec4为元素的数组来存储颜色。 osg:Vec4Array*colors new osg:Vec4Array; colors->push_back(osg:Vec4(1.Of,0.Of,0.Of,1.0f));//index 0 red colors->push_back(osg:Vec4(0.Of,1.0f,0.Of,1.0f))://index 1 green colors->push_back(osg:Vec4(0.Of,0.Of,1.Of,1.0f));//index 2 blue colors->push_back(osg:Vec4(1.0f,1.0f,1.0f,1.0f));//index 3 white 声明的这个变量可以将顶点数组元素和颜色数组元素匹配起来。这个容器的元素数应当和顶点数 致。这个容器是顶点数组和颜色数组的连接。这个索引数组中的条目就对应着顶点数组中的元素。 他们的值就是颜色数组中的索引。顶点数组元素与normal和纹理坐标数组的匹配也是遵循这种模 式。 注意,这种情况下,我们将5个顶点指定4种颜色。顶点数组的0和4元素都被指定为颜色数组 的0元素。 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);//vertex 0 assigned color array element 0 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 下一步,将颜色数组和geometry关联起来,将上面产生的颜色索引指定给geometry,设定绑定 模式为PER_VERTEX。 pyramidGeometry->setColorArray(colors); pyramidGeometry->setColorIndices(colorIndexArray); pyramidGeometry->setColorBinding(osg:Geometry:BIND_PER_VERTEX); osg:Vec2Array*texcoords new osg:Vec2Array(5); (*texcoords)[0].set(0.00f,0.Of); (*texcoords)[1].set(0.25f,0.Of); (*texcoords)[2].set(0.50f,0.0f); (*texcoords)[3].set(0.75f,0.0f); (*texcoords)[4].set (0.50f,1.Of); pyramidGeometry->setTexCoordArray(0,texcoords); 注:一下部分可能错误。3 pyramidFaceThree->push_back(4); pyramidGeometry->addPrimitiveSet(pyramidFaceThree); osg::DrawElementsUInt* pyramidFaceFour = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); pyramidFaceFour->push_back(3); pyramidFaceFour->push_back(0); pyramidFaceFour->push_back(4); pyramidGeometry->addPrimitiveSet(pyramidFaceFour) 声明并加载一个 vec4 为元素的数组来存储颜色。 osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 0 red colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f) ); //index 1 green colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) ); //index 2 blue colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 3 white 声明的这个变量可以将顶点数组元素和颜色数组元素匹配起来。这个容器的元素数应当和顶点数 一致。这个容器是顶点数组和颜色数组的连接。这个索引数组中的条目就对应着顶点数组中的元素。 他们的值就是颜色数组中的索引。顶点数组元素与 normal 和纹理坐标数组的匹配也是遵循这种模 式。 注意,这种情况下,我们将 5 个顶点指定 4 种颜色。顶点数组的 0 和 4 元素都被指定为颜色数组 的 0 元素。 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); // vertex 0 assigned color array element 0 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 下一步,将颜色数组和 geometry 关联起来,将上面产生的颜色索引指定给 geometry,设定绑定 模式为_PER_VERTEX。 pyramidGeometry->setColorArray(colors); pyramidGeometry->setColorIndices(colorIndexArray); pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX); osg::Vec2Array* texcoords = new osg::Vec2Array(5); (*texcoords)[0].set(0.00f,0.0f); (*texcoords)[1].set(0.25f,0.0f); (*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); 注:一下部分可能错误
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有