I followed a tutorial online on how to create a obj file parser, so far my parser reads a obj file and stores all the vertices into a struct named coordinate. Am not quite sure, how to use the coordinates in my struct in my main graphic pipeline
My parser:
void ObjParser(const char* szFileName)
{
ifstream myfile; //use all the method of the ifstream
std::vector<std::string*>coord;
std::vector<coordinate*> vertex;
myfile.open(szFileName);
if(myfile.is_open())
{
//The file is open,use while loop to check file
char buf[256]; //create buffer to read line
while(!myfile.eof())//while we are not at the end of the file.
{
myfile.getline(buf,256);
coord.push_back(new std::string(buf));
}
for(int i = 0; i <coord.size(); i++)
{
//check if it's a comment or not
if(coord[i]->c_str()[0]=='#')
continue;
else if(coord[i]->c_str()[0]=='v' && coord[i]->c_str()[1]==' ')
{
char tmp;
float tmp_x,tmp_y,tmp_z;
sscanf_s(coord[i]->c_str(),"v %f %f %f",&tmp_x,&tmp_y,&tmp_z); //read in the 3
vertex.push_back(new coordinate(tmp_x,tmp_y,tmp_z)); //and then add it to the end of our vertex list
}
}
//Delete coord to avoid memory leaks
for(int i = 0; i < coord.size();i++)
delete coord[i];
}
else{
//Display error message, cause the file connot be opened
MessageBox(NULL, "Error occured while opening file", NULL, NULL);
}
//once complete close file.
myfile.close();
}
the structure of my coordinate class:
struct coordinate{
float x,y,z;
coordinate(float a, float b,float c) : x(a),y(b),z(c) {};
};
I wanna be able to use it in my geometry pipeline and create a wireframe of it.
for example at the moment my vertices are had coded like this:
void wireframe(HDC hdc){
//vertices coordinates:
const int verticescount = 8;
Vertex vertices[verticescount] = {Vertex(-5.0f, -5.0f, 5.0f, 1.0f),
Vertex(5.0f, -5.0f, 5.0f, 1.0f),
Vertex(5.0f, 5.0f, 5.0f, 1.0f),
Vertex(-5.0f, 5.0f, 5.0f, 1.0f),
Vertex(-5.0f, -5.0f, -5.0f, 1.0f),
Vertex(5.0f, -5.0f, -5.0f, 1.0f),
Vertex(5.0f, 5.0f, -5.0f, 1.0f),
Vertex(-5.0f, 5.0f, -5.0f, 1.0f)};
}
any help appreciated on how to get it working.