|
楼主 |
发表于 2014-7-8 19:58:24
|
显示全部楼层
不好意思,是我粘贴错了函数,是调用下面这个函数的时候出现 断言错误
- osg::Geometry * createGeometry()
- {
- osg::Geometry * pyramidGeometry = new osg::Geometry;
- osg::Vec3Array* pyramidVertices = new osg::Vec3Array;
- pyramidVertices->push_back( osg::Vec3( 0, 0, 0) ); // 左前
- pyramidVertices->push_back( osg::Vec3(10, 0, 0) ); // 右前
- pyramidVertices->push_back( osg::Vec3(10,10, 0) ); // 右后
- pyramidVertices->push_back( osg::Vec3( 0,10, 0) ); // 左后
- pyramidVertices->push_back( osg::Vec3( 5, 5,10) ); // 塔尖
- pyramidGeometry->setVertexArray( pyramidVertices );
- /*
- osg::DrawElementsUInt* pyramidBase = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
- pyramidBase->push_back(3);
- pyramidBase->push_back(2);
- pyramidBase->push_back(1);
- pyramidBase->push_back(0);
- pyramidGeometry->addPrimitiveSet(pyramidBase);
- osg::DrawElementsUInt* pyramidFaceOne = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
- pyramidFaceOne->push_back(0);
- pyramidFaceOne->push_back(1);
- pyramidFaceOne->push_back(4);
- pyramidGeometry->addPrimitiveSet(pyramidFaceOne);
- osg::DrawElementsUInt* pyramidFaceTwo = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
- pyramidFaceTwo->push_back(1);
- pyramidFaceTwo->push_back(2);
- pyramidFaceTwo->push_back(4);
- pyramidGeometry->addPrimitiveSet(pyramidFaceTwo);
- osg::DrawElementsUInt* pyramidFaceThree = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
- pyramidFaceThree->push_back(2);
- pyramidFaceThree->push_back(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);
- */
- osg::UIntArray* vecindex = new osg::UIntArray; //顶点索引数组
- vecindex->push_back(0);vecindex->push_back(1);vecindex->push_back(4);
- vecindex->push_back(1);vecindex->push_back(2);vecindex->push_back(4);
- vecindex->push_back(2);vecindex->push_back(3);vecindex->push_back(4);
- vecindex->push_back(3);vecindex->push_back(0);vecindex->push_back(4);
- pyramidGeometry->setVertexIndices(vecindex);
- pyramidGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,vecindex->size()));
- osg::Vec4Array* colors = new osg::Vec4Array;
- colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) );
- colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f) );
- colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) );
- colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) );
- //osg::TemplateIndexArray <unsigned int, osg::Array::UIntArrayType,4,4> *colorIndexArray;
- //colorIndexArray = new osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType,4,4>;
- osg::UIntArray * colorIndexArray = new osg::UIntArray();
- colorIndexArray->push_back(0); // vertex 0 assigned color
- colorIndexArray->push_back(1); // vertex 1 assigned color
- colorIndexArray->push_back(2); // vertex 2 assigned color
- colorIndexArray->push_back(3); // vertex 3 assigned color
- colorIndexArray->push_back(0); // vertex 4 assigned color
- pyramidGeometry->setColorArray(colors);
- pyramidGeometry->setColorIndices(colorIndexArray);
- pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
- osg::Vec2Array* texcoords = new osg::Vec2Array();
- texcoords->push_back(Vec2(0.00f,0.0f));
- texcoords->push_back(Vec2(0.25f,0.0f));
- texcoords->push_back(Vec2(0.5f,0.0f));
- texcoords->push_back(Vec2(0.75f,0.0f));
- texcoords->push_back(Vec2(0.5f,1.0f));
- pyramidGeometry->setTexCoordArray(0,texcoords);
- return pyramidGeometry;
- }
复制代码 |
|