#pragma warning(disable: 4786) #include #include #include #include #include #include #include #include "Drawline.h" #include "Render.h" #include "OBJParser.h" using namespace std; Render::Render() { } Render::~Render() { } void Render::input(char *fileName) { char buf[1024]; char* stopString; char* faceColor=NULL; string line; string separators = " "; vector tokenList; ifstream fin(fileName); // Open the OBJ file //Read line 1, X and Y resolution of the out.ppm image fin.getline(buf,1024); tokenList.clear(); line = buf; getTokens(line, separators, tokenList); convertFromString(Xres,tokenList[0]); convertFromString(Yres,tokenList[1]); //Read line 2,<3D mesh object filename <.obj> fin.getline(buf,1024); tokenList.clear(); objfile = buf; //Read line 3, perspective transform fin.getline(buf,1024); tokenList.clear(); line = buf; getTokens(line, separators, tokenList); for(int i=0;i<6;i++) convertFromString(ps[i],tokenList[i]); //Read line 4, camera specifications fin.getline(buf,1024); tokenList.clear(); line = buf; getTokens(line, separators, tokenList); convertFromString(rx,tokenList[0]); convertFromString(ry,tokenList[1]); convertFromString(rz,tokenList[2]); convertFromString(ux,tokenList[3]); convertFromString(uy,tokenList[4]); convertFromString(uz,tokenList[5]); convertFromString(vx,tokenList[6]); convertFromString(vy,tokenList[7]); convertFromString(vz,tokenList[8]); convertFromString(nx,tokenList[9]); convertFromString(ny,tokenList[10]); convertFromString(nz,tokenList[11]); //Read line 5, Scaling Transform fin.getline(buf,1024); tokenList.clear(); line = buf; getTokens(line, separators, tokenList); convertFromString(sx,tokenList[0]); convertFromString(sy,tokenList[1]); convertFromString(sz,tokenList[2]); //Read line 6, Translations vector fin.getline(buf,1024); tokenList.clear(); line = buf; getTokens(line, separators, tokenList); convertFromString(tx,tokenList[0]); convertFromString(ty,tokenList[1]); convertFromString(tz,tokenList[2]); //Read line 7, Rotation angles fin.getline(buf,1024); tokenList.clear(); line = buf; getTokens(line, separators, tokenList); convertFromString(thx,tokenList[0]); convertFromString(thy,tokenList[1]); convertFromString(thz,tokenList[2]); //showInput();//Debug } void Render::getTokens(string& stmt, string& separators, vector& token_list) { int n = stmt.length(); int start, stop; start = stmt.find_first_not_of(separators); while ((start >= 0) && (start < n)) { stop = stmt.find_first_of(separators, start); if ((stop < 0) || (stop > n)) stop = n; token_list.push_back(stmt.substr(start, stop - start)); start = stmt.find_first_not_of(separators, stop+1); } } //Display the input file void Render::showInput() { cout<=3) drawline.output(argv[2]); else drawline.output(); //system("Pause"); return 0; }