当前位置: 首页>>代码示例>>C++>>正文


C++ MyMesh::getNumFaces方法代码示例

本文整理汇总了C++中MyMesh::getNumFaces方法的典型用法代码示例。如果您正苦于以下问题:C++ MyMesh::getNumFaces方法的具体用法?C++ MyMesh::getNumFaces怎么用?C++ MyMesh::getNumFaces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyMesh的用法示例。


在下文中一共展示了MyMesh::getNumFaces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: renderMesh

void VRMeshEditor::renderMesh(VRMeshEditor::DataItem* dataItem) const
{
    /* Check if vertex and triangle arrays are large enough: */
    unsigned int numVertices=mesh->getNextVertexIndex();
    if(dataItem->numVertices<numVertices)
    {
        delete[] dataItem->vertices;
        dataItem->numVertices=numVertices+(numVertices/2);
        dataItem->vertices=new MyVertex[dataItem->numVertices];
    }
    unsigned int numTriangles=mesh->getNumFaces();
    if(dataItem->numTriangles<numTriangles)
    {
        delete[] dataItem->triangles;
        dataItem->numTriangles=numTriangles+(numTriangles/2);
        dataItem->triangles=new unsigned int[dataItem->numTriangles*3];
    }

    /* Reset vertex array: */
    for(MyMesh::ConstVertexIterator vIt=mesh->beginVertices(); vIt!=mesh->endVertices(); ++vIt)
    {
        MyVertex* vPtr=&dataItem->vertices[vIt->index];
        for(int i=0; i<3; ++i)
        {
            vPtr->normal[i]=0.0f;
            vPtr->position[i]=(*vIt)[i];
        }
    }

    /* Traverse triangles once to calculate normal vectors for smooth shading: */
    unsigned int* viPtr=dataItem->triangles;
    for(MyMesh::ConstFaceIterator fIt=mesh->beginFaces(); fIt!=mesh->endFaces(); ++fIt,viPtr+=3)
    {
        /* Gather triangle's points: */
        const MyMesh::Vertex* v[3];
        const MyMesh::Edge* e=fIt->getEdge();
        for(int i=0; i<3; ++i)
        {
            v[i]=e->getStart();
            viPtr[i]=v[i]->index;
            e=e->getFaceSucc();
        }

        /* Calculate triangle's normal vector: */
        float normal[3];
        planeNormal(*v[0],*v[1],*v[2],normal);

        /* Distribute normal vector to triangle's vertices: */
        for(int i=0; i<3; ++i)
        {
            MyVertex* vPtr=&dataItem->vertices[viPtr[i]];
            for(int j=0; j<3; ++j)
                vPtr->normal[j]+=normal[j];
        }
    }

#if 0
    static bool saveVertices=true;
    if(saveVertices)
    {
#if 0
        float min[3],max[3];
        MyMesh::ConstVertexIterator vIt=mesh->beginVertices();
        for(int i=0; i<3; ++i)
            min[i]=max[i]=vIt->pos()[i];
        for(++vIt; vIt!=mesh->endVertices(); ++vIt)
            for(int i=0; i<3; ++i)
            {
                if(min[i]>vIt->pos()[i])
                    min[i]=vIt->pos()[i];
                else if(max[i]<vIt->pos()[i])
                    max[i]=vIt->pos()[i];
            }
        float center[3];
        for(int i=0; i<3; ++i)
            center[i]=(min[i]+max[i])*0.5f;
        float scale=60.0f/(max[0]-min[0]);
        for(int i=1; i<3; ++i)
        {
            float scale2=60.0f/(max[i]-min[i]);
            if(scale>scale2)
                scale=scale2;
        }
#endif

#if 0
        FILE* sampleFile=fopen("../ScatteredData/ModelVertices.txt","wt");
        fprintf(sampleFile,"%u 3 1\n",numVertices);
        for(MyMesh::ConstVertexIterator vIt=mesh->beginVertices(); vIt!=mesh->endVertices(); ++vIt)
        {
            MyVertex* vPtr=&dataItem->vertices[vIt->index];
            float pos[3];
            for(int i=0; i<3; ++i)
                pos[i]=vPtr->position[i];
            //pos[i]=(vPtr->position[i]-center[i])*scale+64.0f;
            float normLen=sqrtf(vPtr->normal[0]*vPtr->normal[0]+vPtr->normal[1]*vPtr->normal[1]+vPtr->normal[2]*vPtr->normal[2]);
            fprintf(sampleFile,"%8.3f %8.3f %8.3f 0 0 0 %6.3f %6.3f %6.3f\n",pos[0],pos[1],pos[2],vPtr->normal[0]/normLen,vPtr->normal[1]/normLen,vPtr->normal[2]/normLen);
        }
        fclose(sampleFile);
#endif
//.........这里部分代码省略.........
开发者ID:VisualIdeation,项目名称:Vrui,代码行数:101,代码来源:VRMeshEditor.cpp


注:本文中的MyMesh::getNumFaces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。