网格(Mesh) 学习

关于龙书中第十章 的网格优化还不是十分理解,但是对于子集概念已经清楚,并且对于Dump系列函数(用以输出相关数据信息的做法)深有感触,这种输出方式是对整个结构是透彻理解的一种非常好的途径。在以后开发项目的时候应当学会适当运用这种方法来生成相关文件,感觉是一种利于维护和记忆过程的良好方式。

下面来介绍实例代码:

需要引入fstream.h文件,因为涉及到文件流的操作。

Step 1: 全局变量 std::ofstream OutFile;  这个ofstream 在 http://soft.chinabyte.com/database/460/11433960.shtml上有详细的介绍。

step 2:打开目标文件 

OutFile.open("Mesh Dump.txt");

step 3:调用Dump系列函数,例如dumpAdjacencyBuffer();

dumpAdjacencyBuffer(OutFile, Mesh);

step 4: 关闭退出OutFile

OutFile.close();

 

关于dump系列函数的定义,以void dumpAdjacencyBuffer(std::ofstream& outFile, ID3DXMesh* mesh);为例

void dumpAdjacencyBuffer(std::ofstream& outFile, ID3DXMesh* mesh){
    outFile << "Adjacency Buffer:" << std::endl;
    outFile << "-----------------" << std::endl << std::endl;

    // three enttries per face
    std::vector<DWORD> adjacencyBuffer(mesh->GetNumFaces() * 3);

    mesh->GenerateAdjacency(0.0f, &adjacencyBuffer[0]);

    for(int i = 0; i < mesh->GetNumFaces(); i++){
        outFile << "Triangle's adjacent to triangle " << i << ": ";
        outFile << adjacencyBuffer[i * 3    ] << " ";
        outFile << adjacencyBuffer[i * 3 + 1] << " ";
        outFile << adjacencyBuffer[i * 3 + 2] << std::endl;
    }

    outFile << std::endl << std::endl;
}

 

这种方法是很好的一种,检测学习掌握程度的方法。并且产生的数据若进行拓展,也许会有有意想不到的用处,至于到底有什么好处我暂时还没思考完整,有时间回头补充。

posted @ 2014-02-10 23:52  Moniza  阅读(599)  评论(0)    收藏  举报