Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int RF_3D::loadObj(string file)
- {
- float aux[4];
- RF_3D_Object* tmpObj = new RF_3D_Object();
- FILE* pf = fopen(file.c_str(),"r");
- if(NULL == pf)
- {
- RF_Engine::instance->Debug("[RF_3D::loadObj] No se ha podido abrir el fichero");
- return -1;
- }
- while(!feof(pf))
- {
- char t[1000];
- fgets(t,1000,pf);
- int j=0; string tAux;
- for(int i = 0; i < 1000; i++)
- {
- switch(t[i])
- {
- case ' ':
- aux[j] = atof(tAux.c_str());
- j++;
- tAux = "";
- break;
- case 'v': i++; break;
- case 'f': i++; break;
- default: tAux+=t[i]; break;
- }
- }
- aux[j] = atof(tAux.c_str());
- switch(t[0])
- {
- case 'v':
- tmpObj->vertex.push_back(Vector3<float>(aux[0],aux[1],aux[2]));
- break;
- case 'f':
- tmpObj->faces.push_back(Faces((int)aux[0],(int)aux[1],(int)aux[2],(int)aux[3]-1));
- break;
- }
- }
- RF_Engine::instance->Debug("LoadOBJ");
- int siz = tmpObj->vertex.size();
- RF_Engine::instance->Debug(siz);
- RF_Engine::instance->Debug("");
- tmpObj->finalizeCreation();
- RF_3D::objectList.push_back(tmpObj);
- return RF_3D::objectList.size()-1;
- }
Advertisement
Add Comment
Please, Sign In to add comment