从文本文件directx映射读取

时间:2015-03-26 14:48:38

标签: c++ class dictionary directx text-files

这是我的代码示例,我有一个记事本文件,其中包含字母和每个字母,我希望能够在加载场景时生成不同的模型。如果做得好,我可以有效地使用拣选在地图中制作地图构建器,但在此阶段,这不是主题。此代码取自之前的一个项目,该项目是一个win32控制台项目,它使用地图读取生成路径查找,我已经在CModel类下面初始化了模型,CModel处理加载到场景中,例如几何体和模型的外观但我怎么能改变这个代码,允许我从文本文件生成这些模型;在directx。求救!

void Map(float updateTime)
{

//=========== Reading grid from text file =========== //    

    vector<string> grid; // creating 10x10 grid.
    int count = 0;
    int row = 10;
    int col = 10;  

    ifstream input( "Map1.txt" );  //  The input file

    string line; // stores each line.
    if (input.is_open()) 
    {

       while(getline(input, line))
       {
           grid.push_back(line); // get new line.
       }
    }
    else // writes to screen if text file doesn't open.
    {
        stringstream outText;
        outText << "Not open";
        RenderText( outText.str(), 0, 0, 1.0f, 1.0f, 0.0f );
        outText.str("");
    }

    while( input && row <= 100 ) // checking each row and col for values from .txt
    {
        input >> grid[ row ][ col ];
        if( input ) 
        {
            if( ++col == 10 )
            {       
                ++row;                  
                col = 0;                
            }
        }
    }

    for(size_t i=0 ; i < grid.size(); ++i) // finding the size of each line
    {

    }

    if(line == "W") // trying to generate model from letters from the text file.
    {
        grid.push_back(new CModel* = Cube);
    }
    input.close();
}

0 个答案:

没有答案