I'm having a problem reading an OBJ file... Problem 1 is that the vectors are declared as floats (and have been declared as doubles), but print out in the terminal gives me all integers. Terminal output has been:
1-1-1
1-11
-1-11
-1-1-1
when it ought to be:
1.000000 -1.000000 -1.000000
1.000000 -1.000000 1.000000
-1.000000 -1.000000 1.000000
-1.000000 -1.000000 -1.000000
Problem 2 is that I have been unable to read the faces in the file correctly. The output has been:
1
5
1
2
when it should be:
1 2 3 4
5 8 7 6
1 5 6 2
2 6 7 3
I'm trying to get the results to print out correctly now, since I will next be putting these results in nodes using dynamic memory allocation due to their varying in size. Here's the code:
/* This function opens the OBJ file */
void openFile(string nf){
std::ifstream file;
file.open (nf, std::ifstream::out);
string line;
string o_name;
string faces;
char o;
char v;
char f;
int i = 0;
float x;
float y;
float z;
if(file.is_open()){
std::cout<< "file is open!\n";
//include actions for OBJ file...Just read. You work from memory
while(std::getline(file, line))
{
if(line.empty()) //line is empty, then file is empty!
std::cout << "file is empty! \n";
/* finds the shape name*/
if (line[i] == 'o')
{
std::istringstream iss (line);
iss >> o >> o_name;
std::cout << o_name << endl;
line.clear();
//createNodeO(string o_name);
}
/* finds the vertices*/
if (line[i] == 'v')
{
std::istringstream iss (line);
iss >> v >> x >> y >> z;
std::cout << x << y << z << endl;
line.clear();
//createNodeO(float x, float y, float z);
}
/* finds the faces*/
if (line[i] == 'f')
{
std::istringstream iss (line);
iss >> f >> faces;
std::cout << faces << endl;
//createNodeO(string faces);
}
}
}
else{
std::cout<< "could not open the file!\n";
}
file.close();
std::cout<< "file is closed!\n";
}
According to the g++ compiler, I'm crazy when it comes to the faces part. Please help!